@fungi.computer/oyster 0.17.0 → 0.18.1

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/auth.js CHANGED
@@ -2,6 +2,7 @@ import * as Option from "effect/Option";
2
2
  import * as Schema from "effect/Schema";
3
3
  import { presentedGitKey } from "./git-auth.js";
4
4
  import { sha256 } from "./release.js";
5
+ import { isLoopbackHttp } from "./tenancy/registry-record.js";
5
6
  /** Cookie emitted by ownerKeyAuth, for composing credential-specific adapters. */
6
7
  export const ownerKeyCookieName = "oyster_session";
7
8
  /** Marks a browser that has signed in here before; it carries no authority. */
@@ -64,9 +65,12 @@ export function ownerKeyAuth(ownerKey, ownerId = "owner") {
64
65
  if (Option.isNone(form) ||
65
66
  !(await constantTimeEqual(form.value.key, ownerKey)))
66
67
  return new Response("Wrong key", { status: 401 });
68
+ // Secure everywhere except loopback HTTP, where Safari would drop it and
69
+ // the traffic never leaves this machine.
70
+ const secure = isLoopbackHttp(new URL(request.url)) ? "" : " Secure;";
67
71
  const headers = new Headers({ Location: "/" });
68
- headers.append("Set-Cookie", `${ownerKeyCookieName}=${await sessionValue}; Path=/; HttpOnly; Secure; SameSite=Strict; Max-Age=2592000`);
69
- headers.append("Set-Cookie", `${returningCookieName}=1; Path=/; HttpOnly; Secure; SameSite=Strict; Max-Age=31536000`);
72
+ headers.append("Set-Cookie", `${ownerKeyCookieName}=${await sessionValue}; Path=/; HttpOnly;${secure} SameSite=Strict; Max-Age=2592000`);
73
+ headers.append("Set-Cookie", `${returningCookieName}=1; Path=/; HttpOnly;${secure} SameSite=Strict; Max-Age=31536000`);
70
74
  return new Response(null, { status: 303, headers });
71
75
  },
72
76
  };