1
1
'use strict'
2
2
3
3
const { storage } = require ( '../../../../../datadog-core' )
4
- const { getFirstNonDDPathAndLine } = require ( '../path-line' )
5
- const { addVulnerability } = require ( '../vulnerability-reporter' )
6
- const { getIastContext } = require ( '../iast-context' )
4
+ const { getNonDDCallSiteFrames } = require ( '../path-line' )
5
+ const { getIastContext, getIastStackTraceId } = require ( '../iast-context' )
7
6
const overheadController = require ( '../overhead-controller' )
8
7
const { SinkIastPlugin } = require ( '../iast-plugin' )
9
- const { getOriginalPathAndLineFromSourceMap } = require ( '../taint-tracking/rewriter' )
8
+ const {
9
+ addVulnerability,
10
+ getVulnerabilityCallSiteFrames,
11
+ replaceCallSiteFromSourceMap
12
+ } = require ( '../vulnerability-reporter' )
10
13
11
14
class Analyzer extends SinkIastPlugin {
12
15
constructor ( type ) {
@@ -28,12 +31,24 @@ class Analyzer extends SinkIastPlugin {
28
31
}
29
32
30
33
_reportEvidence ( value , context , evidence ) {
31
- const location = this . _getLocation ( value )
34
+ const callSiteFrames = getVulnerabilityCallSiteFrames ( )
35
+ const nonDDCallSiteFrames = getNonDDCallSiteFrames ( callSiteFrames , this . _getExcludedPaths ( ) )
36
+
37
+ const location = this . _getLocation ( value , nonDDCallSiteFrames )
38
+
32
39
if ( ! this . _isExcluded ( location ) ) {
33
- const locationSourceMap = this . _replaceLocationFromSourceMap ( location )
40
+ const originalLocation = this . _getOriginalLocation ( location )
34
41
const spanId = context && context . rootSpan && context . rootSpan . context ( ) . toSpanId ( )
35
- const vulnerability = this . _createVulnerability ( this . _type , evidence , spanId , locationSourceMap )
36
- addVulnerability ( context , vulnerability )
42
+ const stackId = getIastStackTraceId ( context )
43
+ const vulnerability = this . _createVulnerability (
44
+ this . _type ,
45
+ evidence ,
46
+ spanId ,
47
+ originalLocation ,
48
+ stackId
49
+ )
50
+
51
+ addVulnerability ( context , vulnerability , nonDDCallSiteFrames )
37
52
}
38
53
}
39
54
@@ -49,24 +64,25 @@ class Analyzer extends SinkIastPlugin {
49
64
return { value }
50
65
}
51
66
52
- _getLocation ( ) {
53
- return getFirstNonDDPathAndLine ( this . _getExcludedPaths ( ) )
67
+ _getLocation ( value , callSiteFrames ) {
68
+ return callSiteFrames [ 0 ]
54
69
}
55
70
56
- _replaceLocationFromSourceMap ( location ) {
57
- if ( location ) {
58
- const { path, line, column } = getOriginalPathAndLineFromSourceMap ( location )
59
- if ( path ) {
60
- location . path = path
61
- }
62
- if ( line ) {
63
- location . line = line
64
- }
65
- if ( column ) {
66
- location . column = column
67
- }
71
+ _getOriginalLocation ( location ) {
72
+ const locationFromSourceMap = replaceCallSiteFromSourceMap ( location )
73
+ const originalLocation = { }
74
+
75
+ if ( locationFromSourceMap ?. path ) {
76
+ originalLocation . path = locationFromSourceMap . path
77
+ }
78
+ if ( locationFromSourceMap ?. line ) {
79
+ originalLocation . line = locationFromSourceMap . line
68
80
}
69
- return location
81
+ if ( locationFromSourceMap ?. column ) {
82
+ originalLocation . column = locationFromSourceMap . column
83
+ }
84
+
85
+ return originalLocation
70
86
}
71
87
72
88
_getExcludedPaths ( ) { }
@@ -102,12 +118,13 @@ class Analyzer extends SinkIastPlugin {
102
118
return overheadController . hasQuota ( overheadController . OPERATIONS . REPORT_VULNERABILITY , context )
103
119
}
104
120
105
- _createVulnerability ( type , evidence , spanId , location ) {
121
+ _createVulnerability ( type , evidence , spanId , location , stackId ) {
106
122
if ( type && evidence ) {
107
123
const _spanId = spanId || 0
108
124
return {
109
125
type,
110
126
evidence,
127
+ stackId,
111
128
location : {
112
129
spanId : _spanId ,
113
130
...location
0 commit comments