-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
fix(security): neutralize delimiter injection bypasses #2395
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -163,7 +163,7 @@ const OBFUSCATION_PATTERN_ENTRIES = [ | |||||
| }, | ||||||
| { | ||||||
| pattern: /<\/?(system|human|assistant|user)\s*>/i, | ||||||
| message: 'Delimiter injection pattern: <system>/<assistant>/<user> tag detected', | ||||||
| message: 'Delimiter injection pattern: system/assistant/user-style tag detected', | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Detection message is now missing This can mislead findings triage and test expectations. 💡 Suggested text fix- message: 'Delimiter injection pattern: system/assistant/user-style tag detected',
+ message: 'Delimiter injection pattern: system/assistant/human/user-style tag detected',📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| }, | ||||||
| { | ||||||
| pattern: /0x[0-9a-fA-F]{16,}/, | ||||||
|
|
@@ -245,14 +245,17 @@ function sanitizeForPrompt(text) { | |||||
| // Neutralize XML/HTML tags that mimic system boundaries | ||||||
| // Replace < > with full-width equivalents to prevent tag interpretation | ||||||
| // Note: <instructions> is excluded — GSD uses it as legitimate prompt structure | ||||||
| sanitized = sanitized.replace(/<(\/?)(?:system|assistant|human)>/gi, | ||||||
| (_, slash) => `<${slash || ''}system-text>`); | ||||||
| sanitized = sanitized.replace( | ||||||
| /<(\/?)(system|assistant|human|user)\s*>/gi, | ||||||
| (_, slash, role) => `<${slash || ''}${String(role).toLowerCase()}-text>` | ||||||
| ); | ||||||
|
|
||||||
| // Neutralize [SYSTEM] / [INST] markers | ||||||
| sanitized = sanitized.replace(/\[(SYSTEM|INST)\]/gi, '[$1-TEXT]'); | ||||||
| sanitized = sanitized.replace(/\[(\/?)(SYSTEM|INST)\]/gi, | ||||||
| (_, slash, marker) => `[${slash || ''}${marker.toUpperCase()}-TEXT]`); | ||||||
|
|
||||||
| // Neutralize <<SYS>> markers | ||||||
| sanitized = sanitized.replace(/<<\s*SYS\s*>>/gi, '«SYS-TEXT»'); | ||||||
| sanitized = sanitized.replace(/<<\s*\/?\s*SYS\s*>>/gi, '«SYS-TEXT»'); | ||||||
|
|
||||||
| return sanitized; | ||||||
| } | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changelog text includes bracket markers as
[\/SYSTEM]/[\/INST]. In Markdown this likely renders with the backslashes visible (since/doesn’t need escaping), which makes the example tokens inaccurate. Consider changing these to[/SYSTEM]/[/INST](and similarly for any other escaped slashes) so the entry matches the actual markers being neutralized.