Skip to content

Commit 6dc2181

Browse files
committed
Reject security control with non numeric parameters
1 parent c31e0ff commit 6dc2181

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

packages/dd-trace/src/appsec/iast/security-controls/parser.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,12 @@ function parseControl (control) {
5858

5959
method = method?.trim()
6060

61-
parameters = getParameters(parameters)
61+
try {
62+
parameters = getParameters(parameters)
63+
} catch (e) {
64+
log.warn('[ASM] Invalid non-numeric security control parameter %s', parameters)
65+
return
66+
}
6267

6368
return { type, secureMarks, file, method, parameters }
6469
}
@@ -72,12 +77,11 @@ function getSecureMarks (marks) {
7277
function getParameters (parameters) {
7378
return parameters?.split(SECURITY_CONTROL_ELEMENT_DELIMITER)
7479
.map(param => {
75-
let parsedParam = parseInt(param, 10)
80+
const parsedParam = parseInt(param, 10)
7681

77-
// TODO: should we discard the whole securityControl??
82+
// discard the securityControl if there is an incorrect parameter
7883
if (isNaN(parsedParam)) {
79-
log.warn('[ASM] Invalid non-numeric security control parameter %s', param)
80-
parsedParam = undefined
84+
throw new Error('Invalid non-numeric security control parameter')
8185
}
8286

8387
return parsedParam

packages/dd-trace/test/appsec/iast/security-controls/parser.spec.js

+9
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ describe('IAST Security Controls parser', () => {
4242
assert.isUndefined(civ)
4343
})
4444

45+
it('should not parse invalid parameter in security control definition', () => {
46+
const conf = 'INPUT_VALIDATOR:INVALID_MARK:bar/foo/custom_input_validator.js:validate:not_numeric_parameter'
47+
const securityControls = parse(conf)
48+
49+
const civ = securityControls.get(civFilename)
50+
51+
assert.isUndefined(civ)
52+
})
53+
4554
it('should parse valid simple security control definition without parameters', () => {
4655
const conf = 'INPUT_VALIDATOR:COMMAND_INJECTION:bar/foo/custom_input_validator.js:validate'
4756
const securityControls = parse(conf)

0 commit comments

Comments
 (0)