Repository navigation
FIX Allow backslash-digit sequences such as regex backreferences in CodeChameleonConverter decrypt functions - #4261
Open
Shivam Sharma (ShivamSharma43) wants to merge 1 commit into
Conversation
…odeChameleonConverter decrypt functions _stringify_decrypt rejected any decryption code containing a backslash followed by a digit to avoid re.sub group-reference errors when the YAML template was applied. The template is now rendered with Jinja2, which inserts the code as is, so the check only rejected valid functions. Fixes microsoft#4260 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Description
Fixes #4260.
With
encrypt_type="custom",_stringify_decrypt()raisedValueError: Illegal character sequence in user decrypt function!for any decryption code containing a backslash followed by a digit. The check was there to avoid "invalid group reference" errors when the YAML template was applied withre.sub.convert_async()now renders the template withSeedPrompt.render_template_value()(a Jinja2 sandbox), which insertsdecrypt_functionas is, so the check only rejected valid code, such as a regex backreference (r"\2 \1") or'\0'. Because it ran in__init__, the converter couldn't be built at all.reimport fromcodechameleon_converter.py.re.sub(..., r"\2 \1", ...)plus aSEPARATOR = '\0'string element. It checks that the code is rendered into the prompt unchanged, then runs the rendered code and checks it decrypts the encoded prompt.Before / after for the repro in #4260:
This change was prepared with the help of Claude Code (an AI coding assistant). I reviewed the change and the tests.
🤖 Generated with Claude Code