Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hardening: Precedence of the SourceMap HTTP header over the sourceMappingURL comment #27

Closed
jaro-sevcik opened this issue Apr 6, 2023 · 6 comments · Fixed by tc39/source-map-spec#12

Comments

@jaro-sevcik
Copy link
Contributor

Currently, the spec does not say what takes precedence if the source contains the //# sourceMappingURL=x comment, but the header specifies a different source map. The spec should specify that the header overrides that sourceMappingURL comment, and the browsers should be fixed accordingly (see the relevant Chromium bug).

@mitsuhiko
Copy link
Contributor

I would also favor that the header wins over the contents because otherwise the header is quite useless. That said I am not sure if actually having that header is a good idea.

We don’t observe it much in practice and I wonder if there is appetite in deprecating that header.

@jaro-sevcik
Copy link
Contributor Author

It seems that the header usage is around 0.1%. Not sure if that is low enough to warrant deprecation.

@mitsuhiko
Copy link
Contributor

I would not remove support but discourage the use. The header makes some sense in a world where you don’t need the contents of the minified JavaScript but for practice reasons the minified file is very much required so you can’t really optimize much anyways.

The header however is a potential interoperability hazard and it also makes debugging what’s going on ever so slightly more complex.

@jridgewell
Copy link
Member

If the browsers already behave one way, why are we giving precedence to the header? Besides the inline comment being considerably easier to work with, it's also closer to the actual content (being in the content).

@mitsuhiko
Copy link
Contributor

@jridgewell the spec never mentioned it one way or another which is why we now have the situation that it's inconsistent. Safari and Firefox prefer the header, Chrome prefers the comment, unsure what Edge does but I assume it matches Chrome. We (Sentry) also prefer the header over the embedded contents.

As it stand you cannot rely on the header overriding the content (which is the primary usecase I see for it) because Chrome does it the other way around.

I have definitely seen uses of the header internationally overriding the contents. For instance Sentry supports source map fetching and it will issue a specific header for this. Over the years there has been at least one user which has injected a source map header redirecting all requests to a separate HTTP server, only when it detected us scraping via the source map header. In that case we would not have found the source map if we went for the comment.

@kamilogorek
Copy link
Member

Here's a testing setup that can be used to validate the spec compliance: https://github.com/kamilogorek/sourcemaps-headers

Chrome prefers the comment

@mitsuhiko based on my today's tests:

  • all, Safari, Chrome, Firefox, and Edge prefer SourceMap header
  • all of them support X-SourceMap fallback
  • Firefox has a nice warning when there's an actual override

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants