TSX, the TypeScript Execute tool designed to enhance Node.js with esbuild for seamless execution of TypeScript and ESM files, has a new release: version 4.16.0. Compared to its previous stable version, 4.15.9, the key difference lies in its dependency updates. TSX 4.16.0 upgrades esbuild from version ~0.21.4 to ~0.21.5. This update to esbuild, a blazing-fast JavaScript bundler and minifier, likely brings performance improvements, bug fixes, and potentially new features that benefit the tsx workflow, offering a slightly optimized build/execution process for TypeScript projects. The unpacked size of version 4.16.0 has also marginally increased to 422922 from 422836, suggesting minor additions or modifications within the package.
For developers utilizing TSX, this update signifies a commitment to keeping pace with the speed and efficiency improvements offered by esbuild. While the core functionality of TSX remains the same, relying on esbuild to provide fast TypeScript compilation and execution, the underlying enhancements in esbuild can contribute to a smoother and more performant development experience. Specifically, version 4.16.0 was released on 2024-06-29T06:13:55.502Z, approximately six hours after 4.15.9 (released 2024-06-29T00:49:49.697Z), pointing that the update was a fix or an important adittion. Developers already on TSX can upgrade to leverage these benefits, while those exploring TSX for the first time can expect a modern toolchain optimized for rapid TypeScript development leveraging the latest esbuild features.
All the vulnerabilities related to the version 4.16.0 of the package
esbuild enables any website to send any requests to the development server and read the response
esbuild allows any websites to send any request to the development server and read the response due to default CORS settings.
esbuild sets Access-Control-Allow-Origin: * header to all requests, including the SSE connection, which allows any websites to send any request to the development server and read the response.
https://github.com/evanw/esbuild/blob/df815ac27b84f8b34374c9182a93c94718f8a630/pkg/api/serve_other.go#L121 https://github.com/evanw/esbuild/blob/df815ac27b84f8b34374c9182a93c94718f8a630/pkg/api/serve_other.go#L363
Attack scenario:
http://malicious.example.com).fetch('http://127.0.0.1:8000/main.js') request by JS in that malicious web page. This request is normally blocked by same-origin policy, but that's not the case for the reasons above.http://127.0.0.1:8000/main.js.In this scenario, I assumed that the attacker knows the URL of the bundle output file name. But the attacker can also get that information by
/index.html: normally you have a script tag here/assets: it's common to have a assets directory when you have JS files and CSS files in a different directory and the directory listing feature tells the attacker the list of files/esbuild SSE endpoint: the SSE endpoint sends the URL path of the changed files when the file is changed (new EventSource('/esbuild').addEventListener('change', e => console.log(e.type, e.data)))The scenario above fetches the compiled content, but if the victim has the source map option enabled, the attacker can also get the non-compiled content by fetching the source map file.
npm inpm run watchfetch('http://127.0.0.1:8000/app.js').then(r => r.text()).then(content => console.log(content)) in a different website's dev tools.Users using the serve feature may get the source code stolen by malicious websites.