semgrep
semgrep copied to clipboard
increase the scope of constant propagation to the whole file (with symbolic_propagation: true)
[Original title: javascript function variable propagation and line matching]
https://semgrep.dev/s/7Qxk
rules:
- id: bad-call
patterns:
- pattern-either:
- pattern: bad(...)
message: Found call to 'bad'
languages: [js]
severity: WARNING
function bad(s)
return s
let b1=bad
b1("1")
bad("3")
I'm a beginner with semgrep and I think this should match to the b1 function call
so i modify the rules
https://semgrep.dev/s/L2oG
rules:
- id: bad-call
patterns:
- pattern-either:
- pattern: bad(...)
- pattern: |
$X=bad
...
$X(...)
message: Found call to 'bad'
languages: [js]
severity: WARNING
Successfully matched, but it shows matching to line 4 and 7, I want to match to line 6 and 7
Or is there any rule writing to achieve this match, please tell me, thank you
This issue is synced in Linear at https://linear.app/r2c/issue/PA-1187/javascript-function-variable-propagation-and-line-matching.
I tried a new rule and it got stuck
rules:
- id: bad-call
patterns:
- pattern-either:
- pattern: bad(...)
- pattern:
- pattern-inside: |
$X=bad
...
- pattern: $X(...)
message: Found call to 'bad'
languages: [js]
severity: WARNING
@ttttmr symbolic propagation works only within (intra) procedures right now, so if you wrap those calls in a function, it should work. See https://semgrep.dev/s/WDXj
@ievans Thanks, another question is why the above rules are stuck, is this a semgrep problem, or my rules are written incorrectly
To add, I can only reopen a playground in the case of being stuck. It seems that there is no place to cancel the operation. If possible, add a cancel operation, or automatically cancel the timeout. I don’t know if the backend service has a timeout limit.