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

fix(sourcemaps): don't attempt to treat remote URL as a local file path #1850

Merged
merged 2 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/utils/sourcemaps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,14 @@ fn url_matches_extension(url: &str, extensions: &[&str]) -> bool {
.unwrap_or(false)
}

/// Return true iff url is a remote url (not a local path or embedded sourcemap).
fn is_remote_url(url: &str) -> bool {
return match Url::parse(url) {
Ok(url) => url.scheme() != "data",
Err(_) => false,
};
}

impl SourceMapProcessor {
/// Creates a new sourcemap validator.
pub fn new() -> SourceMapProcessor {
Expand Down Expand Up @@ -364,7 +372,14 @@ impl SourceMapProcessor {
continue;
};

let sourcemap_reference = match discover_sourcemaps_location(contents) {
// If this is a full external URL, the code below is going to attempt
// to "normalize" it with the source path, resulting in a bogus path
// like "path/to/source/dir/https://some-static-host.example.com/path/to/foo.js.map"
// that can't be resolved to a source map file.
// Instead, we pretend we failed to discover the location, and we fall back to
// guessing the source map location based on the source location.
let location = discover_sourcemaps_location(contents).filter(|loc| !is_remote_url(loc));
let sourcemap_reference = match location {
Some(url) => SourceMapReference::from_url(url.to_string()),
None => match guess_sourcemap_reference(&sourcemaps, &source.url) {
Ok(target) => target,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ $ sentry-cli sourcemaps inject ./code ./maps ./maps2 --log-level warn
> Found 1 file
> Analyzing 5 sources
> Injecting debug ids
WARN [..]-[..]-[..] [..]:[..]:[..].[..] +[..]:[..] Ambiguous matches for sourcemap path ./code/foo/index.js.map:
WARN [..]-[..]-[..] [..]:[..]:[..].[..] +[..]:[..] ./maps/foo/index.js.map
WARN [..]-[..]-[..] [..]:[..]:[..].[..] +[..]:[..] ./maps2/foo/index.js.map
WARN [..]-[..]-[..] [..]:[..]:[..].[..] [..]:[..] Ambiguous matches for sourcemap path ./code/foo/index.js.map:
WARN [..]-[..]-[..] [..]:[..]:[..].[..] [..]:[..] ./maps/foo/index.js.map
WARN [..]-[..]-[..] [..]:[..]:[..].[..] [..]:[..] ./maps2/foo/index.js.map

Source Map Debug ID Injection Report
Modified: The following source files have been modified to have debug ids
Expand Down
6 changes: 4 additions & 2 deletions tests/integration/_cases/sourcemaps/sourcemaps-inject.trycmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
$ sentry-cli sourcemaps inject ./server ./static
? success
> Searching ./server
> Found 12 files
> Found 14 files
> Searching ./static
> Found 8 files
> Analyzing 20 sources
> Analyzing 22 sources
> Injecting debug ids

Source Map Debug ID Injection Report
Modified: The following source files have been modified to have debug ids
[..]-[..]-[..]-[..]-[..] - ./server/app/page.js
[..]-[..]-[..]-[..]-[..] - ./server/chunks/1.js
[..]-[..]-[..]-[..]-[..] - ./server/dummy_embedded.js
[..]-[..]-[..]-[..]-[..] - ./server/dummy_hosted.js
[..]-[..]-[..]-[..]-[..] - ./server/flight-manifest.js
[..]-[..]-[..]-[..]-[..] - ./server/pages/_document.js
[..]-[..]-[..]-[..]-[..] - ./server/pages/api/hello.js
Expand All @@ -21,6 +22,7 @@ Source Map Debug ID Injection Report
[..]-[..]-[..]-[..]-[..] - ./static/chunks/app/head-172ad45600676c06.js
[..]-[..]-[..]-[..]-[..] - ./static/chunks/pages/asdf-05b39167abbe433b.js
Modified: The following sourcemap files have been modified to have debug ids
[..]-[..]-[..]-[..]-[..] - ./server/dummy_hosted.js.map
[..]-[..]-[..]-[..]-[..] - ./server/pages/_document.js.map
[..]-[..]-[..]-[..]-[..] - ./static/chunks/575-bb7d7e0e6de8d623.js.map
Ignored: The following source files already have debug ids
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ $ sentry-cli sourcemaps upload tests/integration/_fixtures/upload_some_debugids
> Analyzing 20 sources
> Rewriting sources
> Adding source map references
WARN [..]-[..]-[..] [..]:[..]:[..].[..] +[..]:[..] Some source files don't have debug ids:
WARN [..]-[..]-[..] [..]:[..]:[..].[..] +[..]:[..] - ~/server/app/page.js
WARN [..]-[..]-[..] [..]:[..]:[..].[..] +[..]:[..] - ~/server/chunks/1.js
WARN [..]-[..]-[..] [..]:[..]:[..].[..] +[..]:[..] - ~/server/dummy_embedded.js
WARN [..]-[..]-[..] [..]:[..]:[..].[..] +[..]:[..] - ~/server/pages/_document.js
WARN [..]-[..]-[..] [..]:[..]:[..].[..] +[..]:[..] - ~/server/pages/api/hello.js
WARN [..]-[..]-[..] [..]:[..]:[..].[..] +[..]:[..] - ~/static/chunks/575-bb7d7e0e6de8d623.js
WARN [..]-[..]-[..] [..]:[..]:[..].[..] +[..]:[..] - ~/static/chunks/pages/asdf-05b39167abbe433b.js
WARN [..]-[..]-[..] [..]:[..]:[..].[..] [..]:[..] Some source files don't have debug ids:
WARN [..]-[..]-[..] [..]:[..]:[..].[..] [..]:[..] - ~/server/app/page.js
WARN [..]-[..]-[..] [..]:[..]:[..].[..] [..]:[..] - ~/server/chunks/1.js
WARN [..]-[..]-[..] [..]:[..]:[..].[..] [..]:[..] - ~/server/dummy_embedded.js
WARN [..]-[..]-[..] [..]:[..]:[..].[..] [..]:[..] - ~/server/pages/_document.js
WARN [..]-[..]-[..] [..]:[..]:[..].[..] [..]:[..] - ~/server/pages/api/hello.js
WARN [..]-[..]-[..] [..]:[..]:[..].[..] [..]:[..] - ~/static/chunks/575-bb7d7e0e6de8d623.js
WARN [..]-[..]-[..] [..]:[..]:[..].[..] [..]:[..] - ~/static/chunks/pages/asdf-05b39167abbe433b.js
> Bundled 20 files for upload
> Bundle ID: [..]-[..]-[..]-[..]-[..]
> Uploaded files to Sentry
Expand Down
1 change: 1 addition & 0 deletions tests/integration/_fixtures/inject/server/dummy_hosted.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions tests/integration/_fixtures/inject/server/dummy_hosted.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading