Skip to content

Potential fix for code scanning alert no. 10: Client-side cross-site scripting#13

Merged
EthanThePhoenix38 merged 2 commits intomainfrom
alert-autofix-10
Jan 8, 2026
Merged

Potential fix for code scanning alert no. 10: Client-side cross-site scripting#13
EthanThePhoenix38 merged 2 commits intomainfrom
alert-autofix-10

Conversation

@EthanThePhoenix38
Copy link
Member

Potential fix for https://github.com/ThePhoenixAgency/AI-Pulse/security/code-scanning/10

General fix: Never use unvalidated, user-controlled URL parameters directly in navigation sinks or DOM assignments. Instead, validate and normalize the URL once (e.g., via the URL constructor plus a strict scheme whitelist), store it in a separate variable, and only ever use that validated value (safeUrl) at sinks such as iframe.src and a.href.

Best concrete fix here: Inside the existing if (articleUrl && isValidHttpUrl(articleUrl)) { ... } block, create a new URL object from articleUrl and store its string representation in a new constant, for example const safeArticleUrl = new URL(articleUrl).toString();. Then use safeArticleUrl for all navigation-related assignments: openExternal.href, openExternalError.href, and iframe.src. This makes the data-flow explicit: the sink only sees a value that has passed isValidHttpUrl and URL parsing, which both tightens security and clarifies to CodeQL that the sink value is derived from a validated URL. No change in user-visible functionality occurs, because for valid HTTP(S) URLs the toString() result is equivalent to what was being used before (just normalized). All changes are limited to the provided script area in reader.html; no new imports or external libraries are required.

Specific changes (line references approximate based on snippet):

  • In reader.html, inside the if (articleUrl && isValidHttpUrl(articleUrl)) { ... } block around lines 460–497:
    • Directly after the if line, add const safeArticleUrl = new URL(articleUrl).toString();.
    • Replace:
      • document.getElementById('openExternal').href = articleUrl;
      • document.getElementById('openExternalError').href = articleUrl;
      • iframe.src = articleUrl;
        with the same assignments but using safeArticleUrl instead.
  • Keep all other logic (title, source, tags, iframe load handling) unchanged.

This preserves existing behavior while ensuring the value used at navigation sinks is clearly validated and normalized.


Suggested fixes powered by Copilot Autofix. Review carefully before merging.

…scripting

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@EthanThePhoenix38 EthanThePhoenix38 marked this pull request as ready for review January 8, 2026 20:37
Copilot AI review requested due to automatic review settings January 8, 2026 20:37
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request addresses a client-side cross-site scripting (XSS) vulnerability (GitHub Security Alert #10) by implementing URL validation and normalization before using URL parameters in navigation sinks. The fix ensures that user-controlled URL parameters are properly sanitized using the URL constructor after validation, and only the normalized value is used for DOM assignments and navigation.

Key changes:

  • Introduces safeArticleUrl variable that holds the normalized URL output from new URL(articleUrl).toString()
  • Replaces direct usage of articleUrl with safeArticleUrl in all navigation sinks (iframe src and anchor hrefs)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

}
}

// If article parameters exist and URL is valid, show article view
Copy link

Copilot AI Jan 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is redundant with the code logic itself. The condition if (articleUrl && isValidHttpUrl(articleUrl)) is self-documenting, and adding this comment doesn't provide additional value. Consider removing this comment to reduce noise.

Suggested change
// If article parameters exist and URL is valid, show article view

Copilot uses AI. Check for mistakes.
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: abf8b1a473

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +459 to +461
// If article parameters exist and URL is valid, show article view
if (articleUrl && isValidHttpUrl(articleUrl)) {
const safeArticleUrl = new URL(articleUrl).toString();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Close the new validity guard to avoid script parse error

The newly added if (articleUrl && isValidHttpUrl(articleUrl)) { is never closed, so the browser hits an unmatched { and throws a syntax error when parsing the script. That stops all subsequent JS from running (view switching, tab handlers, tracking), even for valid URLs. This is introduced by the commit and will break the reader page for every load until the missing } is added.

Useful? React with 👍 / 👎.

@EthanThePhoenix38 EthanThePhoenix38 merged commit c167ed9 into main Jan 8, 2026
5 checks passed
@EthanThePhoenix38 EthanThePhoenix38 deleted the alert-autofix-10 branch January 8, 2026 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants