commit
add unsupported tld tracking
diff --git a/.env.example b/.env.example
index c8b4b74..9365a90 100644
--- a/.env.example
+++ b/.env.example
@@ -37,5 +37,6 @@ SCANNER_ENABLED=true
DATABASE_PATH=data/tracker.sqlite
MESSAGES_PATH=config/messages.jp
UNSUPPORTED_CNAMES_PATH=config/unsupportedCnames.jp
+UNSUPPORTED_TLDS_PATH=config/unsupportedTlds.jp
NS_MIN_MERGED_PRS=1
MAX_FILES_PER_PR=25
diff --git a/README.md b/README.md
index 0f30492..92b8320 100644
--- a/README.md
+++ b/README.md
@@ -108,6 +108,23 @@ Changes apply on the next scan. An empty list turns the rule off. Approving a fi
a short unsupported-host explanation, adds `status: denied` and `reason: incompatible records`,
and closes the PR instead of requesting changes.
+## Edits to existing registrations
+
+Edits and renames are flagged when the PR author's GitHub login differs from the
+`owner.username` in the submitted file. The comparison ignores case. A moderator
+can request confirmation from the listed owner or ignore the finding.
+
+## CNAME URLs and unsupported TLDs
+
+A `CNAME` containing an HTTP or HTTPS URL gets a Request Changes finding.
+Put the hostname in the `CNAME` field, or use a `URL` record for a redirect where supported.
+
+Edit `config/unsupportedTlds.jp` to manage the `tlds` list for both `CNAME` and `URL`
+records. The rule checks the final label of the target hostname. For example,
+`.tk` matches `site.tk` and `https://site.tk/path`. Changes apply on the next scan.
+Approving a blocked `CNAME` finding denies and closes the PR. Approving a blocked
+`URL` finding requests changes.
+
## Vercel previews behind a login
If the PR's website preview is a `vercel.app` link that redirects to `https://vercel.com/login`,
diff --git a/config/messages.jp b/config/messages.jp
index 6596c1f..bf9ef45 100644
--- a/config/messages.jp
+++ b/config/messages.jp
@@ -12,6 +12,21 @@ reviewComment: "Your `CNAME` record points at a host that we do not support. Ple
reviewDismissal: "Thanks, the `CNAME` record is fixed. Dismissing the requested changes."
reviewSummary: "Please see the inline comment on `CNAME`.\n<sub>This comment was sent with an [automated tool](https://doughmination.gay/automated), and approved by a human. I do not see replies.</sub>"
+[cnameUrl]
+reviewComment: "Your `CNAME` record must contain a hostname only, such as `example.com`. Remove the HTTP or HTTPS scheme and any path, port, query string or fragment. If you want to redirect to a web address, use a `URL` record where supported."
+reviewDismissal: "Thanks for fixing the CNAME value. Dismissing the requested changes."
+reviewSummary: "Please see the comment on your CNAME record."
+
+[unsupportedUrlTld]
+reviewComment: "Your `URL` record points to an unsupported top-level domain. Please use a URL on a supported domain."
+reviewDismissal: "Thanks for updating the URL target. Dismissing the requested changes."
+reviewSummary: "Please see the comment on your URL record."
+
+[ownerUsernameMismatch]
+reviewComment: "The GitHub account that opened this pull request differs from the `owner.username` listed in this registration. Please fix this, as we don't allow orgs to register domains, or people on behalf of others."
+reviewDismissal: "The PR author now matches the listed registration owner. Dismissing the requested changes."
+reviewSummary: "Please see the comment on the registration owner."
+
[noReplyEmail]
reviewComment: "Your `owner.email` value is a GitHub no-reply email address. We do not allow these on our service. Please update it to a personal email address or remove the `owner.email` field entirely, as it is optional."
reviewDismissal: "Thanks, `owner.email` is fixed. Dismissing the requested changes."
diff --git a/config/unsupportedCnames.jp b/config/unsupportedCnames.jp
index 46324f9..9392d46 100644
--- a/config/unsupportedCnames.jp
+++ b/config/unsupportedCnames.jp
@@ -2,20 +2,10 @@
~~ A CNAME matches an entry or any subdomain of it
hosts: [
- ".adult",
".blob.core.windows.net",
- ".cf",
".cfargotunnel.com",
- ".ga",
- ".gq",
- ".ml",
- ".porn",
".r2.dev",
- ".sex",
- ".sexy",
".trycloudflare.com",
- ".tk",
".workers.dev",
- ".xxx",
".ts.net"
]
diff --git a/config/unsupportedTlds.jp b/config/unsupportedTlds.jp
new file mode 100644
index 0000000..a56bb6c
--- /dev/null
+++ b/config/unsupportedTlds.jp
@@ -0,0 +1,15 @@
+~~ config/unsupportedTlds.jp
+~~ Applies to the final hostname label of CNAME and URL targets
+
+tlds: [
+ ".adult",
+ ".cf",
+ ".ga",
+ ".gq",
+ ".ml",
+ ".porn",
+ ".sex",
+ ".sexy",
+ ".tk",
+ ".xxx"
+]
diff --git a/src/lib/labels.ts b/src/lib/labels.ts
index ca606cb..39c1156 100644
--- a/src/lib/labels.ts
+++ b/src/lib/labels.ts
@@ -7,6 +7,9 @@
export const ruleLabels: Record<string, string> = {
nsRecords: 'NS records (first-time contributor)',
unsupportedCname: 'Unsupported CNAME target',
+ cnameUrl: 'HTTP or HTTPS URL in CNAME',
+ unsupportedUrlTld: 'Unsupported URL target TLD',
+ ownerUsernameMismatch: 'PR author differs from registration owner',
noReplyEmail: 'No-reply owner.email',
vercelLogin: 'Vercel preview behind a login',
vercelFileName: 'Misnamed _vercel file',
diff --git a/src/lib/server/config.ts b/src/lib/server/config.ts
index a2f386a..cc2493d 100644
--- a/src/lib/server/config.ts
+++ b/src/lib/server/config.ts
@@ -13,6 +13,7 @@ export interface AppConfig {
databasePath: string;
messagesPath: string;
unsupportedCnamesPath: string;
+ unsupportedTldsPath: string;
avatarPath: string;
pollIntervalSeconds: number;
scannerEnabled: boolean;
@@ -67,6 +68,7 @@ export function getConfig(): AppConfig {
databasePath: readText('DATABASE_PATH', 'data/tracker.sqlite'),
messagesPath: readText('MESSAGES_PATH', 'config/messages.jp'),
unsupportedCnamesPath: readText('UNSUPPORTED_CNAMES_PATH', 'config/unsupportedCnames.jp'),
+ unsupportedTldsPath: readText('UNSUPPORTED_TLDS_PATH', 'config/unsupportedTlds.jp'),
avatarPath: readText('AVATAR_PATH', 'config/avatar.png'),
pollIntervalSeconds: Math.max(30, readNumber('POLL_INTERVAL_SECONDS', 120)),
scannerEnabled: readFlag('SCANNER_ENABLED', true),
diff --git a/src/lib/server/messages.ts b/src/lib/server/messages.ts
index 5e16417..2801307 100644
--- a/src/lib/server/messages.ts
+++ b/src/lib/server/messages.ts
@@ -25,6 +25,9 @@ export type ModerationMessages = {
reviewSummary: string;
};
unsupportedCname: ReviewMessages & { closeComment: string };
+ cnameUrl: ReviewMessages;
+ unsupportedUrlTld: ReviewMessages;
+ ownerUsernameMismatch: ReviewMessages;
noReplyEmail: ReviewMessages;
vercelLogin: ReviewMessages;
vercelFileName: ReviewMessages;
diff --git a/src/lib/server/rules/cnameUrl.ts b/src/lib/server/rules/cnameUrl.ts
new file mode 100644
index 0000000..e05281a
--- /dev/null
+++ b/src/lib/server/rules/cnameUrl.ts
@@ -0,0 +1,35 @@
+/* src/lib/server/rules/cnameUrl.ts
+ * MIT — (c) Doughmination System®
+ */
+
+import { httpUrlPrefix, readRecordTarget } from './recordTargets.ts';
+import type { Rule, Violation } from './types.ts';
+import { findCnameLine } from './unsupportedCname.ts';
+
+export const cnameUrlRule: Rule = {
+ id: 'cnameUrl',
+ title: 'HTTP or HTTPS URL in CNAME',
+ severity: 2,
+ actionType: 'requestChanges',
+ actionLabel: 'Request Changes',
+
+ findLine: (file) => findCnameLine(file.content),
+
+ async evaluate(context) {
+ const violations: Violation[] = [];
+
+ for (const file of context.files) {
+ const target = readRecordTarget(file.json, 'CNAME');
+
+ if (target !== null && httpUrlPrefix.test(target)) {
+ violations.push({
+ ruleId: 'cnameUrl',
+ filePath: file.path,
+ reason: 'CNAME contains an HTTP or HTTPS URL. Use a hostname.'
+ });
+ }
+ }
+
+ return violations;
+ }
+};
diff --git a/src/lib/server/rules/index.ts b/src/lib/server/rules/index.ts
index 317d8ef..7169efd 100644
--- a/src/lib/server/rules/index.ts
+++ b/src/lib/server/rules/index.ts
@@ -3,10 +3,13 @@
*/
import type { RuleId } from '../types.ts';
+import { cnameUrlRule } from './cnameUrl.ts';
import { noReplyEmailRule } from './noReplyEmail.ts';
import { nsRecordsRule } from './nsRecords.ts';
+import { ownerUsernameMismatchRule } from './ownerUsernameMismatch.ts';
import type { Rule } from './types.ts';
import { unsupportedCnameRule } from './unsupportedCname.ts';
+import { unsupportedUrlTldRule } from './unsupportedTlds.ts';
import { vercelLoginRule } from './vercelLogin.ts';
import { vercelFileNameRule, vercelTxtRecordRule } from './vercelVerification.ts';
@@ -14,7 +17,10 @@ import { vercelFileNameRule, vercelTxtRecordRule } from './vercelVerification.ts
export const rules: Rule[] = [
nsRecordsRule,
unsupportedCnameRule,
+ cnameUrlRule,
+ unsupportedUrlTldRule,
vercelLoginRule,
+ ownerUsernameMismatchRule,
noReplyEmailRule,
vercelFileNameRule,
vercelTxtRecordRule
diff --git a/src/lib/server/rules/ownerUsernameMismatch.ts b/src/lib/server/rules/ownerUsernameMismatch.ts
new file mode 100644
index 0000000..cc884ee
--- /dev/null
+++ b/src/lib/server/rules/ownerUsernameMismatch.ts
@@ -0,0 +1,55 @@
+/* src/lib/server/rules/ownerUsernameMismatch.ts
+ * MIT — (c) Doughmination System®
+ */
+
+import type { Rule, Violation } from './types.ts';
+import { isPlainObject } from './types.ts';
+
+function readOwnerUsername(json: unknown): string | null {
+ if (!isPlainObject(json) || !isPlainObject(json.owner)) {
+ return null;
+ }
+
+ const username = json.owner.username;
+
+ return typeof username === 'string' && username.trim() !== '' ? username.trim() : null;
+}
+
+export const ownerUsernameMismatchRule: Rule = {
+ id: 'ownerUsernameMismatch',
+ title: 'PR author differs from the registration owner',
+ severity: 2,
+ actionType: 'requestChanges',
+ actionLabel: 'Request Changes',
+
+ findLine(file) {
+ const lineIndex = file.content.split('\n').findIndex((line) => /"username"\s*:/.test(line));
+
+ return lineIndex === -1 ? null : lineIndex + 1;
+ },
+
+ async evaluate(context) {
+ const author = context.pullRequest.author;
+ const violations: Violation[] = [];
+
+ for (const file of context.files) {
+ if (file.status !== 'modified' && file.status !== 'renamed') {
+ continue;
+ }
+
+ const ownerUsername = readOwnerUsername(file.json);
+
+ if (ownerUsername === null || ownerUsername.toLowerCase() === author.toLowerCase()) {
+ continue;
+ }
+
+ violations.push({
+ ruleId: 'ownerUsernameMismatch',
+ filePath: file.path,
+ reason: `PR author (${author}) differs from owner.username (${ownerUsername}).`
+ });
+ }
+
+ return violations;
+ }
+};
diff --git a/src/lib/server/rules/recordTargets.ts b/src/lib/server/rules/recordTargets.ts
new file mode 100644
index 0000000..2dd0549
--- /dev/null
+++ b/src/lib/server/rules/recordTargets.ts
@@ -0,0 +1,36 @@
+/* src/lib/server/rules/recordTargets.ts
+ * MIT — (c) Doughmination System®
+ */
+
+import { isPlainObject } from './types.ts';
+
+export const httpUrlPrefix = /^https?:\/\//i;
+
+export function readRecordTarget(json: unknown, recordType: 'CNAME' | 'URL'): string | null {
+ if (!isPlainObject(json)) {
+ return null;
+ }
+
+ const records = json.records ?? json.record;
+
+ if (!isPlainObject(records)) {
+ return null;
+ }
+
+ const key = Object.keys(records).find((name) => name.trim().toUpperCase() === recordType);
+ const value = key === undefined ? undefined : records[key];
+
+ return typeof value === 'string' ? value.trim() : null;
+}
+
+export function readHttpHostname(target: string): string | null {
+ if (!httpUrlPrefix.test(target)) {
+ return null;
+ }
+
+ try {
+ return new URL(target).hostname;
+ } catch {
+ return null;
+ }
+}
diff --git a/src/lib/server/rules/rules.test.ts b/src/lib/server/rules/rules.test.ts
index 69d9aa6..4979c15 100644
--- a/src/lib/server/rules/rules.test.ts
+++ b/src/lib/server/rules/rules.test.ts
@@ -6,9 +6,12 @@ import assert from 'node:assert/strict';
import { describe, test } from 'node:test';
import { getCommentableLines } from '../github/diff.ts';
+import { cnameUrlRule } from './cnameUrl.ts';
import { findNoReplyEmail, findOwnerEmailLine } from './noReplyEmail.ts';
import { findNsRecords } from './nsRecords.ts';
+import { ownerUsernameMismatchRule } from './ownerUsernameMismatch.ts';
import { findCnameLine, findUnsupportedCname } from './unsupportedCname.ts';
+import { unsupportedUrlTldRule } from './unsupportedTlds.ts';
import { findVercelLinks, redirectsToVercelLogin } from './vercelLogin.ts';
import {
findVercelTxt,
@@ -313,3 +316,106 @@ describe('Vercel verification records', () => {
assert.ok(violations[0].reason.includes('domains/_vercel.alice.json'));
});
});
+
+describe('CNAME URLs and unsupported TLDs', () => {
+ test('flags both web schemes in CNAME values, including malformed URLs', async () => {
+ const violations = await cnameUrlRule.evaluate(
+ contextFor('free-domains/is-a.bot', [
+ {
+ path: 'domains/http.json',
+ json: { records: { CNAME: 'http://example.com/path' } }
+ },
+ {
+ path: 'domains/https.json',
+ json: { record: { cname: ' HTTPS:// ' } }
+ },
+ {
+ path: 'domains/hostname.json',
+ json: { records: { CNAME: 'example.com' } }
+ }
+ ])
+ );
+
+ assert.deepEqual(
+ violations.map((violation) => violation.filePath),
+ ['domains/http.json', 'domains/https.json']
+ );
+ });
+
+ test('uses the final hostname label for both record types', async () => {
+ const tlds = new Set(['tk']);
+
+ assert.equal(
+ findUnsupportedCname({ records: { CNAME: 'Me.Example.TK.' } }, [], tlds),
+ 'Me.Example.TK.'
+ );
+ assert.equal(
+ findUnsupportedCname({ records: { CNAME: 'site.tk.example.com' } }, [], tlds),
+ null
+ );
+
+ const violations = await unsupportedUrlTldRule.evaluate(
+ contextFor('is-a-dev/register', [
+ {
+ path: 'domains/blocked.json',
+ json: { record: { url: 'https://site.TK.:443/path' } }
+ },
+ {
+ path: 'domains/allowed.json',
+ json: { records: { URL: 'https://[email protected]/path.tk?target=site.tk' } }
+ },
+ {
+ path: 'domains/malformed.json',
+ json: { records: { URL: 'https://' } }
+ }
+ ])
+ );
+
+ assert.equal(violations.length, 1);
+ assert.equal(violations[0].filePath, 'domains/blocked.json');
+ assert.equal(violations[0].ruleId, 'unsupportedUrlTld');
+ });
+});
+
+describe('registration owner mismatch', () => {
+ test('flags edits and renames with another owner', async () => {
+ const anotherOwner = {
+ owner: { username: 'alice' }
+ };
+ const context = contextFor('is-a-dev/register', [
+ {
+ path: 'domains/edited.json',
+ status: 'modified',
+ json: anotherOwner
+ },
+ {
+ path: 'domains/renamed.json',
+ status: 'renamed',
+ json: anotherOwner
+ },
+ {
+ path: 'domains/new.json',
+ json: anotherOwner
+ },
+ {
+ path: 'domains/own.json',
+ status: 'modified',
+ json: { owner: { username: ' CLove ' } }
+ },
+ {
+ path: 'domains/no-owner.json',
+ status: 'modified',
+ json: { owner: {} }
+ }
+ ]);
+ context.pullRequest.author = 'clove';
+
+ const violations = await ownerUsernameMismatchRule.evaluate(context);
+
+ assert.deepEqual(
+ violations.map((violation) => violation.filePath),
+ ['domains/edited.json', 'domains/renamed.json']
+ );
+ assert.ok(violations.every((violation) => violation.reason.includes('alice')));
+ });
+});
diff --git a/src/lib/server/rules/unsupportedCname.ts b/src/lib/server/rules/unsupportedCname.ts
index 8eda08d..7a848fd 100644
--- a/src/lib/server/rules/unsupportedCname.ts
+++ b/src/lib/server/rules/unsupportedCname.ts
@@ -8,7 +8,8 @@ import { loads } from 'jpcl-lang';
import { getConfig } from '../config.ts';
import { createLogger } from '../logger.ts';
import type { DomainFile, Rule, Violation } from './types.ts';
-import { isPlainObject } from './types.ts';
+import { httpUrlPrefix, readHttpHostname, readRecordTarget } from './recordTargets.ts';
+import { getUnsupportedTlds, hasUnsupportedTld } from './unsupportedTlds.ts';
const logger = createLogger('unsupportedCname');
@@ -42,23 +43,23 @@ export function getUnsupportedCnames(): string[] {
}
// An entry matches itself and every subdomain under it
-export function findUnsupportedCname(json: unknown, unsupportedHosts: string[]): string | null {
- if (!isPlainObject(json)) {
+export function findUnsupportedCname(
+ json: unknown,
+ unsupportedHosts: string[],
+ unsupportedTlds: ReadonlySet<string> = new Set()
+): string | null {
+ const target = readRecordTarget(json, 'CNAME');
+
+ if (target === null) {
return null;
}
- // Older registrations use "record"; current ones use "records"
- const records = json.records ?? json.record;
+ if (httpUrlPrefix.test(target)) {
+ const hostname = readHttpHostname(target);
- if (!isPlainObject(records)) {
- return null;
- }
-
- const cnameKey = Object.keys(records).find((key) => key.trim().toUpperCase() === 'CNAME');
- const target = cnameKey === undefined ? undefined : records[cnameKey];
-
- if (typeof target !== 'string') {
- return null;
+ return hostname !== null && hasUnsupportedTld(hostname, unsupportedTlds)
+ ? hostname
+ : null;
}
const host = normaliseHost(target);
@@ -67,12 +68,12 @@ export function findUnsupportedCname(json: unknown, unsupportedHosts: string[]):
.map(normaliseHost)
.some((unsupported) => host === unsupported || host.endsWith(`.${unsupported}`));
- return blocked ? target.trim() : null;
+ return blocked || hasUnsupportedTld(host, unsupportedTlds) ? target : null;
}
// 1-based line of the CNAME entry, or null when it cannot be pinned down
export function findCnameLine(content: string): number | null {
- const lineIndex = content.split('\n').findIndex((line) => /"cname"\s*:/i.test(line));
+ const lineIndex = content.split('\n').findIndex((line) => /"\s*cname\s*"\s*:/i.test(line));
return lineIndex === -1 ? null : lineIndex + 1;
}
@@ -88,14 +89,15 @@ export const unsupportedCnameRule: Rule = {
async evaluate(context) {
const unsupportedHosts = getUnsupportedCnames();
+ const unsupportedTlds = getUnsupportedTlds();
const violations: Violation[] = [];
- if (unsupportedHosts.length === 0) {
+ if (unsupportedHosts.length === 0 && unsupportedTlds.size === 0) {
return violations;
}
for (const file of context.files) {
- const target = findUnsupportedCname(file.json, unsupportedHosts);
+ const target = findUnsupportedCname(file.json, unsupportedHosts, unsupportedTlds);
if (target === null) {
continue;
diff --git a/src/lib/server/rules/unsupportedTlds.ts b/src/lib/server/rules/unsupportedTlds.ts
new file mode 100644
index 0000000..ceb7bb3
--- /dev/null
+++ b/src/lib/server/rules/unsupportedTlds.ts
@@ -0,0 +1,83 @@
+/* src/lib/server/rules/unsupportedTlds.ts
+ * MIT — (c) Doughmination System®
+ */
+
+import { readFileSync } from 'node:fs';
+import { loads } from 'jpcl-lang';
+
+import { getConfig } from '../config.ts';
+import { createLogger } from '../logger.ts';
+import { readHttpHostname, readRecordTarget } from './recordTargets.ts';
+import type { Rule, Violation } from './types.ts';
+
+const logger = createLogger('unsupportedTlds');
+
+export function getUnsupportedTlds(): Set<string> {
+ try {
+ const file = loads(readFileSync(getConfig().unsupportedTldsPath, 'utf8'));
+ const list: unknown = file.tlds;
+
+ if (!Array.isArray(list)) {
+ throw new Error('expected a "tlds" array of top-level domains');
+ }
+
+ const tlds = new Set<string>();
+
+ for (const entry of list) {
+ if (typeof entry === 'string') {
+ const tld = entry.trim().toLowerCase().replace(/^\./, '');
+
+ if (/^[a-z0-9-]+$/.test(tld)) {
+ tlds.add(tld);
+ }
+ }
+ }
+
+ return tlds;
+ } catch (error) {
+ logger.warn('Could not read the unsupported TLD list', error);
+
+ return new Set();
+ }
+}
+
+export function hasUnsupportedTld(hostname: string, tlds: ReadonlySet<string>): boolean {
+ const host = hostname.toLowerCase().replace(/\.$/, '');
+ const lastDot = host.lastIndexOf('.');
+
+ return tlds.has(host.slice(lastDot + 1));
+}
+
+export const unsupportedUrlTldRule: Rule = {
+ id: 'unsupportedUrlTld',
+ title: 'URL target has an unsupported TLD',
+ severity: 2,
+ actionType: 'requestChanges',
+ actionLabel: 'Request Changes',
+
+ findLine(file) {
+ const lineIndex = file.content.split('\n').findIndex((line) => /"\s*url\s*"\s*:/i.test(line));
+
+ return lineIndex === -1 ? null : lineIndex + 1;
+ },
+
+ async evaluate(context) {
+ const tlds = getUnsupportedTlds();
+ const violations: Violation[] = [];
+
+ for (const file of context.files) {
+ const target = readRecordTarget(file.json, 'URL');
+ const hostname = target === null ? null : readHttpHostname(target);
+
+ if (hostname !== null && hasUnsupportedTld(hostname, tlds)) {
+ violations.push({
+ ruleId: 'unsupportedUrlTld',
+ filePath: file.path,
+ reason: `URL points at a host with an unsupported TLD (${hostname}).`
+ });
+ }
+ }
+
+ return violations;
+ }
+};
diff --git a/src/lib/server/types.ts b/src/lib/server/types.ts
index c51df52..a1cb6a4 100644
--- a/src/lib/server/types.ts
+++ b/src/lib/server/types.ts
@@ -5,6 +5,9 @@
export type RuleId =
| 'nsRecords'
| 'unsupportedCname'
+ | 'cnameUrl'
+ | 'unsupportedUrlTld'
+ | 'ownerUsernameMismatch'
| 'noReplyEmail'
| 'vercelLogin'
| 'vercelFileName'