Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
improvements: address feedack
Scott Wilsona27d27852430
diff --git a/backend/scripts/bake-announcements.ts b/backend/scripts/bake-announcements.tsindex 96f01fd0db..ed3936f084 100644--- a/backend/scripts/bake-announcements.ts+++ b/backend/scripts/bake-announcements.ts@@ -24,6 +24,22 @@ const OUT_DIR = path.resolve(process.cwd(), "dist", "announcement-assets");const IMAGE_DIR = path.join(OUT_DIR, "images");const JSON_PATH = path.join(OUT_DIR, "announcements.json");+// SVG is intentionally excluded — same-origin SVG can carry inline <script> and+// would execute in the app origin if a user navigates to the asset URL directly.+const ALLOWED_IMAGE_EXTS = new Set([".png", ".jpg", ".jpeg", ".webp", ".gif"]);+const ALLOWED_IMAGE_MIMES = new Set(["image/png", "image/jpeg", "image/webp", "image/gif"]);+const ALLOWED_LINK_PROTOCOLS = new Set(["http:", "https:"]);++const sanitizeLink = (link: string | null | undefined): string | null => {+ if (!link) return null;+ try {+ const { protocol } = new URL(link);+ return ALLOWED_LINK_PROTOCOLS.has(protocol) ? link : null;+ } catch {+ return null;+ }+};+type ContentfulAsset = {sys: { id: string };fields: { file?: { url?: string; contentType?: string } };@@ -46,7 +62,20 @@ type ContentfulResponse = {includes?: { Asset?: ContentfulAsset[] };};-async function downloadAsset(url: string, assetId: string): Promise<{ filename: string; bytes: number } | null> {+async function downloadAsset(+ url: string,+ assetId: string,+ contentType: string | undefined+): Promise<{ filename: string; bytes: number } | null> {+ const ext = path.extname(new URL(url).pathname).toLowerCase();+ if (!ALLOWED_IMAGE_EXTS.has(ext)) {+ console.warn(`[bake-announcements] skipping ${url}: extension ${ext || "(none)"} not allowed`);+ return null;+ }+ if (contentType && !ALLOWED_IMAGE_MIMES.has(contentType.toLowerCase())) {+ console.warn(`[bake-announcements] skipping ${url}: content-type ${contentType} not allowed`);+ return null;+ }const res = await fetch(url);if (!res.ok) {console.warn(`[bake-announcements] failed to download ${url}: ${res.status}`);@@ -54,11 +83,6 @@ async function downloadAsset(url: string, assetId: string): Promise<{ filename:}const buf = Buffer.from(await res.arrayBuffer());const hash = crypto.createHash("sha256").update(buf).digest("hex").slice(0, 16);- const ext = path.extname(new URL(url).pathname).toLowerCase();- if (!ext) {- console.warn(`[bake-announcements] skipping ${url}: no file extension`);- return null;- }const filename = `${hash}${ext}`;await fs.writeFile(path.join(IMAGE_DIR, filename), buf);console.log(`[bake-announcements] asset ${assetId} -> ${filename} (${buf.length} bytes)`);@@ -88,17 +112,20 @@ async function main() {await fs.mkdir(IMAGE_DIR, { recursive: true });- const assetMap = new Map<string, string>(); // assetId -> remote URL+ const assetMap = new Map<string, { url: string; contentType: string | undefined }>();for (const asset of data.includes?.Asset ?? []) {const remoteUrl = asset.fields?.file?.url;if (!remoteUrl) continue;- assetMap.set(asset.sys.id, remoteUrl.startsWith("//") ? `https:${remoteUrl}` : remoteUrl);+ assetMap.set(asset.sys.id, {+ url: remoteUrl.startsWith("//") ? `https:${remoteUrl}` : remoteUrl,+ contentType: asset.fields?.file?.contentType+ });}const downloaded = new Map<string, string>(); // assetId -> local filenameawait Promise.all(- Array.from(assetMap, async ([assetId, remoteUrl]) => {- const result = await downloadAsset(remoteUrl, assetId);+ Array.from(assetMap, async ([assetId, { url: remoteUrl, contentType }]) => {+ const result = await downloadAsset(remoteUrl, assetId, contentType);if (result) downloaded.set(assetId, result.filename);}));@@ -113,7 +140,7 @@ async function main() {title: entry.fields.title,body: entry.fields.body,imageUrl: filename ? `/api/v1/announcement/assets/${filename}` : null,- link: entry.fields.link ?? null,+ link: sanitizeLink(entry.fields.link),linkLabel: entry.fields.linkLabel ?? null,published: entry.fields.published}diff --git a/backend/src/server/routes/v1/announcement-router.ts b/backend/src/server/routes/v1/announcement-router.tsindex 00ac98cfc3..b576835467 100644--- a/backend/src/server/routes/v1/announcement-router.ts+++ b/backend/src/server/routes/v1/announcement-router.ts@@ -26,8 +26,7 @@ const MIME_BY_EXT: Record<string, string> = {".jpg": "image/jpeg",".jpeg": "image/jpeg",".webp": "image/webp",- ".gif": "image/gif",- ".svg": "image/svg+xml"+ ".gif": "image/gif"};export const registerAnnouncementRouter = async (server: FastifyZodProvider) => {@@ -116,6 +115,7 @@ export const registerAnnouncementRouter = async (server: FastifyZodProvider) =>return reply.type(MIME_BY_EXT[ext] ?? "application/octet-stream").header("cache-control", "public, max-age=31536000, immutable")+ .header("x-content-type-options", "nosniff").send(createReadStream(filePath));}});diff --git a/backend/src/services/announcement/announcement-service.ts b/backend/src/services/announcement/announcement-service.tsindex 3484b6a157..1e82bc8db5 100644--- a/backend/src/services/announcement/announcement-service.ts+++ b/backend/src/services/announcement/announcement-service.ts@@ -28,6 +28,20 @@ export const BUNDLED_DIR = path.resolve(process.cwd(), "dist", "announcement-assexport const BUNDLED_JSON_PATH = path.join(BUNDLED_DIR, "announcements.json");export const BUNDLED_IMAGE_DIR = path.join(BUNDLED_DIR, "images");+// Strip any `link` field that isn't an http(s)/mailto URL so a malicious or+// misconfigured Contentful entry can't deliver a `javascript:` href to the+// rendered <a> in the announcement modal.+const ALLOWED_LINK_PROTOCOLS = new Set(["http:", "https:"]);+const sanitizeLink = (link: string | null | undefined): string | null => {+ if (!link) return null;+ try {+ const { protocol } = new URL(link);+ return ALLOWED_LINK_PROTOCOLS.has(protocol) ? link : null;+ } catch {+ return null;+ }+};+type TAnnouncementServiceFactoryDep = {userDAL: Pick<TUserDALFactory, "findById" | "updateById">;keyStore: Pick<TKeyStoreFactory, "getItem" | "setItemWithExpiry">;@@ -50,10 +64,13 @@ export const announcementServiceFactory = ({ userDAL, keyStore }: TAnnouncementStry {const raw = await fs.readFile(BUNDLED_JSON_PATH, "utf8");const parsed = JSON.parse(raw) as TAnnouncement[];+ // Re-sanitize at load time so an older self-hosted bundle (baked before+ // the bake-time link allowlist was added) can't carry an unsafe href.+ const sanitized = parsed.map((a) => ({ ...a, link: sanitizeLink(a.link) }));logger.info(- `Loaded ${parsed.length} bundled announcement(s) from ${BUNDLED_JSON_PATH} — Contentful fetches disabled`+ `Loaded ${sanitized.length} bundled announcement(s) from ${BUNDLED_JSON_PATH} — Contentful fetches disabled`);- return parsed;+ return sanitized;} catch (err) {const { code } = err as NodeJS.ErrnoException;if (code !== "ENOENT") {@@ -110,7 +127,7 @@ export const announcementServiceFactory = ({ userDAL, keyStore }: TAnnouncementStitle: entry.fields.title,body: entry.fields.body,imageUrl,- link: entry.fields.link ?? null,+ link: sanitizeLink(entry.fields.link),linkLabel: entry.fields.linkLabel ?? null,published: entry.fields.published}diff --git a/frontend/src/components/announcements/AnnouncementModal.tsx b/frontend/src/components/announcements/AnnouncementModal.tsxindex 9d22c4ee8b..bde2e0028a 100644--- a/frontend/src/components/announcements/AnnouncementModal.tsx+++ b/frontend/src/components/announcements/AnnouncementModal.tsx@@ -29,6 +29,19 @@ const formatPublished = (iso: string) => {return Number.isNaN(date.getTime()) ? null : dateFormatter.format(date);};+// Belt to the server-side allowlist: refuse anything that isn't an http(s) URL+// so a stale self-hosted bundle can't sneak a `javascript:` href into <a>.+const ALLOWED_LINK_PROTOCOLS = new Set(["http:", "https:"]);+const safeLink = (link: string | null): string | null => {+ if (!link) return null;+ try {+ const { protocol } = new URL(link, window.location.origin);+ return ALLOWED_LINK_PROTOCOLS.has(protocol) ? link : null;+ } catch {+ return null;+ }+};+export const AnnouncementModal = ({ announcements, isOpen, onOpenChange }: Props) => {const [index, setIndex] = useState(0);@@ -41,7 +54,8 @@ export const AnnouncementModal = ({ announcements, isOpen, onOpenChange }: Propsconst announcement = announcements[safeIndex];if (!announcement) return null;- const ctaLabel = announcement.linkLabel || (announcement.link ? "Learn more" : null);+ const safeHref = safeLink(announcement.link);+ const ctaLabel = announcement.linkLabel || (safeHref ? "Learn more" : null);const publishedLabel = formatPublished(announcement.published);const hasPrev = safeIndex > 0;const hasNext = safeIndex < total - 1;@@ -74,9 +88,9 @@ export const AnnouncementModal = ({ announcements, isOpen, onOpenChange }: Props<DialogDescription className="my-4 whitespace-pre-line text-foreground/75">{announcement.body}</DialogDescription>- {announcement.link && ctaLabel && (+ {safeHref && ctaLabel && (<a- href={announcement.link}+ href={safeHref}target="_blank"rel="noopener noreferrer"className="inline-flex w-fit items-center gap-1.5 text-sm text-white underline"