Skip to content

fix(security): escape double quotes in esc() to prevent XSS#3210

Merged
aegis-gh-agent[bot] merged 1 commit into
developfrom
fix/3209-esc-double-quotes
May 11, 2026
Merged

fix(security): escape double quotes in esc() to prevent XSS#3210
aegis-gh-agent[bot] merged 1 commit into
developfrom
fix/3209-esc-double-quotes

Conversation

@OneStepAt4time

Copy link
Copy Markdown
Owner

Summary

Fixes #3209

The esc() function in src/channels/telegram-style.ts escaped &, <, > but not double quotes. When esc() output is interpolated into HTML attribute values (e.g. <a href="...">), unescaped quotes allow attribute injection via crafted URLs.

CodeQL alert: https://github.com/OneStepAt4time/aegis/security/code-scanning/142

Changes

  • Add .replace(/"/g, "&quot;") to esc() in src/channels/telegram-style.ts
  • Mirror fix in test helper esc() functions (telegram-style.test.ts, telegram-formatting.test.ts)
  • Add 2 new tests: double-quote escaping and combined HTML-special characters

Verification

npx tsc --noEmit  β†’ βœ… 0 errors
npm run build     β†’ βœ… success
npm test          β†’ βœ… 4023 passed, 1 skipped (1 flaky pre-existing timeout in server-core-coverage β€” unrelated)

Targeted test run:

src/__tests__/telegram-formatting.test.ts β†’ βœ… 25 tests passed
src/__tests__/telegram-style.test.ts      β†’ βœ… 19 tests passed

Commit: 9381367
Worktree: ../wt/issue-3209

Security

Defense-in-depth fix. sanitizeHref() already restricts protocols β€” this prevents attribute breakout even if a crafted URL containing " passes through.

…ection (#3209)

The esc() function in telegram-style.ts escaped &, <, > but not double
quotes. When esc() output is interpolated into HTML attribute values
(e.g. href="..."), unescaped quotes allow attribute injection (XSS).

- Add .replace(/"/g, '&quot;') to esc() in telegram-style.ts
- Mirror fix in test helper esc() functions
- Add 2 new tests: double-quote escaping and combined HTML-special chars

Closes #3209
CodeQL: security/code-scanning/142

@aegis-gh-agent aegis-gh-agent Bot 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.

πŸ‘οΈ Argus Review β€” Approved

Fix Correctness βœ…

Adds &quot; escaping to esc() β€” exactly the fix prescribed in #3209. Defense-in-depth: sanitizeHref() already restricts protocols, this prevents attribute breakout.

Changes βœ…

  1. src/channels/telegram-style.ts (+2/-1): .replace(/"/g, "&quot;") added to escape chain. Correct order (after & escape to avoid double-encoding).
  2. src/__tests__/telegram-formatting.test.ts (+9/-1): Test helpers mirrored, 2 new tests (double-quote escape + combined HTML-special chars).
  3. src/__tests__/telegram-style.test.ts (+1/-1): Test helper mirrored.

Test Coverage βœ…

  • New test: esc("hello \"world\"") β†’ "hello &quot;world&quot;" βœ…
  • Combined test: esc("<a href=\"x\">&") β†’ "&lt;a href=&quot;x&quot;&gt;&amp;" βœ…
  • All 4023 tests pass.

Gates βœ…

All 9 gates pass. Security fix. Closes #3209.

@aegis-gh-agent aegis-gh-agent Bot merged commit 182c369 into develop May 11, 2026
18 checks passed
@aegis-gh-agent aegis-gh-agent Bot deleted the fix/3209-esc-double-quotes branch May 11, 2026 19:17
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.

1 participant