Skip to main content
Menu
Advisories

Reflected XSS via data URIs with an allow-listed host in the image endpoint

GHSA-C335-JQF9-8WMCPublished Updated GitHub

Description

Astro's /_image endpoint only loads remote images whose URL is allowed by image.domains or image.remotePatterns. Data URIs are meant to be allowed only by an explicit remotePatterns: [{ protocol: 'data' }] entry. That check could be bypassed by writing the data URI with a host: data is not a special URL scheme, so the URL parser reads cdn.example.com as the hostname of data://cdn.example.com/,<payload>. Any image.domains entry for that host, and any remotePatterns entry without a protocol that matched it, therefore allowed the data URI.

For example, with this configuration:

// astro.config.mjs
export default defineConfig({
  output: 'server',
  image: {
    domains: ['cdn.example.com'],
  },
});

a link to /_image?href=data://cdn.example.com/,<svg xmlns="http://www.w3.org/2000/svg" onload="alert(document.domain)"/> returned the attacker's SVG unchanged as image/svg+xml from the site's own origin, and the script ran when the link was opened.

Impact

Reflected cross-site scripting on on-demand rendered sites that use Astro's /_image endpoint and allow a remote host through image.domains, or through an image.remotePatterns entry without a protocol. The attacker does not need to control any content on the allowed host, because the payload is carried in the link. Exploitation requires a victim to open the crafted link.

Sites whose remotePatterns entries all set protocol: 'https' (or 'http') are not affected.

Affected versions

astro <= 7.4.13 and @astrojs/internal-helpers <= 0.13.2.

Patches

Fixed in astro 7.4.14 and @astrojs/internal-helpers 0.13.3. image.domains entries and image.remotePatterns entries without a protocol now only allow http and https URLs, the same as security.allowedDomains. Data URIs are allowed only by a pattern with protocol: 'data'.

remotePatterns: [{}] no longer allows data URIs on its own. To keep allowing them, add { protocol: 'data' }.

Workarounds

Upgrade to astro 7.4.14 or later. Before upgrading, replace image.domains entries and image.remotePatterns entries that have no protocol with remotePatterns entries that set protocol: 'https':

// astro.config.mjs
export default defineConfig({
  image: {
    remotePatterns: [{ protocol: 'https', hostname: 'cdn.example.com' }],
  },
});

Credits

Reported by @DanQbiX.

Affected versions

References

GitHub · withastro/astro