Skip to content
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

Check store has value before use it #3257

Merged
merged 1 commit into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class SqlInjectionAnalyzer extends InjectionAnalyzer {

this.addSub('datadog:sequelize:query:finish', () => {
const store = storage.getStore()
if (store.sequelizeParentStore) {
if (store && store.sequelizeParentStore) {
iunanua marked this conversation as resolved.
Show resolved Hide resolved
storage.enterWith(store.sequelizeParentStore)
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

const proxyquire = require('proxyquire')

const iastLog = require('../../../../src/appsec/iast/iast-log')
const dc = require('../../../../../diagnostics_channel')

describe('sql-injection-analyzer', () => {
const NOT_TAINTED_QUERY = 'no vulnerable query'
const TAINTED_QUERY = 'vulnerable query'
Expand All @@ -19,6 +22,10 @@ describe('sql-injection-analyzer', () => {
'./injection-analyzer': InjectionAnalyzer
})

afterEach(() => {
sinon.restore()
})

it('should subscribe to mysql, mysql2 and pg start query channel', () => {
expect(sqlInjectionAnalyzer._subscriptions).to.have.lengthOf(5)
expect(sqlInjectionAnalyzer._subscriptions[0]._channel.name).to.equals('apm:mysql:query:start')
Expand Down Expand Up @@ -83,4 +90,12 @@ describe('sql-injection-analyzer', () => {
evidence: { dialect: dialect }
})
})

it('should not report an error when context is not initialized', () => {
sinon.stub(iastLog, 'errorAndPublish')
sqlInjectionAnalyzer.configure(true)
dc.channel('datadog:sequelize:query:finish').publish()
sqlInjectionAnalyzer.configure(false)
expect(iastLog.errorAndPublish).not.to.be.called
})
})