validate variable names in copyToGlobals debug handler#1537
Open
sahvx655-wq wants to merge 1 commit into
Open
Conversation
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Expression injection via unvalidated variable names in copyToGlobals
While reading through the debug handlers I noticed
copyToGlobalsdrops the client-supplieddstVariableNamestraight intoglobals()['{dst_var_name}']and forwards that tosetExpression, and handssrcVariableNameover as the value expression, with neither of them checked. Its siblingrichInspectVariablesalready runsstr.isidentifierover the name it evaluates, so the omission here stood out. A name such asx'] or __import__('os').system('id') or globals()['ycloses the quoted string and injects an arbitrary expression that debugpy then evaluates in the debuggee frame; the forwardedsetExpressionpayload 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/srcVariableNamethat 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.