-
Notifications
You must be signed in to change notification settings - Fork 312
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
[asm] IAST security controls #5117
Open
iunanua
wants to merge
43
commits into
master
Choose a base branch
from
igor/iast-security-controls
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 30 commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
d5a52ea
Security controls parser and secure marks for vulnerabilities
iunanua c4c398c
Use new NOSQL_MONGODB_INJECTION_MARK in nosql-injection-mongodb-analyzer
iunanua 9a1229c
Config
iunanua dce2f18
first hooks
iunanua ac1d502
wrap object properties and more tests
iunanua 4cc7895
Use dd-trace:moduleLoad(Start|End) channels
iunanua 6fe83f6
iterate object strings and more tests
iunanua 4e4d69e
fix parameter index, include createNewTainted flag and do not use Plu…
iunanua 90b9ff8
Fix parameter index and include a test with incorrect index
iunanua 2d86aee
Avoid to hook multiple times the same module and config tests
iunanua 5ed8aa2
sql_injection_mark test
iunanua 57548b0
vulnerable ranges tests
iunanua 610e216
fix windows paths
iunanua ca0bbe5
Merge branch 'master' into igor/iast-security-controls
iunanua b4a217e
Upgrade taint-tracking to 3.3.0
iunanua 0b0c292
Fix * secure mark
iunanua af61bf9
add createNewTainted flag to addSecureMark
iunanua fb1de25
Use existing _isRangeSecure
iunanua 384d526
supressed vulnerabilities metric
iunanua fce89df
increment supressed vulnerability metric
iunanua c324c58
typo
iunanua 767d2db
handle esm default export and filenames starting with file://
iunanua 082ac75
esm integration tests
iunanua 4b948ad
clean up
iunanua d9c1393
secure-marks tests
iunanua 1fdaf86
Merge branch 'master' into igor/iast-security-controls
iunanua 3b697d1
fix secure-marks generator test
iunanua 07dcc02
fix config test
iunanua 5556875
empty
iunanua 3f57dea
check for repeated marks
iunanua d67c179
Update packages/dd-trace/src/appsec/iast/analyzers/injection-analyzer.js
iunanua 1870856
Update packages/dd-trace/src/appsec/iast/security-controls/index.js
iunanua 0d94fdc
Update packages/dd-trace/src/appsec/iast/taint-tracking/secure-marks.js
iunanua dd9721d
some suggestions
iunanua 1e83152
move _isRangeSecure to InjectionAnalyzer
iunanua 9ebe9d8
Add programatically config option
iunanua 0ffe2bf
index.d.ts
iunanua 5de1eec
Merge branch 'master' into igor/iast-security-controls
iunanua e8f623f
StoredInjectionAnalyzer
iunanua de6bc7f
Update packages/dd-trace/test/appsec/iast/analyzers/command-injection…
iunanua a88ce85
store control keys to avoid recreating the array
iunanua a0cd2bc
check visited before iterating
iunanua cbc2355
Merge branch 'master' into igor/iast-security-controls
iunanua File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
'use strict' | ||
|
||
import childProcess from 'node:child_process' | ||
import express from 'express' | ||
import { sanitize } from './sanitizer.mjs' | ||
import sanitizeDefault from './sanitizer-default.mjs' | ||
import { validate, validateNotConfigured } from './validator.mjs' | ||
|
||
const app = express() | ||
const port = process.env.APP_PORT || 3000 | ||
|
||
app.get('/cmdi-s-secure', (req, res) => { | ||
const command = sanitize(req.query.command) | ||
try { | ||
childProcess.execSync(command) | ||
} catch (e) { | ||
// ignore | ||
} | ||
|
||
res.end() | ||
}) | ||
|
||
app.get('/cmdi-s-secure-default', (req, res) => { | ||
const command = sanitizeDefault(req.query.command) | ||
try { | ||
childProcess.execSync(command) | ||
} catch (e) { | ||
// ignore | ||
} | ||
|
||
res.end() | ||
}) | ||
|
||
app.get('/cmdi-iv-insecure', (req, res) => { | ||
if (validateNotConfigured(req.query.command)) { | ||
childProcess.execSync(req.query.command) | ||
} | ||
|
||
res.end() | ||
}) | ||
|
||
app.get('/cmdi-iv-secure', (req, res) => { | ||
if (validate(req.query.command)) { | ||
childProcess.execSync(req.query.command) | ||
} | ||
|
||
res.end() | ||
}) | ||
|
||
app.listen(port, () => { | ||
process.send({ port }) | ||
}) |
7 changes: 7 additions & 0 deletions
7
integration-tests/appsec/esm-security-controls/sanitizer-default.mjs
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,7 @@ | ||
'use strict' | ||
|
||
function sanitizeDefault (input) { | ||
return input | ||
} | ||
|
||
export default sanitizeDefault |
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,5 @@ | ||
'use strict' | ||
|
||
export function sanitize (input) { | ||
return input | ||
} |
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,9 @@ | ||
'use strict' | ||
|
||
export function validate (input) { | ||
return true | ||
} | ||
|
||
export function validateNotConfigured (input) { | ||
return true | ||
} |
103 changes: 103 additions & 0 deletions
103
integration-tests/appsec/iast.esm-security-controls.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,103 @@ | ||
'use strict' | ||
|
||
const { createSandbox, spawnProc, FakeAgent } = require('../helpers') | ||
const path = require('path') | ||
const getPort = require('get-port') | ||
const Axios = require('axios') | ||
const { assert } = require('chai') | ||
|
||
describe('ESM Security controls', () => { | ||
let axios, sandbox, cwd, appPort, appFile, agent, proc | ||
|
||
before(async function () { | ||
this.timeout(process.platform === 'win32' ? 90000 : 30000) | ||
sandbox = await createSandbox(['express']) | ||
appPort = await getPort() | ||
cwd = sandbox.folder | ||
appFile = path.join(cwd, 'appsec', 'esm-security-controls', 'index.mjs') | ||
|
||
axios = Axios.create({ | ||
baseURL: `http://localhost:${appPort}` | ||
}) | ||
}) | ||
|
||
after(async function () { | ||
await sandbox.remove() | ||
}) | ||
const nodeOptions = '--import dd-trace/initialize.mjs' | ||
|
||
describe('with --import', () => { | ||
beforeEach(async () => { | ||
agent = await new FakeAgent().start() | ||
|
||
proc = await spawnProc(appFile, { | ||
cwd, | ||
env: { | ||
DD_TRACE_AGENT_PORT: agent.port, | ||
APP_PORT: appPort, | ||
DD_IAST_ENABLED: 'true', | ||
DD_IAST_REQUEST_SAMPLING: '100', | ||
// eslint-disable-next-line no-multi-str | ||
DD_IAST_SECURITY_CONTROLS_CONFIGURATION: '\ | ||
SANITIZER:COMMAND_INJECTION:appsec/esm-security-controls/sanitizer.mjs:sanitize;\ | ||
SANITIZER:COMMAND_INJECTION:appsec/esm-security-controls/sanitizer-default.mjs;\ | ||
INPUT_VALIDATOR:*:appsec/esm-security-controls/validator.mjs:validate', | ||
NODE_OPTIONS: nodeOptions | ||
} | ||
}) | ||
}) | ||
|
||
afterEach(async () => { | ||
proc.kill() | ||
await agent.stop() | ||
}) | ||
|
||
it('test endpoint with iv not configured have COMMAND_INJECTION vulnerability', async function () { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is "iv"? |
||
await axios.get('/cmdi-iv-insecure?command=ls -la') | ||
|
||
await agent.assertMessageReceived(({ payload }) => { | ||
const spans = payload.flatMap(p => p.filter(span => span.name === 'express.request')) | ||
spans.forEach(span => { | ||
assert.property(span.meta, '_dd.iast.json') | ||
assert.include(span.meta['_dd.iast.json'], '"COMMAND_INJECTION"') | ||
}) | ||
}, null, 1, true) | ||
}) | ||
|
||
it('test endpoint sanitizer do not have COMMAND_INJECTION vulnerability', async () => { | ||
await axios.get('/cmdi-s-secure?command=ls -la') | ||
|
||
await agent.assertMessageReceived(({ payload }) => { | ||
const spans = payload.flatMap(p => p.filter(span => span.name === 'express.request')) | ||
spans.forEach(span => { | ||
assert.notProperty(span.meta, '_dd.iast.json') | ||
assert.property(span.metrics, '_dd.iast.telemetry.suppressed.vulnerabilities.command_injection') | ||
}) | ||
}, null, 1, true) | ||
}) | ||
|
||
it('test endpoint with default sanitizer do not have COMMAND_INJECTION vulnerability', async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I miss a test checking that the usage of the input of the sanitizer is considered vulnerable: const untrustedData = req.query.command
const safeData = sanitize(untrustedData)
exec(untrustedData) // this is vulnerable
exec(safeData) // this is not vulnerable |
||
await axios.get('/cmdi-s-secure-default?command=ls -la') | ||
|
||
await agent.assertMessageReceived(({ payload }) => { | ||
const spans = payload.flatMap(p => p.filter(span => span.name === 'express.request')) | ||
spans.forEach(span => { | ||
assert.notProperty(span.meta, '_dd.iast.json') | ||
assert.property(span.metrics, '_dd.iast.telemetry.suppressed.vulnerabilities.command_injection') | ||
}) | ||
}, null, 1, true) | ||
}) | ||
|
||
it('test endpoint with iv do not have COMMAND_INJECTION vulnerability', async () => { | ||
await axios.get('/cmdi-iv-secure?command=ls -la') | ||
|
||
await agent.assertMessageReceived(({ payload }) => { | ||
const spans = payload.flatMap(p => p.filter(span => span.name === 'express.request')) | ||
spans.forEach(span => { | ||
assert.notProperty(span.meta, '_dd.iast.json') | ||
assert.property(span.metrics, '_dd.iast.telemetry.suppressed.vulnerabilities.command_injection') | ||
}) | ||
}, null, 1, true) | ||
}) | ||
}) | ||
}) |
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
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this
with --import
relevant?nodeOptions
is defined asconst
out of thedescribe