-
Notifications
You must be signed in to change notification settings - Fork 0
Fix share link to use config code instead of current URL #562
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -173,6 +173,7 @@ export function computeDerivedOverrides(ov: Record<string, string>, { reduceMoti | |
| interface SlashedAppBoot { | ||
| rest?: { url?: string; nonce?: string }; | ||
| overrides?: Record<string, string>; | ||
| pluginSettings?: { configurator_url?: string }; | ||
| } | ||
|
|
||
| function wpBoot(): SlashedAppBoot | null { | ||
|
|
@@ -185,6 +186,39 @@ export function isEmbedded(): boolean { | |
| return Boolean(wpBoot()?.rest?.url); | ||
| } | ||
|
|
||
| /** | ||
| * Base URL share links should point at. Embedded hosts (e.g. the WP plugin) | ||
| * persist overrides server-side rather than in the URL hash (see | ||
| * saveStandalone() below, which the WP save path skips entirely), so the | ||
| * current page's URL is a logged-in admin screen, not something worth | ||
| * sharing — use the host's public standalone configurator URL instead. | ||
| * Returns undefined in standalone mode, where buildShareUrl()'s own | ||
| * window.location.href fallback is already correct. | ||
| * | ||
| * The value is host-controlled boot data, so validate it before handing it to | ||
| * buildShareUrl()'s `new URL(baseUrl)`: a relative/malformed string would throw | ||
| * (silently swallowed by the share/copy handlers, so nothing gets copied and | ||
| * the user gets no feedback), and a non-http(s) scheme (javascript:, data:…) | ||
| * would be faithfully propagated into a copied "share link". On any of those, | ||
| * return undefined so buildShareUrl() falls back to the current page URL. | ||
| */ | ||
| export function getShareBaseUrl(): string | undefined { | ||
| const raw = wpBoot()?.pluginSettings?.configurator_url; | ||
| const trimmed = raw?.trim(); | ||
| if (!trimmed) return undefined; | ||
| try { | ||
| const parsed = new URL(trimmed); | ||
| if (parsed.protocol !== "http:" && parsed.protocol !== "https:") { | ||
| console.warn(`[slashed] ignoring configurator_url with unsupported scheme: ${parsed.protocol}`); | ||
| return undefined; | ||
| } | ||
| return trimmed; | ||
| } catch { | ||
| console.warn(`[slashed] ignoring invalid configurator_url: ${trimmed}`); | ||
| return undefined; | ||
| } | ||
| } | ||
|
Comment on lines
+205
to
+220
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2. Unsafe url schemes copied configurator_url is accepted without protocol validation, so a host can supply javascript:/data:/other non-http(s) schemes that will be copied as a “share link”. This is primarily a misconfiguration/phishing footgun, since the app will faithfully propagate the unsafe scheme into the copied URL. Agent Prompt
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in d96eba6 — Generated by Claude Code |
||
|
|
||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| /** | ||
| * Whether a host (e.g. the WP admin page) mounted us into its own container, | ||
| * regardless of whether REST persistence is configured. This is the same | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.