ESD-1624: Stop trusting the page-writable apiURL global in WASM login#513
Merged
Conversation
…ot page-writable global
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #513 +/- ##
=======================================
Coverage 79.29% 79.29%
=======================================
Files 193 193
Lines 18683 18683
=======================================
Hits 14814 14814
Misses 2820 2820
Partials 1049 1049 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens the WASM authentication flow by ensuring the API base URL used for authenticated and unauthenticated clients is sourced from the hostname-validated MEGAPORT_API_URL env var (set by setAuthToken) rather than a page-writable JS global, reducing risk of token exfiltration via URL redirection.
Changes:
- Updated WASM login and unauthenticated client creation to read the API base URL from
os.Getenv("MEGAPORT_API_URL")instead ofwindow.megaportToken.apiURL. - Added
js,wasmunit tests to ensure tampering with the JS global cannot redirect API traffic away from the validated host. - Updated CI workflow to actually execute the config package’s WASM tests under node.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| internal/commands/config/login_wasm.go | Stops trusting page-writable apiURL JS global; uses validated env-var API base URL for client routing. |
| internal/commands/config/login_wasm_test.go | Adds WASM tests to assert routing remains pinned to the validated env-var host even if JS globals are tampered. |
| .github/workflows/wasm.yml | Runs the new WASM config tests in CI so the regression coverage executes. |
penzeliz-megaport
previously approved these changes
Jul 13, 2026
penzeliz-megaport
left a comment
Collaborator
There was a problem hiding this comment.
Reviewed for correctness; no findings. LGTM.
…trust # Conflicts: # internal/commands/config/login_wasm.go # internal/commands/config/login_wasm_test.go
Contributor
Author
|
Merge conflict resolved in c3d43a4 |
projectsuperba
previously approved these changes
Jul 15, 2026
…e unauthenticated client fallback
projectsuperba
approved these changes
Jul 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The WASM login path read the outbound API base URL from
window.megaportToken.apiURL, a page-writable JS global. Any other script on the page (XSS, a compromised widget, a browser extension) could overwrite it after login and redirect the bearer token to an attacker host, defeating the hostname validationsetAuthTokenalready does.Both login call sites now read the URL from the
MEGAPORT_API_URLenv var thatsetAuthTokensets after validating the portal hostname. TheapiURLfield on the JS global stays for UI display only, since nothing security-sensitive reads it back.loginFunc(token path) andnewUnauthenticatedClientFuncnow source the base URL fromos.Getenv("MEGAPORT_API_URL").js,wasmtests assert both paths route to the validated host even when the JS global is tampered to an attacker URL.wasm.ymlstep so the config package's wasm tests actually run under node in CI (previously compiled but never executed).