feat: include google forms

This commit is contained in:
Ryan Di
2025-05-29 11:24:59 +10:00
parent 7cad3645a0
commit 022c407e24

View File

@@ -72,6 +72,8 @@ const ALLOWED_DOMAINS = new Set([
"giphy.com", "giphy.com",
"reddit.com", "reddit.com",
"forms.microsoft.com", "forms.microsoft.com",
"forms.gle",
"docs.google.com/forms",
]); ]);
const ALLOW_SAME_ORIGIN = new Set([ const ALLOW_SAME_ORIGIN = new Set([
@@ -86,6 +88,8 @@ const ALLOW_SAME_ORIGIN = new Set([
"stackblitz.com", "stackblitz.com",
"reddit.com", "reddit.com",
"forms.microsoft.com", "forms.microsoft.com",
"forms.gle",
"docs.google.com",
]); ]);
export const createSrcDoc = (body: string) => { export const createSrcDoc = (body: string) => {
@@ -335,15 +339,24 @@ const matchHostname = (
allowedHostnames: Set<string> | string, allowedHostnames: Set<string> | string,
): string | null => { ): string | null => {
try { try {
const { hostname } = new URL(url); const { hostname, pathname } = new URL(url);
const bareDomain = hostname.replace(/^www\./, ""); const bareDomain = hostname.replace(/^www\./, "");
if (allowedHostnames instanceof Set) { if (allowedHostnames instanceof Set) {
// Check for exact domain match
if (ALLOWED_DOMAINS.has(bareDomain)) { if (ALLOWED_DOMAINS.has(bareDomain)) {
return bareDomain; return bareDomain;
} }
// Check for path-based match (e.g., docs.google.com/forms)
const domainWithPath = `${bareDomain}${
pathname.split("/")[1] ? `/${pathname.split("/")[1]}` : ""
}`;
if (ALLOWED_DOMAINS.has(domainWithPath)) {
return domainWithPath;
}
const bareDomainWithFirstSubdomainWildcarded = bareDomain.replace( const bareDomainWithFirstSubdomainWildcarded = bareDomain.replace(
/^([^.]+)/, /^([^.]+)/,
"*", "*",
@@ -399,6 +412,7 @@ export const embeddableURLValidator = (
if (!url) { if (!url) {
return false; return false;
} }
if (validateEmbeddable != null) { if (validateEmbeddable != null) {
if (typeof validateEmbeddable === "function") { if (typeof validateEmbeddable === "function") {
const ret = validateEmbeddable(url); const ret = validateEmbeddable(url);