@authowl/next 0.2.11 → 0.2.13
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/server.cjs +30 -5
- package/dist/server.js +30 -5
- package/package.json +1 -1
package/dist/server.cjs
CHANGED
|
@@ -82,10 +82,34 @@ var AUTH_FETCH_TIMEOUT_MS = 1e4;
|
|
|
82
82
|
function response(status, body) {
|
|
83
83
|
return body ? Response.json(body, { status, headers: { "cache-control": "no-store" } }) : new Response(null, { status, headers: { "cache-control": "no-store" } });
|
|
84
84
|
}
|
|
85
|
-
function
|
|
85
|
+
function singleForwardingHeader(headers, name) {
|
|
86
|
+
const value = headers.get(name);
|
|
87
|
+
if (!value || value !== value.trim() || value.includes(",")) return null;
|
|
88
|
+
return value;
|
|
89
|
+
}
|
|
90
|
+
function forwardedRequestOrigin(request) {
|
|
91
|
+
const protocol = singleForwardingHeader(request.headers, "x-forwarded-proto");
|
|
92
|
+
const host = singleForwardingHeader(request.headers, "x-forwarded-host") ?? singleForwardingHeader(request.headers, "host");
|
|
93
|
+
if (protocol !== "http" && protocol !== "https" || !host) return null;
|
|
94
|
+
try {
|
|
95
|
+
const url = new URL(`${protocol}://${host}`);
|
|
96
|
+
if (url.username || url.password || url.pathname !== "/" || url.search || url.hash) {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
return url.origin;
|
|
100
|
+
} catch {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function sameOriginBrowserPostOrigin(request) {
|
|
86
105
|
const origin = request.headers.get("origin");
|
|
87
106
|
const site = request.headers.get("sec-fetch-site");
|
|
88
|
-
|
|
107
|
+
const requestOrigin = new URL(request.url).origin;
|
|
108
|
+
if (request.method !== "POST" || origin === null || site !== null && site !== "same-origin" || request.headers.get(APP_SESSION_BRIDGE_HEADER) !== "1" || request.headers.get("content-type")?.split(";", 1)[0]?.trim().toLowerCase() !== "application/json") {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
if (origin === requestOrigin) return requestOrigin;
|
|
112
|
+
return origin === forwardedRequestOrigin(request) ? origin : null;
|
|
89
113
|
}
|
|
90
114
|
function validToken(value) {
|
|
91
115
|
return typeof value === "string" && value.length > 0 && value.length <= 8192 && /^[\u0021-\u007e]+$/.test(value) && !/[",;\\]/.test(value);
|
|
@@ -110,7 +134,8 @@ function createAuthOwlSessionBridge(input) {
|
|
|
110
134
|
return async function authOwlSessionBridge(request) {
|
|
111
135
|
const config = configured ?? getAuthConfig();
|
|
112
136
|
const projectId = config.projectId;
|
|
113
|
-
|
|
137
|
+
const browserOrigin = sameOriginBrowserPostOrigin(request);
|
|
138
|
+
if (!browserOrigin) {
|
|
114
139
|
return response(403, { error: "forbidden" });
|
|
115
140
|
}
|
|
116
141
|
const raw = await request.text();
|
|
@@ -152,7 +177,7 @@ function createAuthOwlSessionBridge(input) {
|
|
|
152
177
|
} catch {
|
|
153
178
|
return response(502, { error: "invalid_auth_response" });
|
|
154
179
|
}
|
|
155
|
-
if (!session
|
|
180
|
+
if (!session?.user || !session.session || session.session.pendingMfaEnrollment === true) {
|
|
156
181
|
return response(401, { error: "invalid_session" });
|
|
157
182
|
}
|
|
158
183
|
if (typeof session.session.expiresAt !== "string") {
|
|
@@ -162,7 +187,7 @@ function createAuthOwlSessionBridge(input) {
|
|
|
162
187
|
if (!Number.isFinite(expires.getTime()) || expires.getTime() <= Date.now()) {
|
|
163
188
|
return response(401, { error: "invalid_session" });
|
|
164
189
|
}
|
|
165
|
-
const secure = new URL(
|
|
190
|
+
const secure = new URL(browserOrigin).protocol === "https:";
|
|
166
191
|
const names = appSessionCookieNames(projectId);
|
|
167
192
|
const result = response(204);
|
|
168
193
|
result.headers.append(
|
package/dist/server.js
CHANGED
|
@@ -52,10 +52,34 @@ var AUTH_FETCH_TIMEOUT_MS = 1e4;
|
|
|
52
52
|
function response(status, body) {
|
|
53
53
|
return body ? Response.json(body, { status, headers: { "cache-control": "no-store" } }) : new Response(null, { status, headers: { "cache-control": "no-store" } });
|
|
54
54
|
}
|
|
55
|
-
function
|
|
55
|
+
function singleForwardingHeader(headers, name) {
|
|
56
|
+
const value = headers.get(name);
|
|
57
|
+
if (!value || value !== value.trim() || value.includes(",")) return null;
|
|
58
|
+
return value;
|
|
59
|
+
}
|
|
60
|
+
function forwardedRequestOrigin(request) {
|
|
61
|
+
const protocol = singleForwardingHeader(request.headers, "x-forwarded-proto");
|
|
62
|
+
const host = singleForwardingHeader(request.headers, "x-forwarded-host") ?? singleForwardingHeader(request.headers, "host");
|
|
63
|
+
if (protocol !== "http" && protocol !== "https" || !host) return null;
|
|
64
|
+
try {
|
|
65
|
+
const url = new URL(`${protocol}://${host}`);
|
|
66
|
+
if (url.username || url.password || url.pathname !== "/" || url.search || url.hash) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
return url.origin;
|
|
70
|
+
} catch {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function sameOriginBrowserPostOrigin(request) {
|
|
56
75
|
const origin = request.headers.get("origin");
|
|
57
76
|
const site = request.headers.get("sec-fetch-site");
|
|
58
|
-
|
|
77
|
+
const requestOrigin = new URL(request.url).origin;
|
|
78
|
+
if (request.method !== "POST" || origin === null || site !== null && site !== "same-origin" || request.headers.get(APP_SESSION_BRIDGE_HEADER) !== "1" || request.headers.get("content-type")?.split(";", 1)[0]?.trim().toLowerCase() !== "application/json") {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
if (origin === requestOrigin) return requestOrigin;
|
|
82
|
+
return origin === forwardedRequestOrigin(request) ? origin : null;
|
|
59
83
|
}
|
|
60
84
|
function validToken(value) {
|
|
61
85
|
return typeof value === "string" && value.length > 0 && value.length <= 8192 && /^[\u0021-\u007e]+$/.test(value) && !/[",;\\]/.test(value);
|
|
@@ -80,7 +104,8 @@ function createAuthOwlSessionBridge(input) {
|
|
|
80
104
|
return async function authOwlSessionBridge(request) {
|
|
81
105
|
const config = configured ?? getAuthConfig();
|
|
82
106
|
const projectId = config.projectId;
|
|
83
|
-
|
|
107
|
+
const browserOrigin = sameOriginBrowserPostOrigin(request);
|
|
108
|
+
if (!browserOrigin) {
|
|
84
109
|
return response(403, { error: "forbidden" });
|
|
85
110
|
}
|
|
86
111
|
const raw = await request.text();
|
|
@@ -122,7 +147,7 @@ function createAuthOwlSessionBridge(input) {
|
|
|
122
147
|
} catch {
|
|
123
148
|
return response(502, { error: "invalid_auth_response" });
|
|
124
149
|
}
|
|
125
|
-
if (!session
|
|
150
|
+
if (!session?.user || !session.session || session.session.pendingMfaEnrollment === true) {
|
|
126
151
|
return response(401, { error: "invalid_session" });
|
|
127
152
|
}
|
|
128
153
|
if (typeof session.session.expiresAt !== "string") {
|
|
@@ -132,7 +157,7 @@ function createAuthOwlSessionBridge(input) {
|
|
|
132
157
|
if (!Number.isFinite(expires.getTime()) || expires.getTime() <= Date.now()) {
|
|
133
158
|
return response(401, { error: "invalid_session" });
|
|
134
159
|
}
|
|
135
|
-
const secure = new URL(
|
|
160
|
+
const secure = new URL(browserOrigin).protocol === "https:";
|
|
136
161
|
const names = appSessionCookieNames(projectId);
|
|
137
162
|
const result = response(204);
|
|
138
163
|
result.headers.append(
|