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.
sourcemapped-stacktrace-node
Advanced tools
A simple module for applying source maps to JS stack traces in the browser.
⚠️ This is a lazy fork of a sourcemapped-stacktrace. To do all things right I need to do a lot of refactoring, for which I do not have time right now. So I did minimal change to be able to use it as npm package. This is a PR with first steps of a refactoring. Highly experimental. Undocumented.
const mapStackTrace = require("sourcemapped-stacktrace-node").default;
// puppeteer is not required to use sourcemapped-stacktrace-node
// it is used for example
const browser = await puppeteer.launch();
const page = await browser.newPage();
page.on("pageerror", e => {
mapStackTrace(
e.stack,
result => {
console.log(result.join("\n"));
},
{ isChromeOrEdge: true }
);
});
This is a simple module for applying source maps to JS stack traces in the browser.
You have Error.stack() in JS (maybe you're logging a trace, or you're looking at traces in Jasmine or Mocha), and you need to apply a sourcemap so you can understand whats happening because you're using some fancy compiled-to-js thing like coffeescript or traceur. Unfortunately, the browser only applies sourcemaps when the trace is viewed in its console, not to the underlying stack object, so you're out of luck.
http://novocaine.github.io/sourcemapped-stacktrace-demo/public_html/smst.html
npm install sourcemapped-stacktrace
https://www.npmjs.com/package/sourcemapped-stacktrace
The npm bundle contains dist/sourcemapped-stacktrace.js, if that's what you're after. The built product is not held in this repo.
Include sourcemapped-stacktrace.js into your page using either an AMD module loader or a plain old script include. As an AMD module it exposes the method 'mapStackTrace'. If an AMD loader is not found this function will be set on window.sourceMappedStackTrace.mapStackTrace.
Re-map entries in a stacktrace using sourcemaps if available.
Arguments:
stack: Array of strings from the browser's stack representation.
done: Callback invoked with the transformed stacktrace (an Array of Strings) passed as the first argument
opts: Optional options object containing:
true
, sourcemaps are cached across multiple mapStackTrace()
calls,
allowing for better performance if called repeatedly, or when browser's cache is disabled.
Defaults to false
.Supported browsers
Several modern browsers support sourcemaps when viewing stack traces from errors in their native console, but as of the time of writing there is no support for applying a sourcemap to the (highly non-standardised) Error.prototype.stack. Error.prototype.stack can be used for logging errors and for displaying errors in test frameworks, and it is not very convenient to have unmapped traces in either of those use cases.
This module fetches all the scripts referenced by the stack trace, determines whether they have an applicable sourcemap, fetches the sourcemap from the server, then uses the Mozilla source-map library to do the mapping. Browsers that support sourcemaps don't offer a standardised sourcemap API, so we have to do all that work ourselves.
The nice part about doing it ourselves is that the library could be extended to work in browsers that don't support sourcemaps, which could be good for logging and debugging problems. Currently, only Chrome and Firefox are supported, but it would be easy to support those formats by ripping off stacktrace.js.
FAQs
A simple module for applying source maps to JS stack traces in the browser.
The npm package sourcemapped-stacktrace-node receives a total of 10,684 weekly downloads. As such, sourcemapped-stacktrace-node popularity was classified as popular.
We found that sourcemapped-stacktrace-node 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.