Skip to content

FIX Allow backslash-digit sequences such as regex backreferences in CodeChameleonConverter decrypt functions - #4261

Open
Shivam Sharma (ShivamSharma43) wants to merge 1 commit into
microsoft:mainfrom
ShivamSharma43:fix/codechameleon-backreference-check
Open

Shivam Sharma (ShivamSharma43) wants to merge 1 commit into
microsoft:mainfrom
ShivamSharma43:fix/codechameleon-backreference-check

Conversation

@ShivamSharma43

Copy link
Copy Markdown
Contributor

Description

Fixes #4260.

With encrypt_type="custom", _stringify_decrypt() raised ValueError: 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 with re.sub. convert_async() now renders the template with SeedPrompt.render_template_value() (a Jinja2 sandbox), which inserts decrypt_function as 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.

  • Removed the check and the now unused re import from codechameleon_converter.py.
  • New test builds a custom converter whose decrypt function uses re.sub(..., r"\2 \1", ...) plus a SEPARATOR = '\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:

before: ValueError: Illegal character sequence in user decrypt function! Invalid chars: ['\2', '\1']
after:      return re.sub(r"(\S+) (\S+)", r"\2 \1", text)
        The encrypted_problem you need to solve is: to How down cut tree? a

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

…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>
Copilot AI balanced review requested due to automatic review settings November 13, 2026 06:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: CodeChameleonConverter rejects custom decrypt functions that contain a backslash followed by a digit, such as regex backreferences

2 participants