@scalemule/nextjs 0.1.14 → 0.1.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.d.mts +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.js +2 -1
- package/dist/client.mjs +2 -1
- package/dist/{index-BIIUrnPr.d.mts → index-DTWyUcyd.d.mts} +22 -1
- package/dist/{index-BIIUrnPr.d.ts → index-DTWyUcyd.d.ts} +22 -1
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +81 -19
- package/dist/index.mjs +82 -20
- package/dist/ledvery-C9vvhlUn.d.mts +43 -0
- package/dist/ledvery-C9vvhlUn.d.ts +43 -0
- package/dist/server/auth.js +2 -1
- package/dist/server/auth.mjs +2 -1
- package/dist/server/index.d.mts +4 -3
- package/dist/server/index.d.ts +4 -3
- package/dist/server/index.js +318 -50
- package/dist/server/index.mjs +312 -51
- package/dist/server/ledvery.d.mts +1 -0
- package/dist/server/ledvery.d.ts +1 -0
- package/dist/server/ledvery.js +322 -0
- package/dist/server/ledvery.mjs +319 -0
- package/dist/server/webhook-handler.d.mts +2 -2
- package/dist/server/webhook-handler.d.ts +2 -2
- package/dist/testing.d.mts +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +2 -1
- package/dist/testing.mjs +2 -1
- package/dist/{webhook-handler-BjFbqZuq.d.ts → webhook-handler-C07AK4QB.d.ts} +1 -1
- package/dist/{webhook-handler-BqzCYRNJ.d.mts → webhook-handler-CUp_A0_p.d.mts} +1 -1
- package/package.json +7 -1
package/dist/server/index.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createMoneyClient } from '@scalemule/money';
|
|
2
2
|
import { cookies, headers } from 'next/headers';
|
|
3
3
|
import { NextResponse } from 'next/server';
|
|
4
|
+
import { LedveryClient } from '@scalemule/ledvery';
|
|
4
5
|
import { createHmac, timingSafeEqual, createHash } from 'crypto';
|
|
5
6
|
|
|
6
7
|
var __create = Object.create;
|
|
@@ -1916,11 +1917,12 @@ var require_semver2 = __commonJS({
|
|
|
1916
1917
|
|
|
1917
1918
|
// src/types/index.ts
|
|
1918
1919
|
var ScaleMuleApiError = class extends Error {
|
|
1919
|
-
constructor(error) {
|
|
1920
|
+
constructor(error, status) {
|
|
1920
1921
|
super(error.message);
|
|
1921
1922
|
this.name = "ScaleMuleApiError";
|
|
1922
1923
|
this.code = error.code;
|
|
1923
1924
|
this.field = error.field;
|
|
1925
|
+
this.status = status;
|
|
1924
1926
|
}
|
|
1925
1927
|
};
|
|
1926
1928
|
|
|
@@ -3778,6 +3780,314 @@ function createAnalyticsRoutes(config = {}) {
|
|
|
3778
3780
|
return { POST };
|
|
3779
3781
|
}
|
|
3780
3782
|
|
|
3783
|
+
// src/server/ledvery-cookies.ts
|
|
3784
|
+
var SM_LEDVERY_STATE_COOKIE = "sm_ledvery_state";
|
|
3785
|
+
var SM_LEDVERY_PKCE_VERIFIER_COOKIE = "sm_ledvery_pkce_verifier";
|
|
3786
|
+
var SM_LEDVERY_NONCE_COOKIE = "sm_ledvery_nonce";
|
|
3787
|
+
var SM_LEDVERY_ID_TOKEN_COOKIE = "sm_ledvery_id_token";
|
|
3788
|
+
var SM_LEDVERY_ACCESS_TOKEN_COOKIE = "sm_ledvery_access_token";
|
|
3789
|
+
var FLOW_COOKIE_MAX_AGE = 60 * 10;
|
|
3790
|
+
var SESSION_COOKIE_MAX_AGE = 60 * 60;
|
|
3791
|
+
function flowCookieOptions() {
|
|
3792
|
+
return {
|
|
3793
|
+
httpOnly: true,
|
|
3794
|
+
secure: process.env.NODE_ENV === "production",
|
|
3795
|
+
sameSite: "lax",
|
|
3796
|
+
path: "/",
|
|
3797
|
+
maxAge: FLOW_COOKIE_MAX_AGE
|
|
3798
|
+
};
|
|
3799
|
+
}
|
|
3800
|
+
function sessionCookieOptions(maxAge) {
|
|
3801
|
+
return {
|
|
3802
|
+
httpOnly: true,
|
|
3803
|
+
secure: process.env.NODE_ENV === "production",
|
|
3804
|
+
sameSite: "lax",
|
|
3805
|
+
path: "/",
|
|
3806
|
+
maxAge: maxAge ? Math.min(maxAge, SESSION_COOKIE_MAX_AGE) : SESSION_COOKIE_MAX_AGE
|
|
3807
|
+
};
|
|
3808
|
+
}
|
|
3809
|
+
function setLedveryFlowCookies(response, params) {
|
|
3810
|
+
const opts = flowCookieOptions();
|
|
3811
|
+
setCookie(response, SM_LEDVERY_STATE_COOKIE, params.state, opts);
|
|
3812
|
+
setCookie(response, SM_LEDVERY_PKCE_VERIFIER_COOKIE, params.codeVerifier, opts);
|
|
3813
|
+
setCookie(response, SM_LEDVERY_NONCE_COOKIE, params.nonce, opts);
|
|
3814
|
+
}
|
|
3815
|
+
function validateAndConsumeLedveryFlowCookies(request, callbackState) {
|
|
3816
|
+
const cookieState = getCookie(request, SM_LEDVERY_STATE_COOKIE);
|
|
3817
|
+
const codeVerifier = getCookie(request, SM_LEDVERY_PKCE_VERIFIER_COOKIE);
|
|
3818
|
+
const nonce = getCookie(request, SM_LEDVERY_NONCE_COOKIE);
|
|
3819
|
+
if (!cookieState) return "Missing Ledvery state cookie - session may have expired";
|
|
3820
|
+
if (!callbackState) return "Missing state parameter in callback";
|
|
3821
|
+
if (!constantTimeEqual(cookieState, callbackState)) return "Ledvery state mismatch - possible CSRF attack";
|
|
3822
|
+
if (!codeVerifier) return "Missing PKCE verifier cookie";
|
|
3823
|
+
if (!nonce) return "Missing nonce cookie";
|
|
3824
|
+
return { codeVerifier, nonce };
|
|
3825
|
+
}
|
|
3826
|
+
function setLedverySession(response, session, opts) {
|
|
3827
|
+
const cookieOpts = sessionCookieOptions(opts?.cookies?.maxAge);
|
|
3828
|
+
if (opts?.cookies?.domain) cookieOpts.domain = opts.cookies.domain;
|
|
3829
|
+
if (opts?.cookies?.path) cookieOpts.path = opts.cookies.path;
|
|
3830
|
+
if (opts?.cookies?.sameSite) cookieOpts.sameSite = opts.cookies.sameSite;
|
|
3831
|
+
if (opts?.cookies?.secure !== void 0) cookieOpts.secure = opts.cookies.secure;
|
|
3832
|
+
const sessionPayload = JSON.stringify({
|
|
3833
|
+
claims: session.claims,
|
|
3834
|
+
expiresAt: session.expiresAt
|
|
3835
|
+
});
|
|
3836
|
+
setCookie(response, SM_LEDVERY_ID_TOKEN_COOKIE, sessionPayload, cookieOpts);
|
|
3837
|
+
if (opts?.storeAccessToken && session.accessToken) {
|
|
3838
|
+
setCookie(response, SM_LEDVERY_ACCESS_TOKEN_COOKIE, session.accessToken, cookieOpts);
|
|
3839
|
+
}
|
|
3840
|
+
}
|
|
3841
|
+
function getLedverySession(request) {
|
|
3842
|
+
const raw = getCookie(request, SM_LEDVERY_ID_TOKEN_COOKIE);
|
|
3843
|
+
if (!raw) return null;
|
|
3844
|
+
try {
|
|
3845
|
+
const parsed = JSON.parse(raw);
|
|
3846
|
+
return {
|
|
3847
|
+
idToken: "",
|
|
3848
|
+
// not stored in cookie for size
|
|
3849
|
+
claims: parsed.claims,
|
|
3850
|
+
expiresAt: parsed.expiresAt
|
|
3851
|
+
};
|
|
3852
|
+
} catch {
|
|
3853
|
+
return null;
|
|
3854
|
+
}
|
|
3855
|
+
}
|
|
3856
|
+
function clearLedverySession(response) {
|
|
3857
|
+
deleteCookie(response, SM_LEDVERY_ID_TOKEN_COOKIE);
|
|
3858
|
+
deleteCookie(response, SM_LEDVERY_ACCESS_TOKEN_COOKIE);
|
|
3859
|
+
}
|
|
3860
|
+
function clearLedveryFlowCookies(response) {
|
|
3861
|
+
deleteCookie(response, SM_LEDVERY_STATE_COOKIE);
|
|
3862
|
+
deleteCookie(response, SM_LEDVERY_PKCE_VERIFIER_COOKIE);
|
|
3863
|
+
deleteCookie(response, SM_LEDVERY_NONCE_COOKIE);
|
|
3864
|
+
}
|
|
3865
|
+
function getCookie(request, name) {
|
|
3866
|
+
const header = request.headers.get("cookie") || "";
|
|
3867
|
+
const match = header.match(new RegExp(`(?:^|;\\s*)${name}=([^;]*)`));
|
|
3868
|
+
return match ? decodeURIComponent(match[1]) : void 0;
|
|
3869
|
+
}
|
|
3870
|
+
function setCookie(response, name, value, opts) {
|
|
3871
|
+
const parts = [
|
|
3872
|
+
`${name}=${encodeURIComponent(value)}`,
|
|
3873
|
+
`Path=${opts.path}`,
|
|
3874
|
+
`Max-Age=${opts.maxAge}`,
|
|
3875
|
+
`SameSite=${opts.sameSite.charAt(0).toUpperCase() + opts.sameSite.slice(1)}`
|
|
3876
|
+
];
|
|
3877
|
+
if (opts.httpOnly) parts.push("HttpOnly");
|
|
3878
|
+
if (opts.secure) parts.push("Secure");
|
|
3879
|
+
if (opts.domain) parts.push(`Domain=${opts.domain}`);
|
|
3880
|
+
response.headers.append("Set-Cookie", parts.join("; "));
|
|
3881
|
+
}
|
|
3882
|
+
function deleteCookie(response, name) {
|
|
3883
|
+
response.headers.append("Set-Cookie", `${name}=; Path=/; Max-Age=0; HttpOnly; SameSite=Lax`);
|
|
3884
|
+
}
|
|
3885
|
+
|
|
3886
|
+
// src/server/redirect.ts
|
|
3887
|
+
function normalizeOrigin(origin) {
|
|
3888
|
+
try {
|
|
3889
|
+
const u = new URL(origin);
|
|
3890
|
+
return `${u.protocol}//${u.host}`.toLowerCase();
|
|
3891
|
+
} catch {
|
|
3892
|
+
return null;
|
|
3893
|
+
}
|
|
3894
|
+
}
|
|
3895
|
+
function isSafeSchemeRelative(input) {
|
|
3896
|
+
return !(input.startsWith("//") || input.startsWith("\\"));
|
|
3897
|
+
}
|
|
3898
|
+
function validateSafeRedirect(input, opts = {}) {
|
|
3899
|
+
const defaultPath = opts.defaultPath ?? "/";
|
|
3900
|
+
if (!input || typeof input !== "string") return defaultPath;
|
|
3901
|
+
const trimmed = input.trim();
|
|
3902
|
+
if (!trimmed) return defaultPath;
|
|
3903
|
+
if (!isSafeSchemeRelative(trimmed)) return defaultPath;
|
|
3904
|
+
const colon = trimmed.indexOf(":");
|
|
3905
|
+
if (colon > 0 && colon < 15) {
|
|
3906
|
+
const scheme = trimmed.slice(0, colon).toLowerCase();
|
|
3907
|
+
if (/^[a-z][a-z0-9+.-]*$/.test(scheme) && scheme !== "http" && scheme !== "https") {
|
|
3908
|
+
return defaultPath;
|
|
3909
|
+
}
|
|
3910
|
+
}
|
|
3911
|
+
if (trimmed.startsWith("/")) {
|
|
3912
|
+
if (trimmed.length > 1 && trimmed[1] === "\\") return defaultPath;
|
|
3913
|
+
return trimmed;
|
|
3914
|
+
}
|
|
3915
|
+
const allowed = (opts.allowedOrigins ?? []).map(normalizeOrigin).filter((o) => o !== null);
|
|
3916
|
+
try {
|
|
3917
|
+
const parsed = new URL(trimmed);
|
|
3918
|
+
const origin = `${parsed.protocol}//${parsed.host}`.toLowerCase();
|
|
3919
|
+
if (!allowed.includes(origin)) return defaultPath;
|
|
3920
|
+
if (opts.stripSameOriginHost !== false) {
|
|
3921
|
+
return `${parsed.pathname}${parsed.search}${parsed.hash}` || "/";
|
|
3922
|
+
}
|
|
3923
|
+
return trimmed;
|
|
3924
|
+
} catch {
|
|
3925
|
+
return defaultPath;
|
|
3926
|
+
}
|
|
3927
|
+
}
|
|
3928
|
+
function isSafeRedirect(input, opts = {}) {
|
|
3929
|
+
if (!input || typeof input !== "string") return false;
|
|
3930
|
+
const defaultPath = `__unsafe_sentinel_${Math.random()}`;
|
|
3931
|
+
const resolved = validateSafeRedirect(input, { ...opts, defaultPath });
|
|
3932
|
+
return resolved !== defaultPath;
|
|
3933
|
+
}
|
|
3934
|
+
|
|
3935
|
+
// src/server/ledvery.ts
|
|
3936
|
+
function createLedveryRoutes(config) {
|
|
3937
|
+
const client = new LedveryClient({
|
|
3938
|
+
issuer: config.issuer,
|
|
3939
|
+
clientId: config.clientId,
|
|
3940
|
+
clientSecret: config.clientSecret,
|
|
3941
|
+
redirectUri: config.redirectUri,
|
|
3942
|
+
fetch: config.fetch
|
|
3943
|
+
});
|
|
3944
|
+
const postLoginRedirect = config.postLoginRedirect || "/";
|
|
3945
|
+
const postLogoutRedirect = config.postLogoutRedirect || "/";
|
|
3946
|
+
const defaultScope = config.defaultScope || "openid email profile";
|
|
3947
|
+
async function handleLogin(request) {
|
|
3948
|
+
const url = new URL(request.url);
|
|
3949
|
+
const returnTo = url.searchParams.get("returnTo");
|
|
3950
|
+
const validatedReturnTo = validateSafeRedirect(returnTo, { defaultPath: postLoginRedirect });
|
|
3951
|
+
const authResult = await client.createAuthorizationUrl({
|
|
3952
|
+
scope: defaultScope
|
|
3953
|
+
});
|
|
3954
|
+
const response = new Response(null, {
|
|
3955
|
+
status: 302,
|
|
3956
|
+
headers: { Location: authResult.url }
|
|
3957
|
+
});
|
|
3958
|
+
setLedveryFlowCookies(response, {
|
|
3959
|
+
state: authResult.state,
|
|
3960
|
+
codeVerifier: authResult.codeVerifier,
|
|
3961
|
+
nonce: authResult.nonce
|
|
3962
|
+
});
|
|
3963
|
+
if (validatedReturnTo !== postLoginRedirect) {
|
|
3964
|
+
response.headers.append(
|
|
3965
|
+
"Set-Cookie",
|
|
3966
|
+
`sm_ledvery_return_to=${encodeURIComponent(validatedReturnTo)}; Path=/; Max-Age=600; HttpOnly; SameSite=Lax${process.env.NODE_ENV === "production" ? "; Secure" : ""}`
|
|
3967
|
+
);
|
|
3968
|
+
}
|
|
3969
|
+
return response;
|
|
3970
|
+
}
|
|
3971
|
+
async function handleCallback(request) {
|
|
3972
|
+
const url = new URL(request.url);
|
|
3973
|
+
const code = url.searchParams.get("code");
|
|
3974
|
+
const callbackState = url.searchParams.get("state");
|
|
3975
|
+
if (!code) {
|
|
3976
|
+
const error = url.searchParams.get("error");
|
|
3977
|
+
const errorDesc = url.searchParams.get("error_description");
|
|
3978
|
+
return new Response(
|
|
3979
|
+
JSON.stringify({ error: error || "missing_code", message: errorDesc || "No authorization code in callback" }),
|
|
3980
|
+
{ status: 403, headers: { "Content-Type": "application/json" } }
|
|
3981
|
+
);
|
|
3982
|
+
}
|
|
3983
|
+
const flowResult = validateAndConsumeLedveryFlowCookies(request, callbackState);
|
|
3984
|
+
if (typeof flowResult === "string") {
|
|
3985
|
+
return new Response(
|
|
3986
|
+
JSON.stringify({ error: "state_mismatch", message: flowResult }),
|
|
3987
|
+
{ status: 403, headers: { "Content-Type": "application/json" } }
|
|
3988
|
+
);
|
|
3989
|
+
}
|
|
3990
|
+
let session;
|
|
3991
|
+
try {
|
|
3992
|
+
session = await client.exchangeCode({
|
|
3993
|
+
code,
|
|
3994
|
+
codeVerifier: flowResult.codeVerifier,
|
|
3995
|
+
receivedState: callbackState,
|
|
3996
|
+
expectedState: getCookieValue(request, "sm_ledvery_state"),
|
|
3997
|
+
expectedNonce: flowResult.nonce
|
|
3998
|
+
});
|
|
3999
|
+
} catch (err) {
|
|
4000
|
+
return new Response(
|
|
4001
|
+
JSON.stringify({ error: "code_exchange_failed", message: err instanceof Error ? err.message : "Code exchange failed" }),
|
|
4002
|
+
{ status: 403, headers: { "Content-Type": "application/json" } }
|
|
4003
|
+
);
|
|
4004
|
+
}
|
|
4005
|
+
const returnTo = getCookieValue(request, "sm_ledvery_return_to");
|
|
4006
|
+
const redirectTo = validateSafeRedirect(returnTo, { defaultPath: postLoginRedirect });
|
|
4007
|
+
const response = new Response(null, {
|
|
4008
|
+
status: 302,
|
|
4009
|
+
headers: { Location: redirectTo }
|
|
4010
|
+
});
|
|
4011
|
+
setLedverySession(response, {
|
|
4012
|
+
idToken: session.idToken,
|
|
4013
|
+
accessToken: session.accessToken,
|
|
4014
|
+
claims: session.claims,
|
|
4015
|
+
expiresAt: session.expiresAt.toISOString()
|
|
4016
|
+
}, {
|
|
4017
|
+
storeAccessToken: config.storeAccessToken,
|
|
4018
|
+
cookies: config.cookies
|
|
4019
|
+
});
|
|
4020
|
+
clearLedveryFlowCookies(response);
|
|
4021
|
+
response.headers.append("Set-Cookie", "sm_ledvery_return_to=; Path=/; Max-Age=0; HttpOnly; SameSite=Lax");
|
|
4022
|
+
return response;
|
|
4023
|
+
}
|
|
4024
|
+
function handleSession(request) {
|
|
4025
|
+
const session = getLedverySession(request);
|
|
4026
|
+
if (!session) {
|
|
4027
|
+
return new Response(JSON.stringify({ session: null }), {
|
|
4028
|
+
status: 200,
|
|
4029
|
+
headers: { "Content-Type": "application/json" }
|
|
4030
|
+
});
|
|
4031
|
+
}
|
|
4032
|
+
const expiresAt = new Date(session.expiresAt);
|
|
4033
|
+
if (expiresAt <= /* @__PURE__ */ new Date()) {
|
|
4034
|
+
return new Response(JSON.stringify({ session: null }), {
|
|
4035
|
+
status: 200,
|
|
4036
|
+
headers: { "Content-Type": "application/json" }
|
|
4037
|
+
});
|
|
4038
|
+
}
|
|
4039
|
+
return new Response(
|
|
4040
|
+
JSON.stringify({
|
|
4041
|
+
session: {
|
|
4042
|
+
sub: session.claims.sub,
|
|
4043
|
+
email: session.claims.email,
|
|
4044
|
+
email_verified: session.claims.email_verified,
|
|
4045
|
+
name: session.claims.name,
|
|
4046
|
+
idp: session.claims.idp,
|
|
4047
|
+
expiresAt: session.expiresAt
|
|
4048
|
+
}
|
|
4049
|
+
}),
|
|
4050
|
+
{ status: 200, headers: { "Content-Type": "application/json" } }
|
|
4051
|
+
);
|
|
4052
|
+
}
|
|
4053
|
+
function handleLogout(_request) {
|
|
4054
|
+
const response = new Response(null, {
|
|
4055
|
+
status: 302,
|
|
4056
|
+
headers: { Location: postLogoutRedirect }
|
|
4057
|
+
});
|
|
4058
|
+
clearLedverySession(response);
|
|
4059
|
+
return response;
|
|
4060
|
+
}
|
|
4061
|
+
async function handler(request, context) {
|
|
4062
|
+
const params = await context.params;
|
|
4063
|
+
const action = params.action?.[0] || "";
|
|
4064
|
+
switch (action) {
|
|
4065
|
+
case "login":
|
|
4066
|
+
return handleLogin(request);
|
|
4067
|
+
case "callback":
|
|
4068
|
+
return handleCallback(request);
|
|
4069
|
+
case "session":
|
|
4070
|
+
return handleSession(request);
|
|
4071
|
+
case "logout":
|
|
4072
|
+
return handleLogout();
|
|
4073
|
+
default:
|
|
4074
|
+
return new Response(
|
|
4075
|
+
JSON.stringify({ error: "not_found", message: `Unknown Ledvery route: ${action}` }),
|
|
4076
|
+
{ status: 404, headers: { "Content-Type": "application/json" } }
|
|
4077
|
+
);
|
|
4078
|
+
}
|
|
4079
|
+
}
|
|
4080
|
+
return {
|
|
4081
|
+
GET: handler,
|
|
4082
|
+
POST: handler
|
|
4083
|
+
};
|
|
4084
|
+
}
|
|
4085
|
+
function getCookieValue(request, name) {
|
|
4086
|
+
const header = request.headers.get("cookie") || "";
|
|
4087
|
+
const match = header.match(new RegExp(`(?:^|;\\s*)${name}=([^;]*)`));
|
|
4088
|
+
return match ? decodeURIComponent(match[1]) : void 0;
|
|
4089
|
+
}
|
|
4090
|
+
|
|
3781
4091
|
// src/server/push.ts
|
|
3782
4092
|
function errorResponse2(code, message, status) {
|
|
3783
4093
|
return new Response(
|
|
@@ -5094,55 +5404,6 @@ async function prefetchBundles(keys) {
|
|
|
5094
5404
|
await Promise.all(keys.map((key) => getBundle(key)));
|
|
5095
5405
|
}
|
|
5096
5406
|
|
|
5097
|
-
// src/server/redirect.ts
|
|
5098
|
-
function normalizeOrigin(origin) {
|
|
5099
|
-
try {
|
|
5100
|
-
const u = new URL(origin);
|
|
5101
|
-
return `${u.protocol}//${u.host}`.toLowerCase();
|
|
5102
|
-
} catch {
|
|
5103
|
-
return null;
|
|
5104
|
-
}
|
|
5105
|
-
}
|
|
5106
|
-
function isSafeSchemeRelative(input) {
|
|
5107
|
-
return !(input.startsWith("//") || input.startsWith("\\"));
|
|
5108
|
-
}
|
|
5109
|
-
function validateSafeRedirect(input, opts = {}) {
|
|
5110
|
-
const defaultPath = opts.defaultPath ?? "/";
|
|
5111
|
-
if (!input || typeof input !== "string") return defaultPath;
|
|
5112
|
-
const trimmed = input.trim();
|
|
5113
|
-
if (!trimmed) return defaultPath;
|
|
5114
|
-
if (!isSafeSchemeRelative(trimmed)) return defaultPath;
|
|
5115
|
-
const colon = trimmed.indexOf(":");
|
|
5116
|
-
if (colon > 0 && colon < 15) {
|
|
5117
|
-
const scheme = trimmed.slice(0, colon).toLowerCase();
|
|
5118
|
-
if (/^[a-z][a-z0-9+.-]*$/.test(scheme) && scheme !== "http" && scheme !== "https") {
|
|
5119
|
-
return defaultPath;
|
|
5120
|
-
}
|
|
5121
|
-
}
|
|
5122
|
-
if (trimmed.startsWith("/")) {
|
|
5123
|
-
if (trimmed.length > 1 && trimmed[1] === "\\") return defaultPath;
|
|
5124
|
-
return trimmed;
|
|
5125
|
-
}
|
|
5126
|
-
const allowed = (opts.allowedOrigins ?? []).map(normalizeOrigin).filter((o) => o !== null);
|
|
5127
|
-
try {
|
|
5128
|
-
const parsed = new URL(trimmed);
|
|
5129
|
-
const origin = `${parsed.protocol}//${parsed.host}`.toLowerCase();
|
|
5130
|
-
if (!allowed.includes(origin)) return defaultPath;
|
|
5131
|
-
if (opts.stripSameOriginHost !== false) {
|
|
5132
|
-
return `${parsed.pathname}${parsed.search}${parsed.hash}` || "/";
|
|
5133
|
-
}
|
|
5134
|
-
return trimmed;
|
|
5135
|
-
} catch {
|
|
5136
|
-
return defaultPath;
|
|
5137
|
-
}
|
|
5138
|
-
}
|
|
5139
|
-
function isSafeRedirect(input, opts = {}) {
|
|
5140
|
-
if (!input || typeof input !== "string") return false;
|
|
5141
|
-
const defaultPath = `__unsafe_sentinel_${Math.random()}`;
|
|
5142
|
-
const resolved = validateSafeRedirect(input, { ...opts, defaultPath });
|
|
5143
|
-
return resolved !== defaultPath;
|
|
5144
|
-
}
|
|
5145
|
-
|
|
5146
5407
|
// src/server/security-headers.ts
|
|
5147
5408
|
var DEFAULT_PERMISSIONS_POLICY = {
|
|
5148
5409
|
// Conference track features — allow self-origin only.
|
|
@@ -5211,4 +5472,4 @@ function buildSecurityHeaders(opts = {}) {
|
|
|
5211
5472
|
return headers2;
|
|
5212
5473
|
}
|
|
5213
5474
|
|
|
5214
|
-
export { CSRF_COOKIE_NAME, CSRF_HEADER_NAME, DEFAULT_PERMISSIONS_POLICY, KNOWN_ACCOUNTS_COOKIE_NAME, OAUTH_STATE_COOKIE_NAME, SESSION_COOKIE_NAME, ScaleMuleError, ScaleMuleServer, USER_ID_COOKIE_NAME, apiHandler, appendKnownAccountCookie, buildClientContextHeaders, buildFlagContext, buildSecurityHeaders, clearKnownAccountsCookie, clearOAuthState, clearSession, configureBundles, configureSecrets, createAnalyticsRoutes, createAuthMiddleware, createAuthRoutes, createNotificationRoutes, createPushRoutes, createServerClient, createWebhookHandler, createWebhookRoutes, errorCodeToStatus, extractClientContext, extractClientContextFromReq, generateCSRFToken, getAppSecret, getAppSecretOrDefault, getBootstrapFlags, getBundle, getCSRFToken, getKnownAccountsCookieRaw, getKnownAccountsFromRequest, getMySqlBundle, getOAuthBundle, getPostgresBundle, getRedisBundle, getS3Bundle, getSession, getSessionFromRequest, getSmtpBundle, invalidateBundleCache, invalidateSecretCache, isSafeRedirect, normalizeKnownAccountsCookie, parseWebhookEvent, prefetchBundles, prefetchSecrets, registerVideoWebhook, removeKnownAccountFromCookie, requireAppSecret, requireBundle, requireSession, resolveGatewayUrl, setOAuthState, unwrap, validateCSRFToken, validateCSRFTokenAsync, validateOAuthState, validateOAuthStateAsync, validateSafeRedirect, verifyWebhookSignature, withAuth, withCSRFProtection, withCSRFToken, withSession };
|
|
5475
|
+
export { CSRF_COOKIE_NAME, CSRF_HEADER_NAME, DEFAULT_PERMISSIONS_POLICY, KNOWN_ACCOUNTS_COOKIE_NAME, OAUTH_STATE_COOKIE_NAME, SESSION_COOKIE_NAME, SM_LEDVERY_ACCESS_TOKEN_COOKIE, SM_LEDVERY_ID_TOKEN_COOKIE, SM_LEDVERY_NONCE_COOKIE, SM_LEDVERY_PKCE_VERIFIER_COOKIE, SM_LEDVERY_STATE_COOKIE, ScaleMuleError, ScaleMuleServer, USER_ID_COOKIE_NAME, apiHandler, appendKnownAccountCookie, buildClientContextHeaders, buildFlagContext, buildSecurityHeaders, clearKnownAccountsCookie, clearOAuthState, clearSession, configureBundles, configureSecrets, createAnalyticsRoutes, createAuthMiddleware, createAuthRoutes, createLedveryRoutes, createNotificationRoutes, createPushRoutes, createServerClient, createWebhookHandler, createWebhookRoutes, errorCodeToStatus, extractClientContext, extractClientContextFromReq, generateCSRFToken, getAppSecret, getAppSecretOrDefault, getBootstrapFlags, getBundle, getCSRFToken, getKnownAccountsCookieRaw, getKnownAccountsFromRequest, getLedverySession, getMySqlBundle, getOAuthBundle, getPostgresBundle, getRedisBundle, getS3Bundle, getSession, getSessionFromRequest, getSmtpBundle, invalidateBundleCache, invalidateSecretCache, isSafeRedirect, normalizeKnownAccountsCookie, parseWebhookEvent, prefetchBundles, prefetchSecrets, registerVideoWebhook, removeKnownAccountFromCookie, requireAppSecret, requireBundle, requireSession, resolveGatewayUrl, setOAuthState, unwrap, validateCSRFToken, validateCSRFTokenAsync, validateOAuthState, validateOAuthStateAsync, validateSafeRedirect, verifyWebhookSignature, withAuth, withCSRFProtection, withCSRFToken, withSession };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { L as LedveryRoutesConfig, a as LedverySessionData, f as createLedveryRoutes, g as getLedverySession } from '../ledvery-C9vvhlUn.mjs';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { L as LedveryRoutesConfig, a as LedverySessionData, f as createLedveryRoutes, g as getLedverySession } from '../ledvery-C9vvhlUn.js';
|