Skip to content

Commit 30ca014

Browse files
authored
Check store has value before use it (#3257)
1 parent bce0ee1 commit 30ca014

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class SqlInjectionAnalyzer extends InjectionAnalyzer {
2828

2929
this.addSub('datadog:sequelize:query:finish', () => {
3030
const store = storage.getStore()
31-
if (store.sequelizeParentStore) {
31+
if (store && store.sequelizeParentStore) {
3232
storage.enterWith(store.sequelizeParentStore)
3333
}
3434
})

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
const proxyquire = require('proxyquire')
44

5+
const iastLog = require('../../../../src/appsec/iast/iast-log')
6+
const dc = require('../../../../../diagnostics_channel')
7+
58
describe('sql-injection-analyzer', () => {
69
const NOT_TAINTED_QUERY = 'no vulnerable query'
710
const TAINTED_QUERY = 'vulnerable query'
@@ -19,6 +22,10 @@ describe('sql-injection-analyzer', () => {
1922
'./injection-analyzer': InjectionAnalyzer
2023
})
2124

25+
afterEach(() => {
26+
sinon.restore()
27+
})
28+
2229
it('should subscribe to mysql, mysql2 and pg start query channel', () => {
2330
expect(sqlInjectionAnalyzer._subscriptions).to.have.lengthOf(5)
2431
expect(sqlInjectionAnalyzer._subscriptions[0]._channel.name).to.equals('apm:mysql:query:start')
@@ -83,4 +90,12 @@ describe('sql-injection-analyzer', () => {
8390
evidence: { dialect: dialect }
8491
})
8592
})
93+
94+
it('should not report an error when context is not initialized', () => {
95+
sinon.stub(iastLog, 'errorAndPublish')
96+
sqlInjectionAnalyzer.configure(true)
97+
dc.channel('datadog:sequelize:query:finish').publish()
98+
sqlInjectionAnalyzer.configure(false)
99+
expect(iastLog.errorAndPublish).not.to.be.called
100+
})
86101
})

0 commit comments

Comments
 (0)