Dough Git

commit

Flag Vercel previews that redirect to the login page

commit
56ea343d9b41d893a58ae7b4f179654187597013
author
Clove Twilight <[email protected]>
date
2026-11-18 06:01
Add a vercelLogin rule. It reads vercel.app links from the PR's website
preview section and follows redirects, only between Vercel hosts, to see
whether they land on vercel.com/login. Approving it requests changes
with the steps to turn off Vercel Authentication.

PRs with an open finding are now rechecked on any update, so the review
is dismissed once the preview loads, even without a new commit.

Co-Authored-By: Sandrone <[email protected]>

diff --git a/README.md b/README.md
index 01e5975..5414d6e 100644
--- a/README.md
+++ b/README.md
@@ -63,6 +63,14 @@ List hosts in `config/unsupportedCnames.jp` under `hosts`, for example
 `hosts: ["vercel.app", "example.com"]`. A CNAME matches an entry or any subdomain of it.
 Changes apply on the next scan. An empty list turns the rule off.
 
+## Vercel previews behind a login
+
+If the PR's website preview is a `vercel.app` link that redirects to `https://vercel.com/login`,
+the tracker flags it. Approving it requests changes with the steps to turn off Vercel
+Authentication. Redirects are only followed between Vercel's own hosts, and a link that cannot
+be reached is never flagged. A PR with an open finding is rechecked whenever it updates, so the
+review is dismissed once the preview loads, even without a new commit.
+
 ## Avatar
 
 `config/avatar.png` is the dashboard favicon and the Discord bot's avatar. Replace the file to
@@ -95,8 +103,9 @@ the other open violations on the same PR.
 1. Add a module in `src/lib/server/rules/` that exports a `Rule`.
 2. Register it in `src/lib/server/rules/index.ts`.
 3. Give it a `severity` from 1 (low) to 3 (high).
-4. A `requestChanges` rule needs a `findLine` and wording in `config/messages.jp`
-   (`reviewComment`, `reviewSummary` and `reviewDismissal`).
+4. A `requestChanges` rule needs wording in `config/messages.jp`
+   (`reviewComment`, `reviewSummary` and `reviewDismissal`). Give it a `findLine` to comment
+   inline; without one, the review body is `reviewComment` alone.
 5. If it needs a new kind of action, add an executor in `src/lib/server/moderation/executors.ts`.
 
 ## Checks
diff --git a/config/messages.jp b/config/messages.jp
index c388fad..48f7f8f 100644
--- a/config/messages.jp
+++ b/config/messages.jp
@@ -12,3 +12,8 @@ reviewSummary: "Please see the inline comment on `CNAME`.\n<sub>This comment was
 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."
 reviewSummary: "Please see the inline comment on `owner.email`.\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>"
+
+[vercelLogin]
+reviewComment: "Your website preview is not live: it redirects to the Vercel login page, so we cannot review it.\n\nTo make it public:\n\n1. Open your project dashboard on Vercel.\n2. Navigate to **Settings > Deployment Protection**.\n3. Toggle off **Vercel Authentication** (Require Login) and click **Save**.\n4. Test your link in an Incognito window to confirm it loads without a login prompt.\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>"
+reviewDismissal: "Thanks, your website preview now loads without a login. Dismissing the requested changes."
+reviewSummary: "Please see the comment on your website preview.\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>"
diff --git a/src/lib/labels.ts b/src/lib/labels.ts
index 073a156..5f0929f 100644
--- a/src/lib/labels.ts
+++ b/src/lib/labels.ts
@@ -7,7 +7,8 @@
 export const ruleLabels: Record<string, string> = {
 	nsRecords: 'NS records (first-time contributor)',
 	unsupportedCname: 'Unsupported CNAME target',
-	noReplyEmail: 'No-reply owner.email'
+	noReplyEmail: 'No-reply owner.email',
+	vercelLogin: 'Vercel preview behind a login'
 };
 
 export const severityLabels: Record<number, string> = {
diff --git a/src/lib/server/github/pullRequests.ts b/src/lib/server/github/pullRequests.ts
index a9bb2e8..ea1fcc3 100644
--- a/src/lib/server/github/pullRequests.ts
+++ b/src/lib/server/github/pullRequests.ts
@@ -16,6 +16,7 @@ interface ApiPullRequest {
 	author_association: string;
 	user: { login: string } | null;
 	head: { sha: string };
+	body: string | null;
 }
 
 export interface PullRequestFile {
@@ -49,7 +50,8 @@ function toSummary(pullRequest: ApiPullRequest): PullRequestSummary {
 		url: pullRequest.html_url,
 		state: pullRequest.state,
 		headSha: pullRequest.head.sha,
-		updatedAt: pullRequest.updated_at
+		updatedAt: pullRequest.updated_at,
+		body: pullRequest.body ?? ''
 	};
 }
 
diff --git a/src/lib/server/messages.ts b/src/lib/server/messages.ts
index 2dde0bb..4f92f52 100644
--- a/src/lib/server/messages.ts
+++ b/src/lib/server/messages.ts
@@ -24,6 +24,11 @@ export type ModerationMessages = {
 		reviewDismissal: string;
 		reviewSummary: string;
 	};
+	vercelLogin: {
+		reviewComment: string;
+		reviewDismissal: string;
+		reviewSummary: string;
+	};
 };
 
 // The committed file, read once, so a later bad edit still has wording to fall back on
@@ -56,6 +61,10 @@ export function getMessages(): ModerationMessages {
 			noReplyEmail: {
 				...defaultMessages.noReplyEmail,
 				...overrides.noReplyEmail
+			},
+			vercelLogin: {
+				...defaultMessages.vercelLogin,
+				...overrides.vercelLogin
 			}
 		};
 	} catch (error) {
diff --git a/src/lib/server/moderation/executors.ts b/src/lib/server/moderation/executors.ts
index 2d35c7c..cffb4f9 100644
--- a/src/lib/server/moderation/executors.ts
+++ b/src/lib/server/moderation/executors.ts
@@ -99,7 +99,9 @@ async function requestRuleChanges(input: ExecutorInput): Promise<ActionOutcome>
 	const line = file && findLine ? findLine(file) : null;
 	const canCommentInline = line !== null && getCommentableLines(file?.patch).has(line);
 
-	const fallbackBody = `${messages.reviewComment}\n\nFile: \`${finding.filePath}\`\n\n${marker}`;
+	// Rules without a line (like vercelLogin) are about the PR, not a file
+	const fileNote = findLine ? `\n\nFile: \`${finding.filePath}\`` : '';
+	const fallbackBody = `${messages.reviewComment}${fileNote}\n\n${marker}`;
 
 	if (canCommentInline) {
 		try {
diff --git a/src/lib/server/moderation/scanner.ts b/src/lib/server/moderation/scanner.ts
index 8c0db3d..9e4b26b 100644
--- a/src/lib/server/moderation/scanner.ts
+++ b/src/lib/server/moderation/scanner.ts
@@ -3,6 +3,7 @@
  */
 
 import { getConfig } from '../config.ts';
+import { listFindingsForPullRequest } from '../db/findings.ts';
 import { deleteValue, getValue, setValue } from '../db/keyValue.ts';
 import {
 	getPullRequestRow,
@@ -92,7 +93,12 @@ async function processPullRequest(pullRequest: PullRequestSummary): Promise<void
 	const alreadyScanned =
 		previous !== null && previous.state === 'open' && previous.scannedSha === pullRequest.headSha;
 
-	if (alreadyScanned) {
+	// A fix can land without a commit (an edited description, a Vercel setting), so flagged PRs are rechecked on any update
+	const hasOpenFindings = listFindingsForPullRequest(pullRequest.number).some(
+		(finding) => finding.status === 'pending' || finding.status === 'actioned'
+	);
+
+	if (alreadyScanned && !hasOpenFindings) {
 		return;
 	}
 
diff --git a/src/lib/server/rules/index.ts b/src/lib/server/rules/index.ts
index 052087b..6e1c7d7 100644
--- a/src/lib/server/rules/index.ts
+++ b/src/lib/server/rules/index.ts
@@ -7,9 +7,15 @@ import { noReplyEmailRule } from './noReplyEmail.ts';
 import { nsRecordsRule } from './nsRecords.ts';
 import type { Rule } from './types.ts';
 import { unsupportedCnameRule } from './unsupportedCname.ts';
+import { vercelLoginRule } from './vercelLogin.ts';
 
 // Add a new rule module here and the scanner, Discord and dashboard all pick it up
-export const rules: Rule[] = [nsRecordsRule, unsupportedCnameRule, noReplyEmailRule];
+export const rules: Rule[] = [
+	nsRecordsRule,
+	unsupportedCnameRule,
+	vercelLoginRule,
+	noReplyEmailRule
+];
 
 export function getRule(ruleId: RuleId): Rule {
 	const rule = rules.find((candidate) => candidate.id === ruleId);
diff --git a/src/lib/server/rules/rules.test.ts b/src/lib/server/rules/rules.test.ts
index 84017a9..3c39c18 100644
--- a/src/lib/server/rules/rules.test.ts
+++ b/src/lib/server/rules/rules.test.ts
@@ -9,6 +9,7 @@ import { getCommentableLines } from '../github/diff.ts';
 import { findNoReplyEmail, findOwnerEmailLine } from './noReplyEmail.ts';
 import { findNsRecords } from './nsRecords.ts';
 import { findCnameLine, findUnsupportedCname } from './unsupportedCname.ts';
+import { findVercelLinks, redirectsToVercelLogin } from './vercelLogin.ts';
 
 describe('findNsRecords', () => {
 	test('finds NS records under "records"', () => {
@@ -147,3 +148,74 @@ describe('review line placement', () => {
 		assert.equal(getCommentableLines(undefined).size, 0);
 	});
 });
+
+describe('findVercelLinks', () => {
+	const template = [
+		'<!-- This should be a LINK (e.g. https://abc.vercel.app, https://abc.github.io) -->',
+		'',
+		'<!-- WEBSITE_PREVIEW_START -->',
+		'https://my-site.vercel.app/',
+		'<!-- WEBSITE_PREVIEW_END -->',
+		'',
+		'Also see https://other.vercel.app'
+	].join('\n');
+
+	test('reads only the preview section, ignoring the example in comments', () => {
+		assert.deepEqual(findVercelLinks(template), ['https://my-site.vercel.app/']);
+	});
+
+	test('falls back to the whole body when the markers are gone', () => {
+		assert.deepEqual(findVercelLinks('Preview: https://a.vercel.app and https://b.github.io'), [
+			'https://a.vercel.app'
+		]);
+	});
+});
+
+describe('redirectsToVercelLogin', () => {
+	const realFetch = globalThis.fetch;
+
+	function fakeRedirects(locations: Record<string, string>): string[] {
+		const requested: string[] = [];
+
+		globalThis.fetch = (async (input: string | URL | Request) => {
+			const url = String(input);
+			const location = locations[url];
+
+			requested.push(url);
+
+			return new Response(null, {
+				status: location ? 302 : 200,
+				headers: location ? { location } : {}
+			});
+		}) as typeof fetch;
+
+		return requested;
+	}
+
+	test('follows the Vercel Authentication chain to the login page', async () => {
+		fakeRedirects({
+			'https://locked.vercel.app/': 'https://vercel.com/sso-api?url=x',
+			'https://vercel.com/sso-api?url=x': '/login?next=%2Fsso-api'
+		});
+
+		assert.equal(await redirectsToVercelLogin('https://locked.vercel.app/'), true);
+		globalThis.fetch = realFetch;
+	});
+
+	test('a public preview is not flagged', async () => {
+		fakeRedirects({});
+
+		assert.equal(await redirectsToVercelLogin('https://open.vercel.app/'), false);
+		globalThis.fetch = realFetch;
+	});
+
+	test('never follows a redirect off Vercel', async () => {
+		const requested = fakeRedirects({
+			'https://sneaky.vercel.app/': 'http://127.0.0.1:3101/login'
+		});
+
+		assert.equal(await redirectsToVercelLogin('https://sneaky.vercel.app/'), false);
+		assert.deepEqual(requested, ['https://sneaky.vercel.app/']);
+		globalThis.fetch = realFetch;
+	});
+});
diff --git a/src/lib/server/rules/vercelLogin.ts b/src/lib/server/rules/vercelLogin.ts
new file mode 100644
index 0000000..b0bce6d
--- /dev/null
+++ b/src/lib/server/rules/vercelLogin.ts
@@ -0,0 +1,88 @@
+/* src/lib/server/rules/vercelLogin.ts
+ * MIT — (c) Doughmination System®
+ */
+
+import { createLogger } from '../logger.ts';
+import type { Rule, Violation } from './types.ts';
+
+const logger = createLogger('vercelLogin');
+
+const previewSection =
+	/<!--\s*WEBSITE_PREVIEW_START\s*-->([\s\S]*?)<!--\s*WEBSITE_PREVIEW_END\s*-->/;
+const vercelLink = /https?:\/\/[a-z0-9.-]+\.vercel\.app[^\s<>()"'`,]*/gi;
+
+// Vercel Authentication hops vercel.app -> vercel.com/sso-api -> vercel.com/login
+const maxRedirects = 5;
+const timeoutMs = 10_000;
+
+// Vercel links in the template's preview section, or the whole body when the markers are gone
+export function findVercelLinks(body: string): string[] {
+	const withoutComments = (previewSection.exec(body)?.[1] ?? body).replace(/<!--[\s\S]*?-->/g, '');
+
+	return [...new Set(withoutComments.match(vercelLink) ?? [])];
+}
+
+function isVercelHost(url: URL): boolean {
+	return url.hostname === 'vercel.com' || url.hostname.endsWith('.vercel.app');
+}
+
+// Follows redirects by hand so a link can never send us off Vercel's own hosts
+export async function redirectsToVercelLogin(link: string): Promise<boolean> {
+	let url = new URL(link);
+
+	for (let hop = 0; hop <= maxRedirects; hop += 1) {
+		if (url.hostname === 'vercel.com' && url.pathname === '/login') {
+			return true;
+		}
+
+		if (url.protocol !== 'https:' || !isVercelHost(url)) {
+			return false;
+		}
+
+		const response = await fetch(url, {
+			redirect: 'manual',
+			signal: AbortSignal.timeout(timeoutMs)
+		});
+
+		await response.body?.cancel();
+
+		const location = response.headers.get('location');
+
+		if (response.status < 300 || response.status >= 400 || location === null) {
+			return false;
+		}
+
+		url = new URL(location, url);
+	}
+
+	return false;
+}
+
+export const vercelLoginRule: Rule = {
+	id: 'vercelLogin',
+	title: 'Vercel preview behind a login',
+	severity: 2,
+	actionType: 'requestChanges',
+	actionLabel: 'Request Changes',
+
+	async evaluate(context) {
+		const violations: Violation[] = [];
+
+		for (const link of findVercelLinks(context.pullRequest.body)) {
+			try {
+				if (await redirectsToVercelLogin(link)) {
+					violations.push({
+						ruleId: 'vercelLogin',
+						filePath: link,
+						reason: `The website preview (${link}) redirects to the Vercel login page.`
+					});
+				}
+			} catch (error) {
+				// Unreachable is not the same as protected; never flag on a network error
+				logger.warn(`Could not check ${link}`, error);
+			}
+		}
+
+		return violations;
+	}
+};
diff --git a/src/lib/server/types.ts b/src/lib/server/types.ts
index 39c3b96..0262b05 100644
--- a/src/lib/server/types.ts
+++ b/src/lib/server/types.ts
@@ -2,7 +2,7 @@
  * MIT — (c) Doughmination System®
  */
 
-export type RuleId = 'nsRecords' | 'unsupportedCname' | 'noReplyEmail';
+export type RuleId = 'nsRecords' | 'unsupportedCname' | 'noReplyEmail' | 'vercelLogin';
 
 export type ActionType = 'closePr' | 'requestChanges' | 'ignore';
 
@@ -21,9 +21,11 @@ export interface PullRequestSummary {
 	state: 'open' | 'closed';
 	headSha: string;
 	updatedAt: string;
+	// The PR description; not stored in the database
+	body: string;
 }
 
-export interface PullRequestRow extends PullRequestSummary {
+export interface PullRequestRow extends Omit<PullRequestSummary, 'body'> {
 	scannedSha: string | null;
 	scannedAt: string | null;
 }