@sylphx/auth 0.1.2 → 0.1.3

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/README.md CHANGED
@@ -24,6 +24,24 @@ Request URL reflects the trusted public origin, or supply `isPublicRequest`
24
24
  with your edge's trusted-origin verification. Never trust caller-supplied
25
25
  forwarded headers alone.
26
26
 
27
+ ### Sylphx Hosting
28
+
29
+ Set `trustSylphxEdge: true` on the handler when **all ingress paths to it are
30
+ restricted to managed literal-host routes** that overwrite `Sylphx-Edge`,
31
+ `X-Forwarded-Host` and `X-Forwarded-Proto` for the matched public hostname.
32
+ This admits the rewritten internal request URL only with `Sylphx-Edge: public`,
33
+ a single exact forwarded host equal to the configured `origin`’s host (including
34
+ any non-default port), and `X-Forwarded-Proto: https`. Partial or contradictory
35
+ headers are rejected even when the request URL matches. With no edge headers,
36
+ the request URL must match the configured HTTPS origin as before.
37
+
38
+ Do not enable this on wildcard, direct-to-service, or other routes where a
39
+ caller can supply either forwarded header. The edge marker is not a credential,
40
+ and the HTTPS stamp is the configured public scheme, not a TLS observation.
41
+ Remove a hand-rolled `isPublicRequest` when adopting this option; that callback
42
+ otherwise retains precedence. Browser Origin and fetch-metadata checks, OAuth
43
+ state checks, and redirect destinations are unchanged.
44
+
27
45
  | Route | Method | Input / result |
28
46
  | --- | --- | --- |
29
47
  | `/auth/config` | GET | Public capabilities only; no credentials or upstream URLs |
package/dist/server.d.ts CHANGED
@@ -78,7 +78,9 @@ export type SylphxAuthOptions = {
78
78
  allowReturnTo?: (path: string) => boolean;
79
79
  flowCookie?: string;
80
80
  sessionCookie?: string;
81
- /** For an existing edge: check a trusted host binding on the internal request. */
81
+ /** Opt in only on managed literal-host routes that overwrite all three Sylphx Edge headers. */
82
+ trustSylphxEdge?: boolean;
83
+ /** Override the public request check, including the built-in Sylphx Edge policy. */
82
84
  isPublicRequest?: (request: Request) => boolean;
83
85
  /** Only for hosts with an existing authoritative session and revocation mechanism. */
84
86
  session?: SessionAdapter;
package/dist/server.js CHANGED
@@ -48,6 +48,7 @@ function portalStart(provider, row, discovery, pin, slug) {
48
48
  }
49
49
  export function createSylphxAuthHandler(options) {
50
50
  const origin = requireOrigin(options.origin);
51
+ const publicHost = new URL(origin).host;
51
52
  const api = requireOrigin(options.authApiOrigin);
52
53
  const tenantAuthOrigin = options.tenantAuthOrigin === undefined ? undefined : requireOrigin(options.tenantAuthOrigin);
53
54
  if (tenantAuthOrigin && tenantAuthOrigin === api)
@@ -329,9 +330,21 @@ export function createSylphxAuthHandler(options) {
329
330
  return fail();
330
331
  }
331
332
  }
333
+ function isPublicRequest(request, url) {
334
+ if (options.trustSylphxEdge === true) {
335
+ const edge = request.headers.get('sylphx-edge');
336
+ const host = request.headers.get('x-forwarded-host');
337
+ const proto = request.headers.get('x-forwarded-proto');
338
+ if (edge !== null || host !== null || proto !== null) {
339
+ // Exact comparisons reject combined duplicates and never choose a list entry.
340
+ return edge === 'public' && host === publicHost && proto === 'https';
341
+ }
342
+ }
343
+ return url.origin === origin;
344
+ }
332
345
  return async (request) => {
333
346
  const url = new URL(request.url);
334
- if (!(options.isPublicRequest?.(request) ?? url.origin === origin))
347
+ if (!(options.isPublicRequest?.(request) ?? isPublicRequest(request, url)))
335
348
  return problem('not_allowed', 403);
336
349
  const { pathname } = url;
337
350
  const identity = transport(request, fetchUpstream, api);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sylphx/auth",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "type": "module",
5
5
  "description": "Web-standard first-party Auth handler and its browser contract",
6
6
  "exports": {