Public: anyone can read this; the crew can change it.

A domain's proof is asked of the authority every time #328

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

domains-authority-merge → main 1 commit

  • Merged. domains-authority-merge was merged into main as 450aebd.

Review

Sign in to review this change.
2 files changed +26 −3
src/apps/domains.ts +15 −3
@@ -112,15 +112,27 @@ export function withAuthority(
112112 primary: DomainResolver,
113113 authority: Authority,
114114 ): DomainResolver {
115 const authoritative = async (name: string): Promise<string[][]> => {
116 const servers = await nameserversFor(name, authority);
117 return authority.resolveTxtAt(servers, name);
118 };
115119 return {
116120 async resolveTxt(name) {
121 // A stale answer is as misleading as a stale "none": a record changed
122 // a minute ago still reads as its old value for as long as its TTL
123 // says. So the authority is asked either way, and both answers count.
124 let near: string[][] = [];
117125 try {
118 return await primary.resolveTxt(name);
126 near = await primary.resolveTxt(name);
119127 } catch (error) {
120128 if (!isNone(error)) throw error;
121 const servers = await nameserversFor(name, authority);
122 return authority.resolveTxtAt(servers, name);
123129 }
130 const far = await authoritative(name).catch((error: unknown) => {
131 if (near.length > 0 && isNone(error)) return [] as string[][];
132 throw error;
133 });
134 const seen = new Set(near.map((r) => r.join("")));
135 return [...near, ...far.filter((r) => !seen.has(r.join("")))];
124136 },
125137 resolveCname: (name) => primary.resolveCname(name),
126138 };
test/app-domains.test.ts +11
@@ -159,6 +159,17 @@ describe("checkDomain: every outcome is a sentence", () => {
159159 "a ns1.example.net",
160160 "[email protected] _forge-verify.app.example.com",
161161 ]);
162 // A stale value from the box's resolver does not hide the authority's.
163 const stale2 = withAuthority(
164 {
165 resolveTxt: () => Promise.resolve([["forge-verify=old-token-value"]]),
166 resolveCname: stale.resolveCname,
167 },
168 authority,
169 );
170 const fresh = await checkDomain("app.example.com", token, "notes.apps.test", stale2);
171 expect(fresh.verified).toBe(true);
172
162173 // And a resolver that says something other than "none" is believed.
163174 const broken = withAuthority(
164175 {

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs