{"record":{"id":"714b585c804201f4","repo":"withastro/astro","slug":"remoteimagenotallowed","errorCode":"RemoteImageNotAllowed","errorMessage":"Remote image ${imageURL} is not allowed by your image configuration.","messagePattern":"Remote image (.+?) is not allowed by your image configuration\\.","errorType":"exception","errorClass":"AstroError","httpStatus":null,"severity":"error","filePath":"packages/astro/src/assets/internal.ts","lineNumber":90,"sourceCode":"\n\tconst service = await getConfiguredImageService();\n\n\t// If the user inlined an import, something fairly common especially in MDX, or passed a function that returns an Image, await it for them\n\tconst resolvedOptions: ImageTransform = {\n\t\t...options,\n\t\tsrc: await resolveSrc(options.src),\n\t};\n\n\tlet originalWidth: number | undefined;\n\tlet originalHeight: number | undefined;\n\n\t// Infer size for remote images if inferSize is true\n\tif (resolvedOptions.inferSize) {\n\t\tdelete resolvedOptions.inferSize; // Delete so it doesn't end up in the attributes\n\n\t\tif (isRemoteImage(resolvedOptions.src) && isRemotePath(resolvedOptions.src)) {\n\t\t\tif (!isRemoteAllowed(resolvedOptions.src, imageConfig)) {\n\t\t\t\tthrow new AstroError({\n\t\t\t\t\t...AstroErrorData.RemoteImageNotAllowed,\n\t\t\t\t\tmessage: AstroErrorData.RemoteImageNotAllowed.message(resolvedOptions.src),\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst getRemoteSize = (url: string) =>\n\t\t\t\tservice.getRemoteSize?.(url, imageConfig) ?? inferRemoteSize(url, imageConfig);\n\t\t\tconst result = await getRemoteSize(resolvedOptions.src); // Directly probe the image URL\n\t\t\tresolvedOptions.width ??= result.width;\n\t\t\tresolvedOptions.height ??= result.height;\n\t\t\t// We've already paid for the fetch; reuse it to pin down the output format so the URL\n\t\t\t// (and any baked filename) doesn't have to defer or refetch.\n\t\t\tif (result.format) {\n\t\t\t\tresolvedOptions.format ??= resolveDefaultOutputFormat(result.format);\n\t\t\t}\n\t\t\toriginalWidth = result.width;\n\t\t\toriginalHeight = result.height;\n\t\t}","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/withastro/astro/blob/d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca/packages/astro/src/assets/internal.ts#L72-L108","documentation":"Thrown by getImage() when inferSize is set, the resolved src is a remote image string, and isRemoteAllowed(src, imageConfig) returns false. Astro requires remote image hosts to be explicitly allow-listed (image.domains / image.remotePatterns) before it will probe a remote URL for dimensions.","triggerScenarios":"Calling getImage({ src: 'https://other-host/img.png', inferSize: true }) where 'other-host' is not in image.domains and does not match any image.remotePatterns. Only remote (string) paths that pass isRemotePath are checked against isRemoteAllowed.","commonSituations":"Author adds a new image CDN/hostname without updating astro.config image.domains or remotePatterns, switches from a local import to a remote URL, or copies an image URL from a third party.","solutions":["Add the host to image.domains: image: { domains: ['other-host'] }.","Or add a remotePatterns entry: image: { remotePatterns: [{ protocol: 'https', hostname: 'other-host' }] }.","If the image is local, import it as an ESM asset instead of using a URL.","Drop inferSize and supply explicit width/height to avoid the remote probe entirely."],"exampleFix":"// astro.config.mjs\n// before\nimage: { domains: ['cdn.example.com'] }\n\n// after\nimage: { domains: ['cdn.example.com', 'other-host'] }","handlingStrategy":"validation","validationCode":"import { matchPattern } from 'astro/assets'; // pseudo\nfunction isAllowedRemote(src: string, cfg: { domains?: string[]; remotePatterns?: any[] }): boolean {\n  const host = (() => { try { return new URL(src).hostname; } catch { return null; } })();\n  if (!host) return false;\n  return (cfg.domains ?? []).includes(host);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep image.domains/remotePatterns in sync with every CDN you use.","Prefer importing local assets over remote URLs where possible.","When adding a new image host, update astro.config the same commit."],"tags":["images","remote","security","config"],"backgroundTag":null,"analyzedSha":"d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca","analyzedAt":"2026-08-12T13:37:29.035Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}