Skip to content

Request destination for SVG documents #1012

Open

Description

@yoavweiss

It's unclear what destination value should be used for SVG documents and different browsers seem to be doing different things, at least when it comes to CSP.

https://svg-discrimination.glitch.me/csp.html is loading fine in Chrome and Safari (as long as img-src: 'self' is there), but the SVG is blocked in Firefox.

At the same time, because SVG document resources are internally represented differently than images in Chromium, an as value of "image" for preloads is a mismatch for SVG documents.

Looking at Fetching the document over in SVG-land doesn't mention destination at all.

We should decide what the destination be, and then align spec and implementations on it.
My personal vote would be for a brand new destination (e.g. "svg" or "svg-document"), to make it easier to explain to developers which CSP or as values control these loads.

Activity

  1. yoavweiss commented on Mar 27, 2020

    @yoavweiss
    CollaboratorAuthor

    Another point to consider: the SVG document, when loaded using a <use> tag, doesn't seem to be able to run script, so maybe an "image" destination is the right call (and the Chromium implementation would have to somehow deal with that SVG documents are images too).

    /cc @yutakahirano @mikewest

  2. annevk commented on Mar 27, 2020

    @annevk
    Member

    It would be interesting to know why they are a separate type in Chromium.

    @ckerschb do you know what Firefox does here and why?

  3. mikewest commented on Mar 27, 2020

    @mikewest
    Member

    I guess I don't know why we'd want them to be distinct destinations. Why distinguish it as an SVG? image seems fine. Likewise, the CSP behavior seems like a bug in Firefox: img-src seems like it should control SVGs just like <img>.

  4. yoavweiss commented on Mar 27, 2020

    @yoavweiss
    CollaboratorAuthor

    I thought we may want another destination when I wasn't sure if these SVGs can run script, but looks like they can't. So, I'm fine with aligning them as an "image" destination and aligning Chromium's implementation to deal with that when it comes to preload. (I'm not sure if ResourceType::kSVGDocument is something we can get rid of, but that would be the cleanest...)

  5. annevk commented on Mar 27, 2020

    @annevk
    Member

    I think we should figure out why ResourceType::kSVGDocument is a thing first. If it only exists for non-web consumers, I agree we should go with image, but otherwise...

  6. Rob--W commented on Mar 27, 2020

    @Rob--W

    Coincidentally I recently looked into why svg subresource requests (e.g. in <use href>) are classified as "other" rather than "image" in Firefox, at https://bugzilla.mozilla.org/show_bug.cgi?id=1624471#c5. I'm not authorative here, but I would think that "image" makes more sense in this case than "other" or "document".

  7. yoavweiss commented on Mar 27, 2020

    @yoavweiss
    CollaboratorAuthor

    Here are Chromium's code search results for kSVGDocument.
    From brief scanning I think it's mostly impacting a couple of error messages, but not much more than that...

    It also seems Chromium is explicitly translating it to an "image" destination

  8. evilpie commented on Sep 9, 2024

    @evilpie
    Member

    I am changing Firefox (bug 1773976) to treat CSS filter: url("foo.svg#bar") and SVG <use> as "image", primarily because we were running into web-compatibility issues with CSP img-src not applying to these SVG loads.

    Could this be codified? I think there is currently no WPT for this behavior.

  9. yoavweiss commented on Sep 9, 2024

    @yoavweiss
    CollaboratorAuthor
  10. longsonr commented on Sep 11, 2024

    @longsonr

    Another point to consider: the SVG document, when loaded using a <use> tag, doesn't seem to be able to run script, so maybe an "image" destination is the right call (and the Chromium implementation would have to somehow deal with that SVG documents are images too).

    /cc @yutakahirano @mikewest

    While neither use, nor image will run script within <script> tags.

    • use will run javascript event handlers but image will not.
    • use can load external references e.g. other use elements but image cannot load any external references.
    • use must be same domain as the loading content but image need not be.
  11. added a commit that references this issue on Sep 12, 2024
  12. annevk commented on Sep 25, 2024

    @annevk
    Member

    Using image for <use> seems very fraught.

    Ultimately the filter property and <use> element specifications will need to set destination where they define their fetching pipeline (but I realize they probably don't).

    An intermediate fix might be updating the table in Fetch and adding web-platform-tests, but it seems very concerning to classify <use> as "image". cc @whatwg/security

  13. mozfreddyb commented on Sep 27, 2024

    @mozfreddyb
    Collaborator

    From a theoretical stand point, I guess it would make sense to have a new destination type? The "cloning" behavior with <use> is not easily covered by something like "iframe" and should get their own type for the most appropriate handling.

    I am OK with treating image-related uses of SVG as image. But that all being said, some of these things seem unfortunately codified in the web platforms by e.g., the de-facto handling of svg like image in some parts of Chrome (at least CSP. We have not looked more closely)

  14. added a commit that references this issue on Sep 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions