-
Notifications
You must be signed in to change notification settings - Fork 312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support to generate_stack
action
#4382
Conversation
Overall package sizeSelf size: 6.7 MB Dependency sizes
🤖 This report was automatically generated by heaviest-objects-in-the-universe |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #4382 +/- ##
==========================================
+ Coverage 80.42% 88.41% +7.98%
==========================================
Files 3 113 +110
Lines 373 4040 +3667
Branches 33 33
==========================================
+ Hits 300 3572 +3272
- Misses 73 468 +395 ☔ View full report in Codecov by Sentry. |
BenchmarksBenchmark execution time: 2024-06-14 14:23:04 Comparing candidate commit 6df590c in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 258 metrics, 8 unstable metrics. |
const indexedFrames = filteredFrames.map((callSite, i) => { | ||
return { | ||
id: i++, | ||
file: callSite.getFileName(), | ||
line: callSite.getLineNumber(), | ||
column: callSite.getColumnNumber(), | ||
function: callSite.getFunctionName() | ||
} | ||
}) | ||
return cutDownFrames(indexedFrames, maxDepth) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this way, we are creating 68 unnecessary objects by default, if you merge both actions in one forEach
you will be able to prevent the creation of these objects:
const resultFrames = []
const lastInitialIndex = /*calculate last beginning index */
const firstFinalIndex = /*calculate first tail index */
filteredFrames.forEach((callSite, id) => {
if (id < lastInitialIndex || id > firstFinalIndex) {
resultFrames.push({
id,
file: callSite.getFileName(),
line: callSite.getLineNumber(),
column: callSite.getColumnNumber(),
function: callSite.getFunctionName()
})
}
})
return resultFrames
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've reworked this part with a similar proposed approach. Please, check it out.
[...Array(10).keys()].map(i => ( | ||
{ | ||
getFileName: () => path.join(__dirname, `file${i}`), | ||
getLineNumber: () => `${i}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't getLineNumber
are getColumnNumber
expecting to return a number?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems reasonable. Might be a good idea to define a more universal standard though on how we capture stack traces given that several products capture and use them. 🤔
4793319
to
7e11788
Compare
rootSpan.meta_struct['_dd.stack'].exploit = [] | ||
} | ||
|
||
if (rootSpan.meta_struct['_dd.stack'].exploit.length < maxStackTraces) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If maxStackTraces is configured as 0
, it shouldn't have a limit.
if (rootSpan.meta_struct['_dd.stack'].exploit.length < maxStackTraces) { | |
if (maxStackTraces < 1 || rootSpan.meta_struct['_dd.stack'].exploit.length < maxStackTraces) { |
Co-authored-by: Ugaitz Urien <[email protected]>
Co-authored-by: Ugaitz Urien <[email protected]>
* Stack trace collection configuration * Collect and report stack trace for appsec events * Handle generate_stack waf action * Fix linting in config.spec.js * Add assertion for stack trace tag in meta_struct for express test * Refactor reportStackTrace and some additional test * Fix lint * Additional assert in reportStackTrace test * Update config * Rework on stack trace collection * Callsite line and column as numbers * Update packages/dd-trace/src/appsec/stack_trace.js Co-authored-by: Ugaitz Urien <[email protected]> * Update packages/dd-trace/src/appsec/stack_trace.js Co-authored-by: Ugaitz Urien <[email protected]> * Reorder test structure * Fix linting * No exploit stack limit when max is set to 0 or below * Fix filtered and capped frames case * Fix lint --------- Co-authored-by: Ugaitz Urien <[email protected]>
* Stack trace collection configuration * Collect and report stack trace for appsec events * Handle generate_stack waf action * Fix linting in config.spec.js * Add assertion for stack trace tag in meta_struct for express test * Refactor reportStackTrace and some additional test * Fix lint * Additional assert in reportStackTrace test * Update config * Rework on stack trace collection * Callsite line and column as numbers * Update packages/dd-trace/src/appsec/stack_trace.js Co-authored-by: Ugaitz Urien <[email protected]> * Update packages/dd-trace/src/appsec/stack_trace.js Co-authored-by: Ugaitz Urien <[email protected]> * Reorder test structure * Fix linting * No exploit stack limit when max is set to 0 or below * Fix filtered and capped frames case * Fix lint --------- Co-authored-by: Ugaitz Urien <[email protected]>
* Stack trace collection configuration * Collect and report stack trace for appsec events * Handle generate_stack waf action * Fix linting in config.spec.js * Add assertion for stack trace tag in meta_struct for express test * Refactor reportStackTrace and some additional test * Fix lint * Additional assert in reportStackTrace test * Update config * Rework on stack trace collection * Callsite line and column as numbers * Update packages/dd-trace/src/appsec/stack_trace.js Co-authored-by: Ugaitz Urien <[email protected]> * Update packages/dd-trace/src/appsec/stack_trace.js Co-authored-by: Ugaitz Urien <[email protected]> * Reorder test structure * Fix linting * No exploit stack limit when max is set to 0 or below * Fix filtered and capped frames case * Fix lint --------- Co-authored-by: Ugaitz Urien <[email protected]>
* Stack trace collection configuration * Collect and report stack trace for appsec events * Handle generate_stack waf action * Fix linting in config.spec.js * Add assertion for stack trace tag in meta_struct for express test * Refactor reportStackTrace and some additional test * Fix lint * Additional assert in reportStackTrace test * Update config * Rework on stack trace collection * Callsite line and column as numbers * Update packages/dd-trace/src/appsec/stack_trace.js Co-authored-by: Ugaitz Urien <[email protected]> * Update packages/dd-trace/src/appsec/stack_trace.js Co-authored-by: Ugaitz Urien <[email protected]> * Reorder test structure * Fix linting * No exploit stack limit when max is set to 0 or below * Fix filtered and capped frames case * Fix lint --------- Co-authored-by: Ugaitz Urien <[email protected]>
* Stack trace collection configuration * Collect and report stack trace for appsec events * Handle generate_stack waf action * Fix linting in config.spec.js * Add assertion for stack trace tag in meta_struct for express test * Refactor reportStackTrace and some additional test * Fix lint * Additional assert in reportStackTrace test * Update config * Rework on stack trace collection * Callsite line and column as numbers * Update packages/dd-trace/src/appsec/stack_trace.js Co-authored-by: Ugaitz Urien <[email protected]> * Update packages/dd-trace/src/appsec/stack_trace.js Co-authored-by: Ugaitz Urien <[email protected]> * Reorder test structure * Fix linting * No exploit stack limit when max is set to 0 or below * Fix filtered and capped frames case * Fix lint --------- Co-authored-by: Ugaitz Urien <[email protected]>
* Stack trace collection configuration * Collect and report stack trace for appsec events * Handle generate_stack waf action * Fix linting in config.spec.js * Add assertion for stack trace tag in meta_struct for express test * Refactor reportStackTrace and some additional test * Fix lint * Additional assert in reportStackTrace test * Update config * Rework on stack trace collection * Callsite line and column as numbers * Update packages/dd-trace/src/appsec/stack_trace.js Co-authored-by: Ugaitz Urien <[email protected]> * Update packages/dd-trace/src/appsec/stack_trace.js Co-authored-by: Ugaitz Urien <[email protected]> * Reorder test structure * Fix linting * No exploit stack limit when max is set to 0 or below * Fix filtered and capped frames case * Fix lint --------- Co-authored-by: Ugaitz Urien <[email protected]>
What does this PR do?
Collects and reports stack traces whenever
generate_stack
action is provided by the waf.Stack trace library frames are stripped out from reported list to ensure that truncated stack traces aren’t polluted by instrumentation frames or otherwise, allowing customers to focus only on frames relevant to them.
Stack traces are sent as part of root span using the tag
_dd.stack
, inmeta_struct
field.Three new configurations have been added to control this feature. Check them here.
Motivation
To provide important information to the customer to understand where the vulnerability exists in their code base.
Additional Notes
N/A
APPSEC-53369