Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
ts-bytenode
Advanced tools
A modified bytenode compiler for TypeScript projects using NodeJS.
Inspired by the original bytenode
library, this tool instead compiles TypeScript code into V8
bytecode. It is expected to be used with NodeJS (eg: CommonJS modules), and also allows compilation for Electron processes.
The inspiration for this offshoot of bytenode
came about from needing to reimplement a segmented build strategy for enterprise-level Electron applications. Since I needed separate production and development builds (as bytenode
breaks debugging capabilities), any segmented system required extra build-tools and time to work with.
Now by integrating both the exposed TypeScript compilation API and piping this output to a modified bytenode
implementation, the outputs can be modified with ease.
npm install --save-dev ts-bytenode # locally
npm install -g ts-bytnode # globally
bytenode
The underlying bytecode compilation and require
augmentation remain the same, however custom file resolution can also be added to alter the desired extension and files that may be required.
Ultimately the current issues affecting bytenode
also affect ts-bytenode
. Since the compilation stage is the same, the output bytecode is at the whim of the V8 engine. For more information please see the (issues for bytenode
)[https://github.com/bytenode/bytenode#known-issues-and-limitations].
One issue has been fixed unexpectedly by adding the TypeScript compilation stage. Since TypeScript polyfills Async/Await expressions, this results in Async Arrow Functions (and regular arrow functions) to not cause crashes in Puppeteer and Electron apps. This should be taken with a grain of salt as by setting target = "ES2017"
or elsewise in your tsconfig.json
, this will preserve Async/Await statements, thus reintroducing this issue.
TS-Bytenode typically expects any tsconfig.json
projects to use the module = "CommonJS"
and moduleResolution = "node"
. Since this package relies on the use of the NodeJS standard library, expecting other contexts is redundant.
Usage: tsb [options] [command]
Options:
-v, --version Output the package version.
-h, --help Display help information.
Commands:
run <filename> Launches a given bytecode file.
compile [options] [filename] Attempts compiling a given TS project to V8 bytecode.
help [command] Display help for an optional command.
Examples:
$ tsb compile Compiles "tsconfig.json" found in the cwd.
$ tsb compile -c ./example Compiles the "tsconfig.json" found in the "./example" directory.
$ tsb compile -c ./example/tsconfig.json
$ tsb compile -m dev Output ".js" files instead of ".tsb".
$ tsb compile -m dev -d dev Output resulting development files into "$outDir/dev". Modifies the "tsconfig.js" output directory.
$ tsb compile -i hello.ts __* Ignore files by basename pattern matching.
$ tsb run ./example Launches the compiled "tsb" file "./example/dist/index.tsb" (if no "index.js" file exist).
$ tsb run ./example/index.tsb
Alongside the CLI functionality, TS-Bytenode also exposes the internal compilation functionality. These can be accessed as.
import { TSB, TSC } from 'ts-bytenode';
TSB; // Bytenode functionality.
TSC; // TypeScript project compilation.
Of this functionality, the most important is the require
modification.
require<T extends any>(fileName: string): T
Just like bytenode
, any .tsb
modules can now be required after calling the TSB.augment()
method. All compiled outputs are wrapped as modules by default as this is the expected functionality required.
Also to note, any compiled .tsb
files must be executed from the same NodeJS version they were compiled with. This process is the same as bytenode
so any issues pertaining to running compiled outputs will be the similar to their results.
Much of this project could not be completed without taking inspiration from bytenode
by @OsamaAbbas.
FAQs
Bytenode Compiler for Typescript.
We found that ts-bytenode demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.