Repository navigation
Commit 213cbf6
authored
validate variable names in copyToGlobals debug handler (#1537)
**Expression injection via unvalidated variable names in copyToGlobals**
While reading through the debug handlers I noticed `copyToGlobals` drops
the client-supplied `dstVariableName` straight into
`globals()['{dst_var_name}']` and forwards that to `setExpression`, and
hands `srcVariableName` over as the value expression, with neither of
them checked. Its sibling `richInspectVariables` already runs
`str.isidentifier` over the name it evaluates, so the omission here
stood out. A name such as `x'] or __import__('os').system('id') or
globals()['y` closes the quoted string and injects an arbitrary
expression that debugpy then evaluates in the debuggee frame; the
forwarded `setExpression` payload showed the escaped quotes plainly once
I logged it.
Left as is this lets a malformed or hostile debug request steer
evaluation well beyond a variable copy. The change rejects any
`dstVariableName`/`srcVariableName` that is not a valid identifier
before the expression is built, mirroring the guard the sibling handler
already applies. Added a regression under the existing debugger tests
that confirms such a request is refused locally rather than forwarded.2 files changed
Lines changed: 30 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
681 | 681 | | |
682 | 682 | | |
683 | 683 | | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
684 | 693 | | |
685 | 694 | | |
686 | 695 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
473 | 473 | | |
474 | 474 | | |
475 | 475 | | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
476 | 497 | | |
477 | 498 | | |
478 | 499 | | |
| |||
0 commit comments