Skip to content

fix: anchor github.com host match in usernameFromHref - #1

Merged
mchmarny merged 2 commits into
mainfrom
fix/username-href-host-anchor
Oct 3, 2026
Merged

mchmarny merged 2 commits into
mainfrom
fix/username-href-host-anchor

Conversation

@mchmarny

@mchmarny mchmarny commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

Summary

usernameFromHref stripped the host with /^https?:\/\/github\.com/, which has no anchor after the hostname. Lookalike hosts were therefore parsed as profile links — e.g. https://github.comx yielded username x, https://github.com-evil yielded -evil.

The pattern now requires the path separator after the host (/^https?:\/\/github\.com\// → /), so only exact github.com URLs are normalized. The new pattern matches a strict subset of the old one with identical output where both match; relative /user hrefs (the common case on GitHub pages) are unaffected.

Resolves CodeQL alert #1 (js/regex/missing-regexp-anchor, src/scan.ts:29).

Testing

  • Added usernameFromHref cases: absolute github.com profile URLs still resolve; github.com, github.comx, github.com-evil, github.company/..., github.com.evil.io/... return null (github.comx and github.com-evil returned a username before this change).
  • npm run lint, npm test (29/29), npm run build pass locally.

The host regex lacked a trailing anchor, so lookalike hosts such as
https://github.comx were stripped to a bare segment and parsed as a
profile username. Require the path separator after the host.

Resolves CodeQL js/regex/missing-regexp-anchor (alert #1).
@mchmarny mchmarny self-assigned this Oct 3, 2026
@mchmarny
mchmarny merged commit d7ec6f6 into main Oct 3, 2026
4 checks passed
@mchmarny
mchmarny deleted the fix/username-href-host-anchor branch October 3, 2026 11:23
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