Skip to content

Conversation

@mattzcarey
Copy link
Contributor

we should do this

@changeset-bot
Copy link

changeset-bot bot commented Jan 16, 2026

⚠️ No Changeset found

Latest commit: ff2973f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@claude
Copy link

claude bot commented Jan 16, 2026

Claude Code Review

PR #788: fix: escape script vars

This PR fixes a potential XSS vulnerability in OAuth error handling where user-controlled error messages could be injected into inline script tags without proper escaping.

Issues Found:

  1. Incomplete XSS prevention (examples/mcp-client/src/server.ts:15-17, site/ai-playground/src/server.ts:78-80):

    • Using JSON.stringify() and string concatenation (+) in inline scripts does not fully prevent XSS
    • If result.authError contains </script>, it will still break out of the script context
    • Example: authError = '</script><img src=x onerror=alert(1)>'

    Recommended fix: Use double JSON encoding:

    const safeError = JSON.stringify(JSON.stringify(result.authError || "Unknown error"));
    return new Response(
      `<script>alert("Authentication failed: " + JSON.parse(SAFEVAR)); window.close();</script>`.replace("SAFEVAR", safeError),
      { headers: { "content-type": "text/html" }, status: 200 }
    );
  2. No test coverage: The OAuth error path lacks tests to verify XSS protection works correctly.

Severity: High - This is security-critical code handling authentication errors that could contain attacker-controlled input.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 16, 2026

Open in StackBlitz

npm i https://pkg.pr.new/cloudflare/agents@788

commit: ff2973f

@mattzcarey mattzcarey merged commit 70e5040 into main Jan 17, 2026
6 checks passed
@mattzcarey mattzcarey deleted the fix-escape-errors branch January 17, 2026 16:43
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