-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #484 from AikidoSec/clean-stacktraces
Clean up error stack traces on detected attack
- Loading branch information
Showing
7 changed files
with
59 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import * as t from "tap"; | ||
import { cleanError } from "./cleanError"; | ||
|
||
t.test("it works", async () => { | ||
const error = new Error("test"); | ||
t.same(error.message, "test"); | ||
t.same(error.name, "Error"); | ||
t.same(error.stack!.includes("cleanError.test.ts"), true); | ||
|
||
const cleaned = cleanError(new Error("test")); | ||
t.same(cleaned.message, "test"); | ||
t.same(cleaned.name, "Error"); | ||
t.same(cleaned.stack!.includes("cleanError.test.ts"), false); | ||
|
||
const cleaned2 = cleanError(new TypeError("test2")); | ||
t.same(cleaned2.message, "test2"); | ||
t.same(cleaned2.name, "TypeError"); | ||
t.same(cleaned2.stack!.includes("cleanError.test.ts"), false); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { cleanupStackTrace } from "./cleanupStackTrace"; | ||
import { getLibraryRoot } from "./getLibraryRoot"; | ||
|
||
// Cleans up the error stack trace by removing all the lines that are part of the library. | ||
// e.g. useful to hide the module patching if we throw an error on a detected attack. | ||
export function cleanError(err: Error) { | ||
if (err.stack) { | ||
err.stack = cleanupStackTrace(err.stack, getLibraryRoot()); | ||
} | ||
|
||
return err; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { resolve } from "path"; | ||
|
||
const libraryRoot = resolve(__dirname, ".."); | ||
|
||
export function getLibraryRoot(): string { | ||
return libraryRoot; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters