Skip to content

Production-ready animations, transitions, backgrounds, and scenes for Remotion

fix(security): restrict render avatarUrl to GitHub avatar host allowlist

dev_wandryf3315a286e14
diff --git a/lib/server/__tests__/validate-input.test.ts b/lib/server/__tests__/validate-input.test.ts
index 2b1ff6df..acc9f7e2 100644
--- a/lib/server/__tests__/validate-input.test.ts
+++ b/lib/server/__tests__/validate-input.test.ts
@@ -99,7 +99,10 @@ describe("parseRenderInput — valid payload", () => {
it("accepts stargazers array of exactly 60 items", () => {
const many = Array.from({ length: 60 }, (_, i) =>
- stargazer({ login: `user${i}`, avatarUrl: `https://example.com/u/${i}` }),
+ stargazer({
+ login: `user${i}`,
+ avatarUrl: `https://avatars.githubusercontent.com/u/${i}`,
+ }),
);
const result = parseRenderInput(validBody({ stargazers: many }));
expect(result.stargazers).toHaveLength(60);
@@ -296,10 +299,10 @@ describe("parseRenderInput — stargazer item shapes", () => {
});
// ---------------------------------------------------------------------------
-// avatarUrl — http(s) enforcement (SSRF surface narrowing)
+// avatarUrl — GitHub avatar host allowlist (closes the SSRF window)
// ---------------------------------------------------------------------------
-describe("parseRenderInput — avatarUrl must be http(s)", () => {
+describe("parseRenderInput — avatarUrl must be a GitHub avatar URL", () => {
it("throws on a file:// avatarUrl", () => {
expect(() =>
parseRenderInput(
@@ -324,23 +327,101 @@ describe("parseRenderInput — avatarUrl must be http(s)", () => {
).toThrow(RenderInputError);
});
- it("accepts an http:// avatarUrl", () => {
+ it("accepts an https:// avatarUrl on the GitHub avatar host", () => {
const result = parseRenderInput(
- validBody({ stargazers: [stargazer({ avatarUrl: "http://example.com/avatar.png" })] }),
+ validBody({
+ stargazers: [stargazer({ avatarUrl: "https://avatars.githubusercontent.com/u/99" })],
+ }),
+ );
+ expect(result.stargazers[0].avatarUrl).toBe(
+ "https://avatars.githubusercontent.com/u/99",
);
- expect(result.stargazers[0].avatarUrl).toBe("http://example.com/avatar.png");
});
- it("accepts an https:// avatarUrl", () => {
+ it("accepts a GitHub avatar URL with a query string", () => {
const result = parseRenderInput(
validBody({
- stargazers: [stargazer({ avatarUrl: "https://avatars.githubusercontent.com/u/99" })],
+ stargazers: [
+ stargazer({ avatarUrl: "https://avatars.githubusercontent.com/u/1?v=4" }),
+ ],
}),
);
expect(result.stargazers[0].avatarUrl).toBe(
- "https://avatars.githubusercontent.com/u/99",
+ "https://avatars.githubusercontent.com/u/1?v=4",
);
});
+
+ it("rejects an http:// downgrade of the GitHub avatar host", () => {
+ expect(() =>
+ parseRenderInput(
+ validBody({
+ stargazers: [stargazer({ avatarUrl: "http://avatars.githubusercontent.com/u/1" })],
+ }),
+ ),
+ ).toThrow(RenderInputError);
+ });
+
+ it("rejects a non-GitHub https host", () => {
+ expect(() =>
+ parseRenderInput(
+ validBody({ stargazers: [stargazer({ avatarUrl: "https://evil.example.com/a.png" })] }),
+ ),
+ ).toThrow(RenderInputError);
+ });
+
+ it("rejects a loopback IP avatarUrl", () => {
+ expect(() =>
+ parseRenderInput(
+ validBody({ stargazers: [stargazer({ avatarUrl: "http://127.0.0.1:8080/x" })] }),
+ ),
+ ).toThrow(RenderInputError);
+ });
+
+ it("rejects the cloud metadata IP avatarUrl", () => {
+ expect(() =>
+ parseRenderInput(
+ validBody({
+ stargazers: [
+ stargazer({ avatarUrl: "http://169.254.169.254/latest/meta-data" }),
+ ],
+ }),
+ ),
+ ).toThrow(RenderInputError);
+ });
+
+ it("rejects an IPv6 loopback avatarUrl", () => {
+ expect(() =>
+ parseRenderInput(
+ validBody({ stargazers: [stargazer({ avatarUrl: "https://[::1]/x" })] }),
+ ),
+ ).toThrow(RenderInputError);
+ });
+
+ it("throws a 400 RenderInputError on an unparseable URL", () => {
+ expect(() =>
+ parseRenderInput(validBody({ stargazers: [stargazer({ avatarUrl: "not a url" })] })),
+ ).toThrow(RenderInputError);
+ });
+
+ it("throws a 400 RenderInputError on a scheme-only URL", () => {
+ expect(() =>
+ parseRenderInput(validBody({ stargazers: [stargazer({ avatarUrl: "https://" })] })),
+ ).toThrow(RenderInputError);
+ });
+
+ it("rejects a hostname that merely starts with the allowed host (subdomain spoof)", () => {
+ expect(() =>
+ parseRenderInput(
+ validBody({
+ stargazers: [
+ stargazer({
+ avatarUrl: "https://avatars.githubusercontent.com.evil.com/x",
+ }),
+ ],
+ }),
+ ),
+ ).toThrow(RenderInputError);
+ });
});
// ---------------------------------------------------------------------------
diff --git a/lib/server/validate-input.ts b/lib/server/validate-input.ts
index b23333da..6712cf6f 100644
--- a/lib/server/validate-input.ts
+++ b/lib/server/validate-input.ts
@@ -4,9 +4,10 @@ import "server-only";
* Strict server-side validation of the render payload. Renders cost real CPU on
* the box, so this is the gate that stops a crafted/oversized request from
* blowing up Chromium: caps the stargazer count + string sizes, enums the
- * orientation/theme, clamps the numbers, and only lets http(s) avatar URLs
- * through (avatars are fetched by the headless browser → http(s)-only narrows
- * the SSRF surface). Throws a typed 400 error on anything outside the rules.
+ * orientation/theme, clamps the numbers, and only lets avatar URLs through
+ * whose host is on the GitHub avatar allowlist (avatars are fetched by the
+ * headless browser → pinning the host closes the SSRF window instead of just
+ * narrowing it). Throws a typed 400 error on anything outside the rules.
*/
export type Orientation = "horizontal" | "vertical";
@@ -49,7 +50,7 @@ const MIN_SPEED = 1;
const MAX_SPEED = 4;
const HEX_COLOR = /^#[0-9a-fA-F]{3,8}$/;
-const HTTP_URL = /^https?:\/\//i;
+const ALLOWED_AVATAR_HOSTS = new Set(["avatars.githubusercontent.com"]);
const DEFAULT_ACCENT = "#ffbb00";
const DEFAULT_SPEED = 1;
@@ -96,9 +97,20 @@ function parseStargazer(value: unknown, index: number): RenderStargazer {
`stargazers[${index}].avatarUrl`,
MAX_AVATAR_URL_LEN,
);
- if (!HTTP_URL.test(avatarUrl)) {
+ let parsedAvatarUrl: URL;
+ try {
+ parsedAvatarUrl = new URL(avatarUrl);
+ } catch {
throw new RenderInputError(
- `stargazers[${index}].avatarUrl must be an http(s) URL`,
+ `stargazers[${index}].avatarUrl must be a valid URL`,
+ );
+ }
+ if (
+ parsedAvatarUrl.protocol !== "https:" ||
+ !ALLOWED_AVATAR_HOSTS.has(parsedAvatarUrl.hostname)
+ ) {
+ throw new RenderInputError(
+ `stargazers[${index}].avatarUrl must be a GitHub avatar URL`,
);
}
const starredAt = requireString(