fix: strip antml thinking tags#59550
Conversation
9500d38 to
b554177
Compare
🔒 Aisle Security AnalysisWe found 1 potential security issue(s) in this PR:
1. 🟡 Namespaced wrapper bypasses reasoning-tag stripping (information disclosure)
Description
After the change, namespaced thinking tags like
As a result, content wrapped in Vulnerable behavior example:
Vulnerable code: const QUICK_TAG_RE = /<\s*\/?\s*(?:(?:antml:)?(?:think(?:ing)?|thought)|antthinking|final)\b/i;
const FINAL_TAG_RE = /<\s*\/?\s*final\b[^<>]*>/gi;RecommendationTreat For example: const QUICK_TAG_RE =
/<\s*\/?\s*(?:(?:antml:)?(?:think(?:ing)?|thought|final)|antthinking)\b/i;
const FINAL_TAG_RE = /<\s*\/?\s*(?:antml:)?final\b[^<>]*>/gi;Also add tests to ensure Analyzed PR: #59550 at commit Last updated on: 2026-04-02T09:04:03Z |
|
Landed in c27b45f |
Greptile SummaryThis PR extends the shared reasoning-tag sanitizer to recognise Anthropic's namespace-prefixed Key changes:
Confidence Score: 5/5
Prompt To Fix All With AIThis is a comment left during a code review.
Path: src/shared/text/reasoning-tags.ts
Line: 5-8
Comment:
**`final` tag missing `antml:` variant in `THINKING_TAG_RE`**
`QUICK_TAG_RE` still includes `final` in its optional-namespace group, but `THINKING_TAG_RE` (and `FINAL_TAG_RE`) do not have a corresponding `antml:final` variant. If Anthropic ever emits `<final>…</final>`, `QUICK_TAG_RE` would fire but `FINAL_TAG_RE` and `THINKING_TAG_RE` would both miss it, and the tag would leak through. This is a minor consistency nit rather than a current crash, but worth noting if the same namespace treatment needs to be applied uniformly.
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "fix: strip antml thinking tags (#59550)" | Re-trigger Greptile |
| const QUICK_TAG_RE = /<\s*\/?\s*(?:(?:antml:)?(?:think(?:ing)?|thought)|antthinking|final)\b/i; | ||
| const FINAL_TAG_RE = /<\s*\/?\s*final\b[^<>]*>/gi; | ||
| const THINKING_TAG_RE = /<\s*(\/?)\s*(?:think(?:ing)?|thought|antthinking)\b[^<>]*>/gi; | ||
| const THINKING_TAG_RE = | ||
| /<\s*(\/?)\s*(?:(?:antml:)?(?:think(?:ing)?|thought)|antthinking)\b[^<>]*>/gi; |
There was a problem hiding this comment.
final tag missing antml: variant in THINKING_TAG_RE
QUICK_TAG_RE still includes final in its optional-namespace group, but THINKING_TAG_RE (and FINAL_TAG_RE) do not have a corresponding antml:final variant. If Anthropic ever emits <final>…</final>, QUICK_TAG_RE would fire but FINAL_TAG_RE and THINKING_TAG_RE would both miss it, and the tag would leak through. This is a minor consistency nit rather than a current crash, but worth noting if the same namespace treatment needs to be applied uniformly.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/shared/text/reasoning-tags.ts
Line: 5-8
Comment:
**`final` tag missing `antml:` variant in `THINKING_TAG_RE`**
`QUICK_TAG_RE` still includes `final` in its optional-namespace group, but `THINKING_TAG_RE` (and `FINAL_TAG_RE`) do not have a corresponding `antml:final` variant. If Anthropic ever emits `<final>…</final>`, `QUICK_TAG_RE` would fire but `FINAL_TAG_RE` and `THINKING_TAG_RE` would both miss it, and the tag would leak through. This is a minor consistency nit rather than a current crash, but worth noting if the same namespace treatment needs to be applied uniformly.
How can I resolve this? If you propose a fix, please make it concise.
Summary
antml:thinkingtags in the shared reasoning sanitizerTesting