Skip to content

Commit 3be9610

Browse files
committed
sanitize @-prefixed refs in debugger expression compiler
1 parent 83254be commit 3be9610

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

packages/debugger/src/domain/expression.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,11 @@ export function compile(node: ExpressionNode): string | number | boolean | null
142142
? `(typeof ${compile(target)} === '${typeName}')`
143143
: `Function.prototype[Symbol.hasInstance].call(${assertIdentifier(typeName)}, ${compile(target)})`
144144
} else if (type === 'ref') {
145-
const refValue = value as string
145+
const refValue = assertIdentifier(value as string)
146146
if (refValue.startsWith('@')) {
147147
return `$dd_${refValue.slice(1)}`
148148
}
149-
return assertIdentifier(refValue)
149+
return refValue
150150
} else if (Array.isArray(value)) {
151151
const args = value.map((v) => compile(v as ExpressionNode))
152152
switch (type) {

packages/debugger/test/expressionTestCases.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,26 @@ export const references: TestCase[] = [
121121
expected: new SyntaxError('Illegal identifier: throw new Error()'),
122122
execute: false,
123123
},
124+
{
125+
ast: { ref: '@x; throw new Error("injected"); //' },
126+
expected: new SyntaxError('Illegal identifier: @x; throw new Error("injected"); //'),
127+
execute: false,
128+
},
129+
{
130+
ast: { ref: '@x.y' },
131+
expected: new SyntaxError('Illegal identifier: @x.y'),
132+
execute: false,
133+
},
134+
{
135+
ast: { ref: '@x-y' },
136+
expected: new SyntaxError('Illegal identifier: @x-y'),
137+
execute: false,
138+
},
139+
{
140+
ast: { ref: '@(1)' },
141+
expected: new SyntaxError('Illegal identifier: @(1)'),
142+
execute: false,
143+
},
124144
]
125145

126146
export const propertyAccess: TestCase[] = [

0 commit comments

Comments
 (0)