Skip to content

feat: send the client's token with the overlay's open-editor request - #2488

Open
alexander-akait wants to merge 3 commits into
mainfrom
feat/overlay-open-editor-token
Open

alexander-akait wants to merge 3 commits into
mainfrom
feat/overlay-open-editor-token

Conversation

@alexander-akait

@alexander-akait alexander-akait commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

The overlay now sends the client's token along when it asks openEditorEndpoint to open a file it was clicked on: /__open-editor?fileName=…&token=….

That lets a server tell the overlay's own request from one another page made. Origin and Sec-Fetch-* cannot do that everywhere: browsers send neither over plain http to anything but localhost, which is what a dev server on a network address is. webpack-dev-server will use it to protect /webpack-dev-server/open-editor when allowedOrigins is set.

  • Only to an endpoint on the page's own server, a rooted path (/…, not //…). An absolute url can name any server, and the token is not that server's to have.
  • Only when the client was given a token; nothing changes otherwise. An endpoint that does not check it ignores an extra query parameter.
  • The URL is built in client-src/utils/open-editor-url.js, which is unit-tested on its own.

Tests:

  • test/open-editor-url.test.js: the token on a rooted path; never on https://…, //… or a relative path; nothing without a token.
  • test/e2e/overlay.test.js: clicking a file reference reaches the endpoint carrying the instance's token.
  • Overlay e2e 234/234; unit suite 7390 passed (the 2 failures are the root-only writeToDisk EACCES cases that fail on main too). Minor changeset.

Generated by Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Editor-overlay requests now include the client token when opening files on the current server.
    • Tokens are excluded from external or unsupported endpoint URLs to avoid unintended transmission.
    • Editor-opening URLs now preserve existing query parameters and fragments while safely encoding file references and tokens.
  • TypeScript

    • Added declarations for configuring the editor token and generating editor-opening URLs.
  • Tests

    • Added coverage for token handling, URL encoding, endpoint validation, and browser-based editor-opening behavior.

So a server can tell the overlay's request from one another page made.
Only to an endpoint on the page's own server, and only when the client was
given a token.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UjuMAuk9o6UazjHzcAQCTA
@changeset-bot

changeset-bot Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: e1e7b49

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
webpack-dev-middleware Minor

Not sure what this means? Click here to learn what changesets are.

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

@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 67ffc81b-98d4-461f-bc7c-3d6ac5454736
📥 Commits

Reviewing files that changed from the base of the PR and between 119dd70 and e1e7b49.

📒 Files selected for processing: 2
  • client-src/utils/open-editor-url.js
  • test/open-editor-url.test.js

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

Walkthrough

The client passes its connection token to the editor overlay. For rooted same-server endpoints, the overlay includes an available token when it builds an editor-opening URL. The new utility encodes file references, preserves URL components, and excludes tokens for other endpoint forms. Unit and end-to-end tests cover URL generation and token forwarding.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to e1e7b

No actionable merge-blocking risk remains. The previously reported leading-backslash token-leak case is excluded at the reviewed head.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: sending the client token with the overlay's open-editor request.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 7 files.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1a2dd696-152b-431e-bff9-d351cf0b5a46
📥 Commits

Reviewing files that changed from the base of the PR and between 0ffba03 and 8210ae6.

📒 Files selected for processing: 9
  • .changeset/overlay-open-editor-token.md
  • .cspell.json
  • client-src/index.js
  • client-src/overlay.js
  • client-src/utils/open-editor-url.js
  • test/e2e/overlay.test.js
  • test/open-editor-url.test.js
  • types/client/overlay.d.ts
  • types/client/utils/open-editor-url.d.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

Comment thread client-src/utils/open-editor-url.js Outdated
A browser reads `/\host` as protocol-relative, like `//host`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UjuMAuk9o6UazjHzcAQCTA

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

🟡 Minor · Place fileName before the endpoint fragment. · open-editor-url.js:15-19

client-src/utils/open-editor-url.js:15-19
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Place fileName before the endpoint fragment.

When a rooted openEditorEndpoint contains an existing query or fragment, the current template appends ?fileName=... after it. The documented /__open-editor route then does not receive req.query.fileName, so it can reject the request instead of opening the selected file. Insert fileName into the query before the fragment. Keep the existing isOwnServer check so token delivery remains limited to rooted same-server paths.

Suggested fix
 export default function openEditorUrl(endpoint, reference, token) {
-  const url = `${endpoint}?fileName=${encodeURIComponent(reference)}`;
+  const hashIndex = endpoint.indexOf("#");
+  const fragment = hashIndex === -1 ? "" : endpoint.slice(hashIndex);
+  const withoutFragment =
+    hashIndex === -1 ? endpoint : endpoint.slice(0, hashIndex);
+  const separator = withoutFragment.includes("?") ? "&" : "?";
+  const url = `${withoutFragment}${separator}fileName=${encodeURIComponent(
+    reference,
+  )}${fragment}`;
   const isOwnServer = /^\/(?![/\\])/.test(endpoint);

ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ea94ced5-d6e9-4235-b6fa-676ff94b42b8
📥 Commits

Reviewing files that changed from the base of the PR and between 8210ae6 and 119dd70.

📒 Files selected for processing: 3
  • client-src/utils/open-editor-url.js
  • test/open-editor-url.test.js
  • types/client/utils/open-editor-url.d.ts
🚧 Files skipped from review as they are similar to previous changes: 3
  • client-src/utils/open-editor-url.js
  • test/open-editor-url.test.js
  • types/client/utils/open-editor-url.d.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

…s fragment

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UjuMAuk9o6UazjHzcAQCTA

Copy link
Copy Markdown
Member Author

@coderabbitai Fixed the outside-diff finding (fileName and the endpoint's own query or fragment) in e1e7b49. fileName and the token now go into any query the endpoint already has, before its fragment. Both are still encoded with encodeURIComponent, so a space stays %20 for a route that decodes by hand. Added a test.


Generated by Claude Code

@coderabbitai

coderabbitai Bot commented Oct 20, 2026

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail
fd '^open-editor-url(\.test)?\.js$'
ast-grep outline client-src/utils/open-editor-url.js
ast-grep outline test/open-editor-url.test.js
sed -n '1,180p' client-src/utils/open-editor-url.js
sed -n '1,220p' test/open-editor-url.test.js

Length of output: 3333


@alexander-akait Thanks for the fix. I verified that openEditorUrl appends fileName and the token to the existing query before the fragment. Both values still use encodeURIComponent.

The regression test covers an existing query and fragment, including %20 encoding for a space. This addresses the finding. I inspected the code and test but did not run the tests.


✏️ Learnings added
Learnt from: alexander-akait
URL: https://github.com/webpack/webpack-dev-middleware/pull/2488

Timestamp: 2026-10-20T12:16:46.588Z
Learning: In webpack/webpack-dev-middleware, client-src/utils/open-editor-url.js must preserve encodeURIComponent encoding for fileName and token when building openEditorEndpoint requests. Routes can decode values directly with decodeURIComponent, so spaces must remain %20 rather than the + encoding produced by URLSearchParams.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.


If you found this review helpful, would you consider giving us a shout-out on X?

Thank you for using CodeRabbit!

You are interacting with an AI system.

@codecov

codecov Bot commented Oct 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.68%. Comparing base (0ffba03) to head (e1e7b49).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2488      +/-   ##
==========================================
+ Coverage   96.63%   96.68%   +0.05%     
==========================================
  Files          24       25       +1     
  Lines        2644     2655      +11     
==========================================
+ Hits         2555     2567      +12     
+ Misses         89       88       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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