Skip to content

Commit 996e8fb

Browse files
authored
Add stack id in location as a string (#5250)
* Add stack id in location as a string * get stackId from location * remove stack id from format vuln
1 parent fd42515 commit 996e8fb

7 files changed

Lines changed: 12 additions & 13 deletions

File tree

packages/dd-trace/src/appsec/iast/analyzers/vulnerability-analyzer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ class Analyzer extends SinkIastPlugin {
133133
return {
134134
type,
135135
evidence,
136-
stackId,
137136
location: {
138137
spanId: _spanId,
138+
stackId,
139139
...location
140140
},
141141
hash: this._createHash(this._createHashSource(type, evidence, location))

packages/dd-trace/src/appsec/iast/iast-context.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ function getIastContext (store, topContext) {
1010
}
1111

1212
function getIastStackTraceId (iastContext) {
13-
if (!iastContext) return 0
13+
if (!iastContext) return '0'
1414

1515
if (!iastContext.stackTraceId) {
1616
iastContext.stackTraceId = 0
1717
}
1818

1919
iastContext.stackTraceId += 1
20-
return iastContext.stackTraceId
20+
return String(iastContext.stackTraceId)
2121
}
2222

2323
/* TODO Fix storage problem when the close event is called without

packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,11 @@ class VulnerabilityFormatter {
8181
}
8282

8383
formatVulnerability (vulnerability, sourcesIndexes, sources) {
84-
const { type, hash, stackId, evidence, location } = vulnerability
84+
const { type, hash, evidence, location } = vulnerability
8585

8686
const formattedVulnerability = {
8787
type,
8888
hash,
89-
stackId,
9089
evidence: this.formatEvidence(type, evidence, sourcesIndexes, sources),
9190
location
9291
}

packages/dd-trace/src/appsec/iast/vulnerability-reporter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function addVulnerability (iastContext, vulnerability, callSiteFrames) {
5959

6060
reportStackTrace(
6161
span,
62-
vulnerability.stackId,
62+
vulnerability.location.stackId,
6363
originalCallSiteList,
6464
STACK_TRACE_NAMESPACES.IAST
6565
)

packages/dd-trace/test/appsec/iast/analyzers/vulnerability-analyzer.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,12 @@ describe('vulnerability-analyzer', () => {
112112
context,
113113
{
114114
type: 'TEST_ANALYZER',
115-
stackId: 1,
116115
evidence: {
117116
value: 'VULNERABLE_VALUE'
118117
},
119118
location: {
120119
spanId: '123456',
120+
stackId: '1',
121121
...VULNERABILITY_LOCATION_FROM_SOURCEMAP
122122
},
123123
hash: 5975567724

packages/dd-trace/test/appsec/iast/vulnerability-formatter/index.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,13 @@ describe('Vulnerability formatter', () => {
9797
const vulnerabilities = [{
9898
type: 'test-vulnerability',
9999
hash: 123456,
100-
stackId: 1,
101100
evidence: {
102101
value: 'payload'
103102
},
104103
location: {
105104
path: 'path',
106-
line: 42
105+
line: 42,
106+
stackId: '1'
107107
}
108108
}]
109109

@@ -114,13 +114,13 @@ describe('Vulnerability formatter', () => {
114114
vulnerabilities: [{
115115
type: 'test-vulnerability',
116116
hash: 123456,
117-
stackId: 1,
118117
evidence: {
119118
value: 'payload'
120119
},
121120
location: {
122121
path: 'path',
123-
line: 42
122+
line: 42,
123+
stackId: '1'
124124
}
125125
}]
126126
})

packages/dd-trace/test/appsec/iast/vulnerability-reporter.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,15 @@ describe('vulnerability-reporter', () => {
129129
it('should create span on the fly', () => {
130130
const vulnerability =
131131
vulnerabilityAnalyzer._createVulnerability('INSECURE_HASHING', { value: 'sha1' }, undefined,
132-
{ path: 'filename.js', line: 73 }, 1)
132+
{ path: 'filename.js', line: 73 }, '1')
133133
addVulnerability(undefined, vulnerability, [])
134134
expect(fakeTracer.startSpan).to.have.been.calledOnceWithExactly('vulnerability', { type: 'vulnerability' })
135135
expect(onTheFlySpan.addTags.firstCall).to.have.been.calledWithExactly({
136136
'_dd.iast.enabled': 1
137137
})
138138
expect(onTheFlySpan.addTags.secondCall).to.have.been.calledWithExactly({
139139
'_dd.iast.json': '{"sources":[],"vulnerabilities":[{"type":"INSECURE_HASHING","hash":3410512655,' +
140-
'"stackId":1,"evidence":{"value":"sha1"},"location":{"spanId":42,"path":"filename.js","line":73}}]}'
140+
'"evidence":{"value":"sha1"},"location":{"spanId":42,"stackId":"1","path":"filename.js","line":73}}]}'
141141
})
142142
expect(prioritySampler.setPriority)
143143
.to.have.been.calledOnceWithExactly(onTheFlySpan, USER_KEEP, SAMPLING_MECHANISM_APPSEC)

0 commit comments

Comments
 (0)