Skip to content

fix: gate svg processing behind a flag#16582

Merged
ematipico merged 9 commits intomainfrom
feat/svg-flag
May 6, 2026
Merged

fix: gate svg processing behind a flag#16582
ematipico merged 9 commits intomainfrom
feat/svg-flag

Conversation

@Princesseuh
Copy link
Copy Markdown
Member

@Princesseuh Princesseuh commented May 4, 2026

Changes

SVGs are always troublesome in the end and wanting to actually process them is so uncommon that it's best to leave it to the user.

I decided to put it on a global image option so that other services could also use it, but I'd be okay with it being a service config as well, it's ok

Testing

Added a test

Docs

WIP

idealinsane and others added 2 commits April 27, 2026 18:12
Add image-meta dependency and use it in the Sharp image service to detect input formats early. Special-case SVGs: SVG sources are blocked by default and will throw unless image.dangerouslyAllowSVG is enabled. Update ASTRO_CONFIG_DEFAULTS and schema to include dangerouslyAllowSVG (default false) and add the corresponding type docs to the public config. Also add a safe fallback to return the original buffer if format detection fails.
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 4, 2026

🦋 Changeset detected

Latest commit: ab3bb9d

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions Bot added pkg: astro Related to the core `astro` package (scope) docs pr labels May 4, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 4, 2026

e18e dependency analysis

No dependency warnings found.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 4, 2026

Merging this PR will not alter performance

✅ 18 untouched benchmarks


Comparing feat/svg-flag (ab3bb9d) with main (ba2d2e3)

Open in CodSpeed

@github-actions github-actions Bot added the semver: minor Change triggers a `minor` release label May 4, 2026
@Princesseuh Princesseuh changed the title fix: add image.dangerouslyAllowSVG and SVG detection fix: gate svg processing behind a flag May 4, 2026
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is blocked because it contains a minor changeset. A reviewer will merge this at the next release if approved.

@Princesseuh Princesseuh added this to the 6.3 milestone May 4, 2026
@Princesseuh Princesseuh marked this pull request as ready for review May 4, 2026 14:50
Copy link
Copy Markdown
Member

@delucis delucis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code changes look fine — just left a thought about the flag naming.

* This is disabled by default because SVG files can contain scripts and other active content.
* Enable this option only if you trust your SVG sources.
*/
dangerouslyAllowSVG?: boolean;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bikeshed, but maybe this should be dangerouslyProcessSVG or dangerouslyRasterizeSVG? When this isn’t set users can still use SVGs right? It just doesn’t rasterize/process them in any way?

(Also could maybe be enabled by default in static sites where there’s no risk? But that might be confusing.)

Copy link
Copy Markdown
Member Author

@Princesseuh Princesseuh May 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dangerouslyProcessSVG sounds great to me and would work if we ever enable sharp's SVG support

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go for it!

Copy link
Copy Markdown
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, however @delucis has a good point regarding naming. With the current name, it feels like users can't import/use SVG anymore?

Copy link
Copy Markdown
Member

@delucis delucis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes LGTM

Comment thread packages/astro/src/types/public/config.ts Outdated
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is blocked because it contains a minor changeset. A reviewer will merge this at the next release if approved.

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is blocked because it contains a minor changeset. A reviewer will merge this at the next release if approved.

Copy link
Copy Markdown
Member

@delucis delucis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hah, I thought that sounded funny. OK, that change aligns more with what I’d understood 👍

@ematipico ematipico merged commit 885cd31 into main May 6, 2026
27 of 28 checks passed
@ematipico ematipico deleted the feat/svg-flag branch May 6, 2026 11:03
@astrobot-houston astrobot-houston mentioned this pull request May 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs pr pkg: astro Related to the core `astro` package (scope) semver: minor Change triggers a `minor` release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants