Skip to content

fix(#638): escape DOM-sourced email parts in site mailto builder (CodeQL #8)#639

Merged
atlas-apex merged 1 commit into
me2resh:devfrom
atlas-apex:fix/GH-638-site-mailto-xss
Jun 11, 2026
Merged

fix(#638): escape DOM-sourced email parts in site mailto builder (CodeQL #8)#639
atlas-apex merged 1 commit into
me2resh:devfrom
atlas-apex:fix/GH-638-site-mailto-xss

Conversation

@atlas-apex

Copy link
Copy Markdown
Collaborator

Summary

  • Clears CodeQL High refactor(#100): multi-project only + fork-first install #8 (js/xss-through-dom) in site/index.html. The email-obfuscation snippet assembled a mailto: href from the data-u / data-d DOM attributes (read via getAttribute) and concatenated them unescaped into the href — DOM text flowing into a DOM sink.
  • Fix: wrap the local-part and domain in encodeURIComponent ('mailto:' + encodeURIComponent(u) + '@' + encodeURIComponent(d) + …). CodeQL recognises encodeURIComponent as a sanitiser, so the alert clears; meta-characters are escaped before the sink.
  • Behaviour unchanged for real addressesencodeURIComponent('ahmed') / encodeURIComponent('apexscript.com') are no-ops (alphanumerics + . aren't encoded). The @ (@) separator is preserved. Real-world risk was already low (the data attributes are author-set and the mailto: prefix precludes a javascript: URL), so this is defence-in-depth + alert hygiene.

Testing

  1. The change wraps two existing variables in encodeURIComponent — no structural change; the surrounding IIFE still parses.
  2. Manual: hovering/clicking the obfuscated email still produces the correct mailto:ahmed@…?subject=…&body=… href.
  3. CodeQL js/xss-through-dom refactor(#100): multi-project only + fork-first install #8 should resolve on the next scan.

Closes #638


Glossary

Term Definition
DOM-XSS (js/xss-through-dom) XSS where text read from the DOM reaches a DOM sink without sanitisation.
encodeURIComponent Percent-encodes URL meta-characters; recognised by CodeQL as a sanitiser for this sink.
Email obfuscation Splitting/assembling a mailto: at runtime to deter naive address scrapers.

The email-obfuscation snippet built a mailto: href from the data-u/data-d DOM
attributes without escaping, which CodeQL flags as js/xss-through-dom (me2resh#8).
Wrap the local-part and domain in encodeURIComponent so meta-characters are
escaped before reaching the href sink. Real-world risk was low (author-controlled
attributes; mailto: prefix precludes javascript:), but this clears the alert and
is a no-op for normal addresses.

Closes me2resh#638
@atlas-apex atlas-apex merged commit 3116eed into me2resh:dev Jun 11, 2026
7 checks passed
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.

2 participants