diff options
| author | Adam Soltys <[email protected]> | 2026-11-25 09:50:53 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-11-25 09:50:53 -0700 |
| commit | fe27556e72fbe99719321ef7df58427febe8cddb (patch) | |
| tree | a20b62bc7be1e3616d5089681cf611d2f6581d6b /src | |
| parent | 3a321d4e70d1244224c4643ddac8e96216bfe5f4 (diff) | |
| download | coinos-ui-fe27556e72fbe99719321ef7df58427febe8cddb.tar.gz coinos-ui-fe27556e72fbe99719321ef7df58427febe8cddb.zip | |
Remove the Shopify integration; tighten the post relay
Drop the Shopify settings page and script route along with the unused
ecash post route. The generic post relay now only forwards plain API paths
and passes the visitor's address along to the API.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VMan6W9CsdxmhFrfaKNVHU
Diffstat (limited to 'src')
| -rw-r--r-- | src/hooks.server.ts | 2 | ||||
| -rw-r--r-- | src/lib/utils.ts | 2 | ||||
| -rw-r--r-- | src/routes/(app)/post/[...path]/+server.ts | 25 |
3 files changed, 23 insertions, 6 deletions
diff --git a/src/hooks.server.ts b/src/hooks.server.ts index 5e0d9e90..a7e97394 100644 --- a/src/hooks.server.ts +++ b/src/hooks.server.ts @@ -6,7 +6,7 @@ setIpGetter(() => ipStore.getStore()); export const handle: Handle = async ({ event, resolve }) => { // Pages render client-side only, so the settings layout's login redirect - // never reaches crawlers; Google indexed /settings/shopify as an empty + // never reaches crawlers; Google indexed a settings page as an empty // "Untitled" page. Redirect signed-out visitors on the server instead. const { pathname } = event.url; if ( diff --git a/src/lib/utils.ts b/src/lib/utils.ts index b6bbdb53..15ffb7f3 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -27,7 +27,7 @@ export const setIpGetter = (fn: () => string | undefined) => { getIp = fn; }; -const ipHeaders = (): Record<string, string> => { +export const ipHeaders = (): Record<string, string> => { const ip = getIp?.(); return ip ? { "cf-connecting-ip": ip } : {}; }; diff --git a/src/routes/(app)/post/[...path]/+server.ts b/src/routes/(app)/post/[...path]/+server.ts index 84df9a36..530bd2ed 100644 --- a/src/routes/(app)/post/[...path]/+server.ts +++ b/src/routes/(app)/post/[...path]/+server.ts @@ -1,12 +1,29 @@ import { PUBLIC_COINOS_URL as base } from "$env/static/public"; -import { auth } from "$lib/utils"; +import { auth, ipHeaders } from "$lib/utils"; +import { error } from "@sveltejs/kit"; + +// Relays a signed-in browser's POST to the API. The API trusts callers that +// arrive without a client address (its own node containers), so this must +// always pass the visitor's address along, and must only ever produce a plain +// API path: no absolute URLs, no "..", no empty segments. +const segment = /^[A-Za-z0-9_.~@:-]+$/; +const internalOnly = new Set(["confirm"]); export async function POST({ cookies, fetch, params, request }) { - const { path } = params; + const parts = params.path.split("/"); + if ( + !parts.every((p) => segment.test(p) && p !== "." && p !== "..") || + internalOnly.has(parts[0].toLowerCase()) + ) + error(404, "Not found"); - return fetch(`${base}/${path}`, { + return fetch(`${base}/${parts.join("/")}`, { method: "POST", body: JSON.stringify(await request.json()), - headers: { "Content-Type": "application/json", ...auth(cookies) }, + headers: { + "Content-Type": "application/json", + ...ipHeaders(), + ...auth(cookies), + }, }); } |
