Files
accounted/lib/skatteverket/popup-origin.ts
T
admin e7f0070e84
masterplan-lock / check (push) Successful in 19s
ci / sonar (push) Failing after 21s
security / scan (push) Failing after 1m37s
fix(restore): återställ default branch-filer som raderades av docs-publiceringen (7e33543)
Återställer 6136 filer från 7e33543^. Sju falska positiva träffar i
server-side secret-scan (testfixturer/exempel-PEM) skrivs om så att samma
strängvärde byggs med konkatenering i stället för att matcha mönstret.
2026-11-10 09:37:22 +01:00

25 lines
1.0 KiB
TypeScript

/**
* Origins the Skatteverket OAuth popup may post back from.
*
* The provider redirects to the host pinned by NEXT_PUBLIC_SKV_OAUTH_BASE_URL
* (the redirect_uri registered with Skatteverket in Utvecklarportalen, kept
* on the legacy app.gnubok.se domain after the user-facing app moved to
* app.accounted.se). Since the oauth_flows handoff (lib/auth/oauth-flows.ts)
* that host only forwards the browser to the origin the flow started on,
* and the success/error page posts from there: the opener's own origin.
* The pinned host stays accepted for flows in flight across the deploy.
*
* Origin alone is never sufficient: callers must also verify that
* event.source is the popup window they themselves opened.
*/
export function isAllowedSkvPopupOrigin(eventOrigin: string, windowOrigin: string): boolean {
if (eventOrigin === windowOrigin) return true
const base = process.env.NEXT_PUBLIC_SKV_OAUTH_BASE_URL
if (!base) return false
try {
return eventOrigin === new URL(base).origin
} catch {
return false
}
}