-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Untrusted deserialization vulnerability detection
- Loading branch information
1 parent
4d6a8e3
commit 9ddb298
Showing
10 changed files
with
129 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict' | ||
|
||
const shimmer = require('../../datadog-shimmer') | ||
const { channel, addHook } = require('./helpers/instrument') | ||
|
||
const nodeUnserializeCh = channel('datadog:node-serialize:unserialize:start') | ||
|
||
function wrapUnserialize (serialize) { | ||
return function wrappedUnserialize (obj) { | ||
if (nodeUnserializeCh.hasSubscribers) { | ||
nodeUnserializeCh.publish({ obj }) | ||
} | ||
|
||
return serialize.apply(this, arguments) | ||
} | ||
} | ||
|
||
addHook({ name: 'node-serialize', versions: ['0'] }, serialize => { | ||
shimmer.wrap(serialize, 'unserialize', wrapUnserialize) | ||
|
||
return serialize | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
packages/dd-trace/src/appsec/iast/analyzers/untrusted-deserialization-analyzer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use strict' | ||
|
||
const InjectionAnalyzer = require('./injection-analyzer') | ||
const { UNTRUSTED_DESERIALIZATION } = require('../vulnerabilities') | ||
|
||
class UntrustedDeserializationAnalyzer extends InjectionAnalyzer { | ||
constructor () { | ||
super(UNTRUSTED_DESERIALIZATION) | ||
} | ||
|
||
onConfigure () { | ||
this.addSub('datadog:node-serialize:unserialize:start', ({ obj }) => this.analyze(obj)) | ||
} | ||
|
||
_areRangesVulnerable () { | ||
return true | ||
} | ||
} | ||
|
||
module.exports = new UntrustedDeserializationAnalyzer() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...st/appsec/iast/analyzers/untrusted-deserialization-analyzer.node-serialize.plugin.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
'use strict' | ||
|
||
const { prepareTestServerForIast } = require('../utils') | ||
const { storage } = require('../../../../../datadog-core') | ||
const iastContextFunctions = require('../../../../src/appsec/iast/iast-context') | ||
const { newTaintedString } = require('../../../../src/appsec/iast/taint-tracking/operations') | ||
const { SQL_ROW_VALUE } = require('../../../../src/appsec/iast/taint-tracking/source-types') | ||
|
||
describe('untrusted-deserialization-analyzer with node-serialize', () => { | ||
withVersions('node-serialize', 'node-serialize', version => { | ||
let obj | ||
before(() => { | ||
obj = JSON.stringify({ name: 'example' }) | ||
}) | ||
|
||
describe('unserialize', () => { | ||
prepareTestServerForIast('untrusted deserialization analyzer', | ||
(testThatRequestHasVulnerability, testThatRequestHasNoVulnerability) => { | ||
let lib | ||
beforeEach(() => { | ||
lib = require(`../../../../../../versions/node-serialize@${version}`).get() | ||
}) | ||
|
||
testThatRequestHasVulnerability(() => { | ||
const store = storage.getStore() | ||
const iastContext = iastContextFunctions.getIastContext(store) | ||
const str = newTaintedString(iastContext, obj, 'query', 'Request') | ||
lib.unserialize(str) | ||
}, 'UNTRUSTED_DESERIALIZATION') | ||
|
||
testThatRequestHasVulnerability(() => { | ||
const store = storage.getStore() | ||
const iastContext = iastContextFunctions.getIastContext(store) | ||
const str = newTaintedString(iastContext, obj, 'query', SQL_ROW_VALUE) | ||
lib.unserialize(str) | ||
}, 'UNTRUSTED_DESERIALIZATION', undefined, undefined, undefined, | ||
'Should detect UNTRUSTED_DESERIALIZATION vulnerability with DB source') | ||
|
||
testThatRequestHasNoVulnerability(() => { | ||
lib.unserialize(obj) | ||
}, 'UNTRUSTED_DESERIALIZATION') | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters