@atelic-action/ui 3.15.0 → 3.17.0

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
@@ -274,7 +274,7 @@ export const POST = createRequestLink({ noun: "preview" });
274
274
  | Env | Read by | What it does |
275
275
  |---|---|---|
276
276
  | `GATE_SESSION_SECRET` | all three | The signing secret, and the switch: unset, the gate is off. Use 32 random bytes or more |
277
- | `GATE_ALLOWLIST` | all three | Comma separated emails that may receive a link. Taking an address off, then redeploying, refuses its outstanding link and ends its session |
277
+ | `GATE_ALLOWLIST` | all three | Comma separated entries that may receive a link. An address matches itself exactly; the business's domain, written `example.com` or `@example.com`, admits every address on it but none on its subdomains. Case never matters, and an empty entry or a word with no dot matches nothing. Taking an entry off, then redeploying, refuses its outstanding links and ends their sessions |
278
278
  | `RESEND_API_KEY` | request link | The sending only key the link goes out on |
279
279
  | `GATE_BASE_URL` | request link | The host the link points at; a bare host is read as https, and plain http is refused unless it is local. Unset, production uses the project's own domain and a preview uses the deployment it was asked on |
280
280
  | `GATE_FROM`, `GATE_SUBJECT`, `GATE_LINK_TTL_MIN` | request link | Sender, subject, and link lifetime in minutes (15, a day at most) |
@@ -2,7 +2,15 @@
2
2
  * How the gate reads its settings from the environment. Shared by the two
3
3
  * sign in functions and the middleware, so each reads a value the same way.
4
4
  */
5
- /** Whether an address is on the comma separated allowlist. */
5
+ /**
6
+ * Whether an address is on the comma separated allowlist. An entry is either
7
+ * a full address, which matches that address exactly, or the business's
8
+ * domain, written bare (`example.com`) or with a leading at (`@example.com`),
9
+ * which admits every address whose part after the `@` is that domain (the
10
+ * business's own people, whoever the page is forwarded to). A domain never
11
+ * admits its subdomains, and everything is compared case folded. An entry
12
+ * that is empty, or is no address and holds no dot, matches nothing.
13
+ */
6
14
  export declare function isAllowed(email: string, allowlist: string | undefined): boolean;
7
15
  /**
8
16
  * A setting that has to be a positive, finite number, or its default. A
@@ -2,15 +2,44 @@
2
2
  * How the gate reads its settings from the environment. Shared by the two
3
3
  * sign in functions and the middleware, so each reads a value the same way.
4
4
  */
5
- /** Whether an address is on the comma separated allowlist. */
5
+ /**
6
+ * Whether an address is on the comma separated allowlist. An entry is either
7
+ * a full address, which matches that address exactly, or the business's
8
+ * domain, written bare (`example.com`) or with a leading at (`@example.com`),
9
+ * which admits every address whose part after the `@` is that domain (the
10
+ * business's own people, whoever the page is forwarded to). A domain never
11
+ * admits its subdomains, and everything is compared case folded. An entry
12
+ * that is empty, or is no address and holds no dot, matches nothing.
13
+ */
6
14
  export function isAllowed(email, allowlist) {
7
15
  const wanted = email.trim().toLowerCase();
8
- if (!wanted)
16
+ // Only one plain address is ever admitted (one `@`, a local part, no
17
+ // whitespace or list and quoting characters), so a crafted string such as
18
+ // `a@evil.example,b@widget.example` can never ride a domain match into a send.
19
+ const plain = /^[^@\s,;<>()"\\]+@[^@\s,;<>()"\\]+$/.test(wanted);
20
+ if (!plain)
9
21
  return false;
22
+ const domain = wanted.slice(wanted.lastIndexOf("@") + 1);
10
23
  return (allowlist ?? "")
11
24
  .split(",")
12
25
  .map((entry) => entry.trim().toLowerCase())
13
- .includes(wanted);
26
+ .some((entry) => {
27
+ if (entry.length === 0)
28
+ return false;
29
+ const named = domainOf(entry);
30
+ return named === undefined ? entry === wanted : named === domain;
31
+ });
32
+ }
33
+ /**
34
+ * The domain a domain entry names, or undefined when the entry is a full
35
+ * address. A domain entry has to look like one (labels joined by dots), so a
36
+ * stray word or a bare `@` names a domain no address can be on.
37
+ */
38
+ function domainOf(entry) {
39
+ const bare = entry.startsWith("@") ? entry.slice(1) : entry;
40
+ if (bare.includes("@"))
41
+ return undefined;
42
+ return /^[^.\s@]+(\.[^.\s@]+)+$/.test(bare) ? bare : "";
14
43
  }
15
44
  /**
16
45
  * A setting that has to be a positive, finite number, or its default. A
@@ -8,7 +8,8 @@
8
8
  *
9
9
  * Env (set on the Vercel project):
10
10
  * - GATE_SESSION_SECRET signing secret; also the gate's on and off switch
11
- * - GATE_ALLOWLIST comma separated emails allowed to receive a link
11
+ * - GATE_ALLOWLIST comma separated entries allowed to receive a link: an address,
12
+ * or the business's domain (example.com or @example.com)
12
13
  * - RESEND_API_KEY sending only Resend key
13
14
  * - GATE_FROM sender display name (optional)
14
15
  * - GATE_SUBJECT email subject (optional)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atelic-action/ui",
3
- "version": "3.15.0",
3
+ "version": "3.17.0",
4
4
  "description": "Shared UI for the Atelic templates: site chrome, base styles, the component library, the access gate, and the app shell they install",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",
@@ -15,7 +15,7 @@ export interface WriteupPerson {
15
15
  /**
16
16
  * The sign off a printed artifact closes on: the script line, then the person
17
17
  * lockup, the photo beside the name, the role, and the address
18
- * (Brand/voice.md, Pitch Surfaces 9). The documents in @atelic-action/artifact
18
+ * (Brand/VOICE.md, Pitch Surfaces 9). The documents in @atelic-action/artifact
19
19
  * (the writeup, the read, the monthly page, the note) all wear it, so its
20
20
  * styles live in the base sheet chain
21
21
  * (styles/artifact.css); its container sets the type size and the color.
@@ -3,14 +3,42 @@
3
3
  * sign in functions and the middleware, so each reads a value the same way.
4
4
  */
5
5
 
6
- /** Whether an address is on the comma separated allowlist. */
6
+ /**
7
+ * Whether an address is on the comma separated allowlist. An entry is either
8
+ * a full address, which matches that address exactly, or the business's
9
+ * domain, written bare (`example.com`) or with a leading at (`@example.com`),
10
+ * which admits every address whose part after the `@` is that domain (the
11
+ * business's own people, whoever the page is forwarded to). A domain never
12
+ * admits its subdomains, and everything is compared case folded. An entry
13
+ * that is empty, or is no address and holds no dot, matches nothing.
14
+ */
7
15
  export function isAllowed(email: string, allowlist: string | undefined): boolean {
8
16
  const wanted = email.trim().toLowerCase();
9
- if (!wanted) return false;
17
+ // Only one plain address is ever admitted (one `@`, a local part, no
18
+ // whitespace or list and quoting characters), so a crafted string such as
19
+ // `a@evil.example,b@widget.example` can never ride a domain match into a send.
20
+ const plain = /^[^@\s,;<>()"\\]+@[^@\s,;<>()"\\]+$/.test(wanted);
21
+ if (!plain) return false;
22
+ const domain = wanted.slice(wanted.lastIndexOf("@") + 1);
10
23
  return (allowlist ?? "")
11
24
  .split(",")
12
25
  .map((entry) => entry.trim().toLowerCase())
13
- .includes(wanted);
26
+ .some((entry) => {
27
+ if (entry.length === 0) return false;
28
+ const named = domainOf(entry);
29
+ return named === undefined ? entry === wanted : named === domain;
30
+ });
31
+ }
32
+
33
+ /**
34
+ * The domain a domain entry names, or undefined when the entry is a full
35
+ * address. A domain entry has to look like one (labels joined by dots), so a
36
+ * stray word or a bare `@` names a domain no address can be on.
37
+ */
38
+ function domainOf(entry: string): string | undefined {
39
+ const bare = entry.startsWith("@") ? entry.slice(1) : entry;
40
+ if (bare.includes("@")) return undefined;
41
+ return /^[^.\s@]+(\.[^.\s@]+)+$/.test(bare) ? bare : "";
14
42
  }
15
43
 
16
44
  /**
@@ -8,7 +8,8 @@
8
8
  *
9
9
  * Env (set on the Vercel project):
10
10
  * - GATE_SESSION_SECRET signing secret; also the gate's on and off switch
11
- * - GATE_ALLOWLIST comma separated emails allowed to receive a link
11
+ * - GATE_ALLOWLIST comma separated entries allowed to receive a link: an address,
12
+ * or the business's domain (example.com or @example.com)
12
13
  * - RESEND_API_KEY sending only Resend key
13
14
  * - GATE_FROM sender display name (optional)
14
15
  * - GATE_SUBJECT email subject (optional)