Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions apps/functions/dns-redirecting/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import * as functions from 'firebase-functions';

const isValidDomain = (domain: string): boolean => {
// Only allow alphanumeric characters, dots, and hyphens
return /^[a-zA-Z0-9.-]+$/.test(domain);
};
Comment thread
josephperrott marked this conversation as resolved.

export const dnsRedirecting = functions.https.onRequest(
{
cors: true,
Expand Down Expand Up @@ -30,6 +35,11 @@ export const dnsRedirecting = functions.https.onRequest(
}
}

if (!isValidDomain(hostname)) {
response.status(400).send('Invalid Hostname');
return;
}

if (hostname === 'code-of-conduct.angular.io') {
response.redirect(redirectType, 'https://code-of-conduct.angular.dev');
} else if (hostname === 'update.angular.dev') {
Expand Down
Loading