-
Notifications
You must be signed in to change notification settings - Fork 228
Fix @mention sanitization bypass with underscore prefix #15076
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 | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -297,7 +297,9 @@ function neutralizeCommands(s) { | |||||||||||||||||||||||||
| function neutralizeAllMentions(s) { | ||||||||||||||||||||||||||
| // Replace @name or @org/team outside code with `@name` | ||||||||||||||||||||||||||
| // No filtering - all mentions are neutralized | ||||||||||||||||||||||||||
| return s.replace(/(^|[^\w`])@([A-Za-z0-9](?:[A-Za-z0-9_-]{0,37}[A-Za-z0-9])?(?:\/[A-Za-z0-9._-]+)?)/g, (m, p1, p2) => { | ||||||||||||||||||||||||||
| // Changed [^\w`] to [^A-Za-z0-9`] to include underscore as a valid preceding character | ||||||||||||||||||||||||||
| // This prevents bypass patterns like "test_@user" from escaping sanitization | ||||||||||||||||||||||||||
| return s.replace(/(^|[^A-Za-z0-9`])@([A-Za-z0-9](?:[A-Za-z0-9_-]{0,37}[A-Za-z0-9])?(?:\/[A-Za-z0-9._-]+)?)/g, (m, p1, p2) => { | ||||||||||||||||||||||||||
| // Log when a mention is escaped to help debug issues | ||||||||||||||||||||||||||
| if (typeof core !== "undefined" && core.info) { | ||||||||||||||||||||||||||
| core.info(`Escaped mention: @${p2} (not in allowed list)`); | ||||||||||||||||||||||||||
|
Comment on lines
+300
to
305
|
||||||||||||||||||||||||||
| // Changed [^\w`] to [^A-Za-z0-9`] to include underscore as a valid preceding character | |
| // This prevents bypass patterns like "test_@user" from escaping sanitization | |
| return s.replace(/(^|[^A-Za-z0-9`])@([A-Za-z0-9](?:[A-Za-z0-9_-]{0,37}[A-Za-z0-9])?(?:\/[A-Za-z0-9._-]+)?)/g, (m, p1, p2) => { | |
| // Log when a mention is escaped to help debug issues | |
| if (typeof core !== "undefined" && core.info) { | |
| core.info(`Escaped mention: @${p2} (not in allowed list)`); | |
| // Changed [^\w`] to [^A-Za-z0-9`] to treat underscore as a separator before mentions | |
| // This ensures patterns like "test_@user" are matched and neutralized instead of bypassing | |
| return s.replace(/(^|[^A-Za-z0-9`])@([A-Za-z0-9](?:[A-Za-z0-9_-]{0,37}[A-Za-z0-9])?(?:\/[A-Za-z0-9._-]+)?)/g, (m, p1, p2) => { | |
| // Log when a mention is neutralized to help debug issues | |
| if (typeof core !== "undefined" && core.info) { | |
| core.info(`Escaped mention: @${p2}`); |
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.
These new bypass tests only exercise the default path (no allowedAliases), which uses sanitizeContentCore. The underscore-prefix bypass still exists in other code paths that use the old boundary regex (e.g. sanitizeContent() when allowedAliases is non-empty, and other mention regex usages in this package). Add at least one test that calls sanitizeContent with a non-empty allowedAliases list and asserts that an underscore-prefixed disallowed mention (e.g. "ok @Allowed and test_@admin" with allowedAliases ["allowed"]) is still neutralized; then update the corresponding implementation(s) to use the same boundary fix.