Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

relay: accept a trailing-dot DNS name in RELAY_PHONE_ORIGINS; build the default-policy test from loadConfig

Bugfixer 28916c5ec0dc3
diff --git a/relay/src/config.ts b/relay/src/config.ts
index 757926f4d8..d49d15fd12 100644
--- a/relay/src/config.ts
+++ b/relay/src/config.ts
@@ -91,8 +91,8 @@ const MIN_METRICS_TOKEN = 32;
const MAX_PHONE_ORIGINS = 8;
const PHONE_ORIGINS_RULE = `RELAY_PHONE_ORIGINS must list exact https:// origins, comma-separated, at most ${MAX_PHONE_ORIGINS}`;
-/** A DNS name or IPv4 address, or a bracketed IPv6 address, as the URL parser serializes them. */
-const HOSTNAME = /^([a-z0-9-]+(\.[a-z0-9-]+)*|\[[0-9a-f:]+\])$/;
+/** A DNS name (a final dot allowed, as browsers keep it) or IPv4 address, or a bracketed IPv6 address, as the URL parser serializes them. */
+const HOSTNAME = /^([a-z0-9-]+(\.[a-z0-9-]+)*\.?|\[[0-9a-f:]+\])$/;
/** Exactly what a browser sends as Origin: `https://host[:port]`, lower case, no default port, path or credentials. No wildcards. */
function isExactHttpsOrigin(value: string): boolean {
diff --git a/relay/test/origins.test.ts b/relay/test/origins.test.ts
index 878e242061..43868898fb 100644
--- a/relay/test/origins.test.ts
+++ b/relay/test/origins.test.ts
@@ -23,6 +23,12 @@ describe("RELAY_PHONE_ORIGINS", () => {
assert.deepEqual([...loadConfig({ ...base, RELAY_PHONE_ORIGINS: value }).phoneOrigins], value.split(","));
});
+ test("accepts a fully qualified name with a trailing dot as its own origin", () => {
+ const { phoneOrigins } = loadConfig({ ...base, RELAY_PHONE_ORIGINS: "https://app.example.com." });
+ assert.deepEqual([...phoneOrigins], ["https://app.example.com."]);
+ assert.equal(phoneOrigins.has(APP), false);
+ });
+
test("refuses anything that is not an exact https:// origin, and never repeats it", () => {
const bad = [
"http://app.example.com",
@@ -60,7 +66,7 @@ describe("RELAY_PHONE_ORIGINS", () => {
describe("a relay without RELAY_PHONE_ORIGINS", () => {
let relay: TestRelay;
before(async () => {
- relay = await startTestRelay();
+ relay = await startTestRelay({}, { phoneOrigins: [...loadConfig(base).phoneOrigins] });
});
after(() => relay.stop());