@cedarjs/auth-dbauth-api 7.0.0-canary.3072 → 7.0.0-canary.3074
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/DbAuthHandler.d.ts +18 -1
- package/dist/DbAuthHandler.d.ts.map +1 -1
- package/dist/DbAuthHandler.js +50 -8
- package/dist/errors.d.ts +2 -2
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +5 -5
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/originValidation.d.ts +131 -0
- package/dist/originValidation.d.ts.map +1 -0
- package/dist/originValidation.js +92 -0
- package/package.json +4 -4
package/dist/DbAuthHandler.d.ts
CHANGED
|
@@ -231,6 +231,17 @@ export interface DbAuthHandlerOptions<TUser = UserType, TUserAttributes = Record
|
|
|
231
231
|
* CORS settings, same as in createGraphqlHandler
|
|
232
232
|
*/
|
|
233
233
|
cors?: CorsConfig;
|
|
234
|
+
/**
|
|
235
|
+
* Extra origins that are trusted for state-changing (non-GET) requests,
|
|
236
|
+
* on top of the request's own host and any origins already listed in
|
|
237
|
+
* `cors.origin`.
|
|
238
|
+
*
|
|
239
|
+
* Needed when the web side and API are on different origins and
|
|
240
|
+
* `cors.origin` isn't set to those origins, or when `cors.origin` is set
|
|
241
|
+
* to `true` -- reflecting any request origin is never treated as trust,
|
|
242
|
+
* so that combination requires listing trusted origins here explicitly.
|
|
243
|
+
*/
|
|
244
|
+
trustedOrigins?: string | string[];
|
|
234
245
|
}
|
|
235
246
|
export interface SignupHandlerOptions<TUserAttributes> {
|
|
236
247
|
username: string;
|
|
@@ -312,6 +323,8 @@ export declare class DbAuthHandler<TUser extends UserType, TUserAttributes = Rec
|
|
|
312
323
|
body?: string | undefined;
|
|
313
324
|
statusCode: number;
|
|
314
325
|
}>;
|
|
326
|
+
_requestHost(): string | null;
|
|
327
|
+
_requestProtocol(): string | null;
|
|
315
328
|
forgotPassword(): Promise<AuthMethodOutput>;
|
|
316
329
|
getToken(): Promise<AuthMethodOutput>;
|
|
317
330
|
login(): Promise<AuthMethodOutput>;
|
|
@@ -334,7 +347,6 @@ export declare class DbAuthHandler<TUser extends UserType, TUserAttributes = Rec
|
|
|
334
347
|
}): (string | null)[];
|
|
335
348
|
_createAuthProviderCookieString(): string;
|
|
336
349
|
_createSessionCookieString<TIdType = any>(data: DbAuthSession<TIdType>, csrfToken: string): string;
|
|
337
|
-
_validateCsrf(): Promise<boolean>;
|
|
338
350
|
_findUserByToken(token: string): Promise<any>;
|
|
339
351
|
_clearResetToken(user: Record<string, unknown>): Promise<void>;
|
|
340
352
|
_verifyUser(username: string | undefined, password: string | undefined): Promise<any>;
|
|
@@ -364,6 +376,11 @@ export declare class DbAuthHandler<TUser extends UserType, TUserAttributes = Rec
|
|
|
364
376
|
body: string;
|
|
365
377
|
headers: Headers;
|
|
366
378
|
};
|
|
379
|
+
_forbidden(message: string): {
|
|
380
|
+
statusCode: number;
|
|
381
|
+
body: string;
|
|
382
|
+
headers: Headers;
|
|
383
|
+
};
|
|
367
384
|
_getUserMatchCriteriaOptions(username: string, usernameMatchFlowOption: string | undefined): {
|
|
368
385
|
[x: string]: string;
|
|
369
386
|
} | {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DbAuthHandler.d.ts","sourceRoot":"","sources":["../src/DbAuthHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,0BAA0B,EAG1B,wBAAwB,EAKzB,MAAM,wBAAwB,CAAA;AAC/B,OAAO,KAAK,EAAE,oBAAoB,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,YAAY,CAAA;AAIhF,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"DbAuthHandler.d.ts","sourceRoot":"","sources":["../src/DbAuthHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,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C5B,QAAQ,EAAE,MAAM,GAAG,SAAS;IA6CxB,eAAe,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,QAAQ,EAAE,MAAM;IA6C/D,eAAe;IAqCf,WAAW;IAqCX,cAAc;IAqBpB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,KAAK,IAAI,MAAM;IAYxE,cAAc,CACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACzB,UAAU,SAAM,GACf,CAAC;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,EAAE,OAAO,EAAE;QAAE,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC;IAkBpD,eAAe,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,gBAAgB;IAIrE,GAAG,CACD,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5D,OAAO,UAAgB,EACvB,OAAO;;KAAsB;;;;;IAW/B,SAAS;;;IAMT,WAAW,CAAC,OAAO,EAAE,MAAM;;;;;IAQ3B,UAAU,CAAC,OAAO,EAAE,MAAM;;;;;IAQ1B,4BAA4B,CAC1B,QAAQ,EAAE,MAAM,EAChB,uBAAuB,EAAE,MAAM,GAAG,SAAS;;;;;;;;CAgB9C"}
|
package/dist/DbAuthHandler.js
CHANGED
|
@@ -6,6 +6,13 @@ import {
|
|
|
6
6
|
normalizeRequest
|
|
7
7
|
} from "@cedarjs/api";
|
|
8
8
|
import * as DbAuthError from "./errors.js";
|
|
9
|
+
import {
|
|
10
|
+
isProxiedRequest,
|
|
11
|
+
isRequestOriginTrusted,
|
|
12
|
+
requiresOriginValidation,
|
|
13
|
+
resolveRequestHost,
|
|
14
|
+
resolveRequestProtocol
|
|
15
|
+
} from "./originValidation.js";
|
|
9
16
|
import {
|
|
10
17
|
decryptSession,
|
|
11
18
|
encryptSession,
|
|
@@ -188,11 +195,28 @@ class DbAuthHandler {
|
|
|
188
195
|
if (this.httpMethod !== DbAuthHandler.VERBS[method]) {
|
|
189
196
|
return this.createResponse(this._notFound(), corsHeaders);
|
|
190
197
|
}
|
|
198
|
+
if (requiresOriginValidation(this.httpMethod) && !isRequestOriginTrusted(
|
|
199
|
+
{
|
|
200
|
+
method: this.httpMethod,
|
|
201
|
+
headers: this.normalizedRequest.headers,
|
|
202
|
+
host: this._requestHost(),
|
|
203
|
+
protocol: this._requestProtocol(),
|
|
204
|
+
proxied: isProxiedRequest(this.normalizedRequest.headers)
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
trustedOrigins: this.options.trustedOrigins,
|
|
208
|
+
corsOrigin: this.options.cors?.origin
|
|
209
|
+
}
|
|
210
|
+
)) {
|
|
211
|
+
throw new DbAuthError.UntrustedOriginError();
|
|
212
|
+
}
|
|
191
213
|
const [body, headers, options = { statusCode: 200 }] = await this[method]();
|
|
192
214
|
return this.createResponse(this._ok(body, headers, options), corsHeaders);
|
|
193
215
|
} catch (e) {
|
|
194
216
|
if (e instanceof DbAuthError.WrongVerbError) {
|
|
195
217
|
return this.createResponse(this._notFound(), corsHeaders);
|
|
218
|
+
} else if (e instanceof DbAuthError.UntrustedOriginError) {
|
|
219
|
+
return this.createResponse(this._forbidden(e.message), corsHeaders);
|
|
196
220
|
} else {
|
|
197
221
|
return this.createResponse(
|
|
198
222
|
this._badRequest(e.message || e),
|
|
@@ -201,6 +225,25 @@ class DbAuthHandler {
|
|
|
201
225
|
}
|
|
202
226
|
}
|
|
203
227
|
}
|
|
228
|
+
// best-effort host the request was sent to, used by origin validation to
|
|
229
|
+
// allow same-origin requests through with no extra configuration. Prefers
|
|
230
|
+
// `X-Forwarded-Host` over the connection-level host/URL -- see
|
|
231
|
+
// `resolveRequestHost` for why that's safe behind a proxy
|
|
232
|
+
_requestHost() {
|
|
233
|
+
return resolveRequestHost(
|
|
234
|
+
this.normalizedRequest.headers,
|
|
235
|
+
isFetchApiRequest(this.event) ? this.event.url : void 0
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
// best-effort scheme the request arrived over, used alongside
|
|
239
|
+
// `_requestHost` for origin validation. See `resolveRequestProtocol` for
|
|
240
|
+
// when it can and can't be determined reliably
|
|
241
|
+
_requestProtocol() {
|
|
242
|
+
return resolveRequestProtocol(
|
|
243
|
+
this.normalizedRequest.headers,
|
|
244
|
+
isFetchApiRequest(this.event) ? this.event.url : void 0
|
|
245
|
+
);
|
|
246
|
+
}
|
|
204
247
|
async forgotPassword() {
|
|
205
248
|
const { enabled = true } = this.options.forgotPassword;
|
|
206
249
|
if (!enabled) {
|
|
@@ -681,14 +724,6 @@ class DbAuthHandler {
|
|
|
681
724
|
].join(";");
|
|
682
725
|
return sessionCookieString;
|
|
683
726
|
}
|
|
684
|
-
// checks the CSRF token in the header against the CSRF token in the session
|
|
685
|
-
// and throw an error if they are not the same (not used yet)
|
|
686
|
-
async _validateCsrf() {
|
|
687
|
-
if (this.sessionCsrfToken !== this.normalizedRequest.headers.get("csrf-token")) {
|
|
688
|
-
throw new DbAuthError.CsrfTokenMismatchError();
|
|
689
|
-
}
|
|
690
|
-
return true;
|
|
691
|
-
}
|
|
692
727
|
async _findUserByToken(token) {
|
|
693
728
|
const tokenExpires = /* @__PURE__ */ new Date();
|
|
694
729
|
tokenExpires.setSeconds(
|
|
@@ -904,6 +939,13 @@ class DbAuthHandler {
|
|
|
904
939
|
headers: new Headers({ "content-type": "application/json" })
|
|
905
940
|
};
|
|
906
941
|
}
|
|
942
|
+
_forbidden(message) {
|
|
943
|
+
return {
|
|
944
|
+
statusCode: 403,
|
|
945
|
+
body: JSON.stringify({ error: message }),
|
|
946
|
+
headers: new Headers({ "content-type": "application/json" })
|
|
947
|
+
};
|
|
948
|
+
}
|
|
907
949
|
_getUserMatchCriteriaOptions(username, usernameMatchFlowOption) {
|
|
908
950
|
const findUniqueUserMatchCriteriaOptions = !usernameMatchFlowOption ? { [this.options.authFields.username]: username } : {
|
|
909
951
|
[this.options.authFields.username]: {
|
package/dist/errors.d.ts
CHANGED
|
@@ -49,8 +49,8 @@ export declare class DuplicateUsernameError extends Error {
|
|
|
49
49
|
export declare class IncorrectPasswordError extends Error {
|
|
50
50
|
constructor(username: string, message?: string | undefined);
|
|
51
51
|
}
|
|
52
|
-
export declare class
|
|
53
|
-
constructor();
|
|
52
|
+
export declare class UntrustedOriginError extends Error {
|
|
53
|
+
constructor(message?: string);
|
|
54
54
|
}
|
|
55
55
|
export declare class SessionDecryptionError extends Error {
|
|
56
56
|
constructor();
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,oBAAqB,SAAQ,KAAK;;CAO9C;AAED,qBAAa,wBAAyB,SAAQ,KAAK;;CAKlD;AAED,qBAAa,mBAAoB,SAAQ,KAAK;;CAK7C;AAED,qBAAa,oBAAqB,SAAQ,KAAK;;CAK9C;AAED,qBAAa,4BAA6B,SAAQ,KAAK;;CAKtD;AAED,qBAAa,2BAA4B,SAAQ,KAAK;;CAKrD;AAED,qBAAa,qBAAsB,SAAQ,KAAK;;CAO/C;AAED,qBAAa,0BAA2B,SAAQ,KAAK;;CAOpD;AAED,qBAAa,sBAAuB,SAAQ,KAAK;gBACnC,IAAI,EAAE,MAAM;CAIzB;AAED,qBAAa,cAAe,SAAQ,KAAK;gBAC3B,UAAU,EAAE,MAAM;CAI/B;AAED,qBAAa,gBAAiB,SAAQ,KAAK;;CAK1C;AAED,qBAAa,iBAAkB,SAAQ,KAAK;gBAExC,QAAQ,GAAE,MAAM,GAAG,SAAqB,EACxC,OAAO,GAAE,MAAM,GAAG,SAA4C;CAUjE;AAED,qBAAa,gCAAiC,SAAQ,KAAK;gBAEvD,OAAO,GAAE,MAAM,GAAG,SAAqD;CAK1E;AAED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
|
}
|
|
115
|
-
class
|
|
116
|
-
constructor() {
|
|
117
|
-
super(
|
|
118
|
-
this.name = "
|
|
115
|
+
class UntrustedOriginError extends Error {
|
|
116
|
+
constructor(message = "Request origin is not trusted") {
|
|
117
|
+
super(message);
|
|
118
|
+
this.name = "UntrustedOriginError";
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
121
|
class SessionDecryptionError extends Error {
|
|
@@ -197,7 +197,6 @@ class NoWebAuthnSessionError extends WebAuthnError {
|
|
|
197
197
|
}
|
|
198
198
|
}
|
|
199
199
|
export {
|
|
200
|
-
CsrfTokenMismatchError,
|
|
201
200
|
DuplicateUsernameError,
|
|
202
201
|
FieldRequiredError,
|
|
203
202
|
FlowNotEnabledError,
|
|
@@ -222,6 +221,7 @@ export {
|
|
|
222
221
|
ReusedPasswordError,
|
|
223
222
|
SessionDecryptionError,
|
|
224
223
|
UnknownAuthMethodError,
|
|
224
|
+
UntrustedOriginError,
|
|
225
225
|
UserNotFoundError,
|
|
226
226
|
UsernameAndPasswordRequiredError,
|
|
227
227
|
UsernameNotFoundError,
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAA;AACrD,cAAc,aAAa,CAAA;AAC3B,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAA;AACrD,cAAc,aAAa,CAAA;AAC3B,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAC7D,cAAc,uBAAuB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,7 @@ export * from "./DbAuthHandler.js";
|
|
|
2
2
|
import { PasswordValidationError } from "./errors.js";
|
|
3
3
|
export * from "./shared.js";
|
|
4
4
|
import { authDecoder, createAuthDecoder } from "./decoder.js";
|
|
5
|
+
export * from "./originValidation.js";
|
|
5
6
|
export {
|
|
6
7
|
PasswordValidationError,
|
|
7
8
|
authDecoder,
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import type { CorsConfig } from '@cedarjs/api';
|
|
2
|
+
/**
|
|
3
|
+
* Minimal, transport-agnostic shape of an incoming request needed to decide
|
|
4
|
+
* whether its `Origin` header should be trusted for a state-changing
|
|
5
|
+
* request. Deliberately decoupled from any specific request/event type (no
|
|
6
|
+
* `DbAuthHandler` coupling) so this helper can be reused by other handler
|
|
7
|
+
* packages.
|
|
8
|
+
*/
|
|
9
|
+
export interface OriginValidationRequest {
|
|
10
|
+
/**
|
|
11
|
+
* HTTP method of the request, e.g. `GET`, `POST`. Used by
|
|
12
|
+
* {@link requiresOriginValidation} to decide whether a request needs to be
|
|
13
|
+
* checked at all.
|
|
14
|
+
*/
|
|
15
|
+
method: string;
|
|
16
|
+
/**
|
|
17
|
+
* Request headers, including `origin` if the browser sent one.
|
|
18
|
+
*/
|
|
19
|
+
headers: Headers;
|
|
20
|
+
/**
|
|
21
|
+
* Host (and port, if non-default) the request was sent to, resolved with
|
|
22
|
+
* {@link resolveRequestHost}. Used to allow same-origin requests through
|
|
23
|
+
* with no extra configuration, which covers the standard Cedar setup
|
|
24
|
+
* where the web side proxies API requests through its own origin. Pass
|
|
25
|
+
* `null` when the host can't be determined.
|
|
26
|
+
*/
|
|
27
|
+
host?: string | null;
|
|
28
|
+
/**
|
|
29
|
+
* Scheme (`http`/`https`) the request is considered to have arrived
|
|
30
|
+
* over, resolved with {@link resolveRequestProtocol}, when it can be
|
|
31
|
+
* determined reliably. Used as an extra check alongside `host` when
|
|
32
|
+
* deciding whether the `Origin` header matches the request's own
|
|
33
|
+
* origin. Pass `null`/`undefined` when it can't be determined -- in that
|
|
34
|
+
* case only the host is compared, unless `proxied` narrows that further
|
|
35
|
+
* (see {@link isProxiedRequest}).
|
|
36
|
+
*/
|
|
37
|
+
protocol?: string | null;
|
|
38
|
+
/**
|
|
39
|
+
* Whether the request declares itself as arriving through a forwarding
|
|
40
|
+
* proxy, resolved with {@link isProxiedRequest}. Scopes the
|
|
41
|
+
* unknown-scheme same-host restriction to requests a proxy actually
|
|
42
|
+
* touched -- see `isSameOrigin`.
|
|
43
|
+
*/
|
|
44
|
+
proxied?: boolean;
|
|
45
|
+
}
|
|
46
|
+
export interface OriginValidationConfig {
|
|
47
|
+
/**
|
|
48
|
+
* Extra origins that are always trusted for state-changing requests, on
|
|
49
|
+
* top of the request's own host and any origins already listed in
|
|
50
|
+
* `cors.origin`.
|
|
51
|
+
*/
|
|
52
|
+
trustedOrigins?: string | string[];
|
|
53
|
+
/**
|
|
54
|
+
* The `origin` value from a handler's `cors` config (same shape as passed
|
|
55
|
+
* to `createCorsContext`). String and array values are treated as
|
|
56
|
+
* trusted origins.
|
|
57
|
+
*
|
|
58
|
+
* `true` (reflect any request origin back in
|
|
59
|
+
* `Access-Control-Allow-Origin`) is intentionally NOT treated as trust --
|
|
60
|
+
* combined with `credentials: true` that is the exact misconfiguration
|
|
61
|
+
* this check protects against. Apps that need to accept requests from an
|
|
62
|
+
* arbitrary set of origins must list them explicitly in `trustedOrigins`
|
|
63
|
+
* instead.
|
|
64
|
+
*/
|
|
65
|
+
corsOrigin?: CorsConfig['origin'];
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* HTTP methods that can change server-side state and therefore need their
|
|
69
|
+
* `Origin` validated. `GET` and `HEAD` requests are read-only and are never
|
|
70
|
+
* checked.
|
|
71
|
+
*/
|
|
72
|
+
export declare function requiresOriginValidation(method: string): boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Resolves the host a request should be considered as having arrived at,
|
|
75
|
+
* preferring a forwarding proxy's advertised host over the connection-level
|
|
76
|
+
* one.
|
|
77
|
+
*
|
|
78
|
+
* A proxy in front of the api side (this framework's own `cedar serve
|
|
79
|
+
* --ud`, or an external nginx/CDN) terminates the browser's connection and
|
|
80
|
+
* opens a new one to the api server, so the request's own URL/`Host` header
|
|
81
|
+
* reflects that internal hop rather than the origin-facing host the
|
|
82
|
+
* browser actually targeted. `X-Forwarded-Host` carries the origin-facing
|
|
83
|
+
* host instead.
|
|
84
|
+
*
|
|
85
|
+
* Trusting `X-Forwarded-Host` here is safe for CSRF purposes: a cross-site
|
|
86
|
+
* HTML form can't set arbitrary request headers, and a cross-origin
|
|
87
|
+
* `fetch()` that sets a custom header triggers a CORS preflight, so an
|
|
88
|
+
* attacker can't forge it without already having crossed the browser's
|
|
89
|
+
* CORS checks.
|
|
90
|
+
*
|
|
91
|
+
* @param url - The request's own URL (Fetch API requests only), used as a
|
|
92
|
+
* fallback when neither `X-Forwarded-Host` nor `Host` is present.
|
|
93
|
+
*/
|
|
94
|
+
export declare function resolveRequestHost(headers: Headers, url?: string | null): string | null;
|
|
95
|
+
/**
|
|
96
|
+
* Resolves the scheme (`http`/`https`) a request should be considered as
|
|
97
|
+
* having arrived over, mirroring {@link resolveRequestHost}.
|
|
98
|
+
*
|
|
99
|
+
* The request's own URL is only used as a fallback when no
|
|
100
|
+
* `X-Forwarded-Host` is present -- once a proxy has declared itself by
|
|
101
|
+
* setting that header, the request's own URL reflects the internal hop to
|
|
102
|
+
* the proxy, and its scheme can't be assumed to match what the browser
|
|
103
|
+
* actually used unless the proxy also set `X-Forwarded-Proto`.
|
|
104
|
+
*
|
|
105
|
+
* @param url - The request's own URL (Fetch API requests only).
|
|
106
|
+
*/
|
|
107
|
+
export declare function resolveRequestProtocol(headers: Headers, url?: string | null): string | null;
|
|
108
|
+
/**
|
|
109
|
+
* Whether a request declares itself as arriving through a forwarding
|
|
110
|
+
* proxy, i.e. carries an `X-Forwarded-Host` header.
|
|
111
|
+
*
|
|
112
|
+
* Used to scope the unknown-scheme same-host restriction (see
|
|
113
|
+
* `isSameOrigin`) to requests a proxy actually touched. A request with no
|
|
114
|
+
* forwarding headers at all is a direct connection -- the normal case for
|
|
115
|
+
* dev servers, classic `cedar serve`, and most self-hosts -- not evidence
|
|
116
|
+
* of a proxy.
|
|
117
|
+
*/
|
|
118
|
+
export declare function isProxiedRequest(headers: Headers): boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Decides whether a request's `Origin` header should be trusted.
|
|
121
|
+
*
|
|
122
|
+
* Requests with no `Origin` header are always trusted: non-browser clients
|
|
123
|
+
* (server-to-server calls, CLIs, mobile apps) don't send one and don't carry
|
|
124
|
+
* ambient browser cookies, so they aren't CSRF vectors.
|
|
125
|
+
*
|
|
126
|
+
* When an `Origin` header is present, it's trusted when it matches the
|
|
127
|
+
* request's own host, is listed in `trustedOrigins`, or is listed in
|
|
128
|
+
* `corsOrigin`. Everything else is untrusted.
|
|
129
|
+
*/
|
|
130
|
+
export declare function isRequestOriginTrusted(request: OriginValidationRequest, config: OriginValidationConfig): boolean;
|
|
131
|
+
//# sourceMappingURL=originValidation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"originValidation.d.ts","sourceRoot":"","sources":["../src/originValidation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAE9C;;;;;;GAMG;AACH,MAAM,WAAW,uBAAuB;IACtC;;;;OAIG;IACH,MAAM,EAAE,MAAM,CAAA;IACd;;OAEG;IACH,OAAO,EAAE,OAAO,CAAA;IAChB;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB;;;;;;;;OAQG;IACH,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB;;;;;OAKG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,MAAM,WAAW,sBAAsB;IACrC;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IAClC;;;;;;;;;;;OAWG;IACH,UAAU,CAAC,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAA;CAClC;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAGhE;AAgBD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,OAAO,EAChB,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,GAClB,MAAM,GAAG,IAAI,CAoBf;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,OAAO,EAChB,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,GAClB,MAAM,GAAG,IAAI,CAef;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAE1D;AA+CD;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,uBAAuB,EAChC,MAAM,EAAE,sBAAsB,GAC7B,OAAO,CA6BT"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
function requiresOriginValidation(method) {
|
|
2
|
+
const upperMethod = method.toUpperCase();
|
|
3
|
+
return upperMethod !== "GET" && upperMethod !== "HEAD";
|
|
4
|
+
}
|
|
5
|
+
function toOriginList(value) {
|
|
6
|
+
if (!value) {
|
|
7
|
+
return [];
|
|
8
|
+
}
|
|
9
|
+
return Array.isArray(value) ? value : [value];
|
|
10
|
+
}
|
|
11
|
+
function firstForwardedValue(headerValue) {
|
|
12
|
+
return headerValue.split(",")[0].trim();
|
|
13
|
+
}
|
|
14
|
+
function resolveRequestHost(headers, url) {
|
|
15
|
+
const forwardedHost = headers.get("x-forwarded-host");
|
|
16
|
+
if (forwardedHost) {
|
|
17
|
+
return firstForwardedValue(forwardedHost);
|
|
18
|
+
}
|
|
19
|
+
const host = headers.get("host");
|
|
20
|
+
if (host) {
|
|
21
|
+
return host;
|
|
22
|
+
}
|
|
23
|
+
if (url) {
|
|
24
|
+
try {
|
|
25
|
+
return new URL(url).host;
|
|
26
|
+
} catch {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
function resolveRequestProtocol(headers, url) {
|
|
33
|
+
const forwardedProto = headers.get("x-forwarded-proto");
|
|
34
|
+
if (forwardedProto) {
|
|
35
|
+
return firstForwardedValue(forwardedProto).toLowerCase();
|
|
36
|
+
}
|
|
37
|
+
if (!headers.get("x-forwarded-host") && url) {
|
|
38
|
+
try {
|
|
39
|
+
return new URL(url).protocol.replace(":", "");
|
|
40
|
+
} catch {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
function isProxiedRequest(headers) {
|
|
47
|
+
return headers.get("x-forwarded-host") !== null;
|
|
48
|
+
}
|
|
49
|
+
function isSameOrigin(origin, host, protocol, proxied) {
|
|
50
|
+
try {
|
|
51
|
+
const originUrl = new URL(origin);
|
|
52
|
+
if (originUrl.host !== host) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
if (protocol) {
|
|
56
|
+
return originUrl.protocol === `${protocol}:`;
|
|
57
|
+
}
|
|
58
|
+
if (proxied) {
|
|
59
|
+
return originUrl.protocol === "https:";
|
|
60
|
+
}
|
|
61
|
+
return true;
|
|
62
|
+
} catch {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function isRequestOriginTrusted(request, config) {
|
|
67
|
+
const origin = request.headers.get("origin");
|
|
68
|
+
if (!origin) {
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
if (request.host && isSameOrigin(origin, request.host, request.protocol, request.proxied)) {
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
const trustedOrigins = toOriginList(config.trustedOrigins);
|
|
75
|
+
if (trustedOrigins.includes(origin)) {
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
const corsOrigins = toOriginList(
|
|
79
|
+
typeof config.corsOrigin === "string" || Array.isArray(config.corsOrigin) ? config.corsOrigin : void 0
|
|
80
|
+
);
|
|
81
|
+
if (corsOrigins.includes(origin)) {
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
export {
|
|
87
|
+
isProxiedRequest,
|
|
88
|
+
isRequestOriginTrusted,
|
|
89
|
+
requiresOriginValidation,
|
|
90
|
+
resolveRequestHost,
|
|
91
|
+
resolveRequestProtocol
|
|
92
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/auth-dbauth-api",
|
|
3
|
-
"version": "7.0.0-canary.
|
|
3
|
+
"version": "7.0.0-canary.3074",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/cedarjs/cedar.git",
|
|
@@ -57,13 +57,13 @@
|
|
|
57
57
|
"test:watch": "vitest watch"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@cedarjs/project-config": "7.0.0-canary.
|
|
60
|
+
"@cedarjs/project-config": "7.0.0-canary.3074",
|
|
61
61
|
"md5": "2.3.0",
|
|
62
62
|
"uuid": "11.1.0"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@cedarjs/api": "7.0.0-canary.
|
|
66
|
-
"@cedarjs/framework-tools": "7.0.0-canary.
|
|
65
|
+
"@cedarjs/api": "7.0.0-canary.3074",
|
|
66
|
+
"@cedarjs/framework-tools": "7.0.0-canary.3074",
|
|
67
67
|
"@simplewebauthn/server": "13.3.3",
|
|
68
68
|
"@types/aws-lambda": "8.10.162",
|
|
69
69
|
"@types/md5": "2.3.6",
|