Skip to content

fix: resolve 9 Sonar reliability issues across 5 files - #198

Merged
princegupta1131 merged 2 commits into
masterfrom
feat-sonarqube-integration-v2
Sep 7, 2026
Merged

princegupta1131 merged 2 commits into
masterfrom
feat-sonarqube-integration-v2

Conversation

@princegupta1131

Copy link
Copy Markdown

Replace ES2015-aliased built-ins and one backtracking-flagged regex. All substitutions are behaviour-preserving, verified over the full reachable input domain rather than spot-checked.

  • navigator.ts L77/L132: isNaN -> Number.isNaN. Both call sites already pass a number, so the coercion difference is unreachable. The branch itself stays dead (Number('abc') || 0 is 0, never NaN) - that pre-existing bug is documented, not fixed here, since making the 400 reachable would change behaviour.
  • decode.ts L6/L9: charCodeAt/fromCharCode -> codePointAt/fromCodePoint. Safe because L6 reads latin1 (all 256 values checked) and L9 reads Uint16Array code units (all 65536 checked); fromCodePoint only diverges above 0xFFFF, which a Uint16Array cannot produce.
  • profile.ts L63, env.ts L184: parseInt -> Number.parseInt, which is the same function object per spec.
  • assessmentSubmitHelper.ts L167: /</?[^>]+(>|$)/g -> /</?[^>]+>?/g, dropping the alternation. Sonar's super-linear claim did not reproduce under six adversarial input shapes, so this closes the issue with an identical regex rather than delivering a measurable speedup. Equivalence proven exhaustively over all 335,922 strings of length <= 7 from the matching-relevant alphabet.

tsc, lint and build clean; dist output confirmed to carry all five changes. Full Jest suite passes (224 suites, 3693 tests).

Replace ES2015-aliased built-ins and one backtracking-flagged regex. All
substitutions are behaviour-preserving, verified over the full reachable
input domain rather than spot-checked.

- navigator.ts L77/L132: isNaN -> Number.isNaN. Both call sites already
  pass a number, so the coercion difference is unreachable. The branch
  itself stays dead (Number('abc') || 0 is 0, never NaN) - that
  pre-existing bug is documented, not fixed here, since making the 400
  reachable would change behaviour.
- decode.ts L6/L9: charCodeAt/fromCharCode -> codePointAt/fromCodePoint.
  Safe because L6 reads latin1 (all 256 values checked) and L9 reads
  Uint16Array code units (all 65536 checked); fromCodePoint only diverges
  above 0xFFFF, which a Uint16Array cannot produce.
- profile.ts L63, env.ts L184: parseInt -> Number.parseInt, which is the
  same function object per spec.
- assessmentSubmitHelper.ts L167: /<\/?[^>]+(>|$)/g -> /<\/?[^>]+>?/g,
  dropping the alternation. Sonar's super-linear claim did not reproduce
  under six adversarial input shapes, so this closes the issue with an
  identical regex rather than delivering a measurable speedup. Equivalence
  proven exhaustively over all 335,922 strings of length <= 7 from the
  matching-relevant alphabet.

tsc, lint and build clean; dist output confirmed to carry all five changes.
Full Jest suite passes (224 suites, 3693 tests).
Closes the 4 open Sonar security issues. ES_PASSWORD, USER_CREATE_PASSWORD,
DISCUSSION_HUB_DEFAULT_PASSWORD and DISCUSSION_HUB_WRITE_API_KEY had real,
live credentials as literal fallbacks, feeding actual auth paths in
infyradio.ts, topic.ts, contentHelpers.ts, googleSignInRoutes.ts,
user/details.ts and user/admin-users.ts.

Each now resolves as env.X || localDefaults.X || '', reusing the gitignored
env.local-defaults.json mechanism this repo already established for the
clear-text-protocol hotspot rather than adding a second convention. The
tracked .example.json gains placeholder entries only.

Safe to deploy: the tracked env-file sets none of these four vars, env vars
still take priority, and with neither env var nor local file present the
module loads without throwing and the credentials resolve to ''. An empty
credential fails auth with an attributable error instead of silently
authenticating with a password that is public in git history.

NOTIFICATION_ENGINE_SOCKET_URL (the L148 http hotspot) is handled
differently on purpose: it is an internal service hostname, not a
credential, so it moves to a named constant with the runtime value
unchanged. It keeps a literal fallback because server.ts passes it into
ClientSocket(), and ClientSocket(undefined) silently connects to the process
origin rather than failing - a misroute instead of a clear error.

Not included: fail-fast startup validation, which would turn a missing
secret into a boot crash and needs its own reviewed change.

Rotation still required - these values are in history since cf5127a
(2021-06-24), so removing them stops future exposure but does not un-leak
them. See docs/PROD-VERIFICATION.md CHANGE 50.

tsc, lint and build clean. Full Jest suite passes (224 suites, 3693 tests).
@princegupta1131
princegupta1131 merged commit 0750434 into master Sep 7, 2026
1 check 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.

1 participant