Skip to content

Prevent special token injection from user-provided text - #770

Open
niraj-mx07 wants to merge 1 commit into
google-deepmind:mainfrom
niraj-mx07:main
Open

Prevent special token injection from user-provided text#770
niraj-mx07 wants to merge 1 commit into
google-deepmind:mainfrom
niraj-mx07:main

Conversation

@niraj-mx07

Copy link
Copy Markdown

Summary

Fixes the prompt-structure injection issue described in #768 by escaping characters that can introduce Gemma's special control sequences when processing user-provided text.

Changes

  • Added an escape() method to the tokenizer to escape characters used in special token sequences.
  • Prevented escaped special sequences from being interpreted as Gemma control tokens during tokenization.
  • Preserved normal tokenization behavior for regular text.
  • Added a test covering the updated tokenization behavior.

Motivation

User-controlled text containing sequences such as <|turn> could previously be interpreted as special Gemma control tokens rather than ordinary text. This could allow untrusted input to alter the intended conversation structure.

This change ensures that special sequences originating from user-provided text are treated as text instead of being interpreted as control tokens.

Fixes #768

…not accidentally be interpreted as chat structure
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.

Missing escape sequence allows to inject a system message

1 participant