Skip to content

Sentry extension erroring when email present in the URL when passed through the sanitiser #1412

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

Closed
vlazdra opened this issue Apr 27, 2023 · 10 comments

Comments

@vlazdra
Copy link

vlazdra commented Apr 27, 2023

Platform

Dart

Obfuscation

Disabled

Debug Info

Disabled

Doctor

[✓] Flutter (Channel stable, 3.7.12, on macOS 13.1 22C65 darwin-arm64, locale en-RS)
• Flutter version 3.7.12 on channel stable at /Users/vlazdra/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 4d9e56e694 (9 days ago), 2023-04-17 21:47:46 -0400
• Engine revision 1a65d409c7
• Dart version 2.19.6
• DevTools version 2.20.1

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
• Android SDK at /Users/vlazdra/Library/Android/sdk
• Platform android-33, build-tools 33.0.2
• ANDROID_HOME = /Users/vlazdra/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
• All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.3)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 14E222b
• CocoaPods version 1.12.1

[✓] Chrome - develop for the web
• CHROME_EXECUTABLE = /Applications/Brave Browser.app/Contents/MacOS/Brave Browser

[✓] Android Studio (version 2022.2)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)

[✓] IntelliJ IDEA Community Edition (version 2023.1)
• IntelliJ at /Applications/IntelliJ IDEA CE.app
• Flutter plugin version 73.0.4
• Dart plugin version 231.8109.91

[✓] VS Code (version 1.77.3)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.40.0

[✓] Connected device (3 available)
• sdk gphone64 arm64 (mobile) • emulator-5554 • android-arm64 • Android 13 (API 33) (emulator)
• macOS (desktop) • macos • darwin-arm64 • macOS 13.1 22C65 darwin-arm64
• Chrome (web) • chrome • web-javascript • Brave Browser 112.1.50.121

[✓] HTTP Host Availability
• All required HTTP hosts are available

Version

7.5.0

Steps to Reproduce

It might be reproducable if the URL contains an email address, not 100% sure that it will do.
I receive an unknown Dio error with this message: FormatException: Invalid character (at character 9) https://[Filtered]@EXAMPLE.COM

Removing the Dio extension: dioClient.addSentry(); "fixes" the issue.

Expected Result

The parsing is successful.
Again, not sure if the parsing part actually fails, but I do see that Dio returning an Unknown error because of it.

Actual Result

The URL that is being process looks like this:
https://staging.server.com/api/v4/auth/password/reset/[email protected]

Possible regression of this PR: #1327

Are you willing to submit a PR?

No

@marandaneto
Copy link
Contributor

@vlazdra Thanks for reporting.
Can you give more details about when this happens and which features you have enabled?
Is it adding breadcrumbs?
Is it capturing client errors?
Is it when measuring performance? (spans)

Please share your SDK init code snippet and the code snippet of when setting up dio, thanks.

@github-project-automation github-project-automation bot moved this to Needs Discussion in [DEPRECATED] Mobile SDKs Apr 27, 2023
@marandaneto marandaneto moved this from Needs Discussion to Needs More Information in [DEPRECATED] Mobile SDKs Apr 27, 2023
@marandaneto marandaneto removed the bug label Apr 27, 2023
@marandaneto
Copy link
Contributor

The result here is wrong:

static String _urlWithAuthRemoved(String url) {
final userInfoMatch = _authRegExp.firstMatch(url);
if (userInfoMatch != null && userInfoMatch.groupCount == 3) {
final userInfoString = userInfoMatch.group(2) ?? '';
final replacementString = userInfoString.contains(":")
? "[Filtered]:[Filtered]@"
: "[Filtered]@";
return '${userInfoMatch.group(1) ?? ''}$replacementString${userInfoMatch.group(3) ?? ''}';
} else {
return url;
}
}
}

The output is https://[Filtered]@example.com for urlDetails?.urlOrFallback but @example.com is part of the email and not the URL or userInfo.
It's not throwing FormatException tho.

@marandaneto
Copy link
Contributor

@denrase can you check this? probably the same problem here.

@vlazdra
Copy link
Author

vlazdra commented Apr 28, 2023

Hey @marandaneto! 👋

This is the setup of the Sentry SDK:

  await SentryFlutter.init((options) {
    options.dsn = 'dsn value';
    // Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
    // We recommend adjusting this value in production.
    options.tracesSampleRate = 1.0;
    options.attachScreenshot = true;
  });

Regarding the Dio setup, it's pretty basic, I'm adding 5 different Interceptors but when I do enable the Sentry extensions that when I get the FormatException. Even if I remove all of my custom Interceptors and just leave the basic Dio setup and the Sentry extensions, it still errors with FormatException.

_dioClient.addSentry();

The worst things is that I'm unable to catch where exactly the issue is ocuring. The closest I thought where something might go wrong is with the new change.

Also, I'm not using Breadcrumbs directly at this stage, and nor am I using the Transaction option at this stage as well as Performance tracing.

Version of Sentry: 7.5.0 (both dart and flutter packages)
Version of Dio: 5.1.1

@marandaneto
Copy link
Contributor

@vlazdra right, it's probably a different URL then, maybe similar to https://staging.server.com/api/v4/auth/password/reset/[email protected] but not exactly, which fails during parsing, is there any way to be 100% sure of its format? via crumbs, debugging, etc?
We'll check if there's a need to at least wrap the whole thing in a try/catch, if not yet.

@vlazdra
Copy link
Author

vlazdra commented Apr 28, 2023

@marandaneto I think I got it. At least where it fails to parse and throws a FormatException.

In the end it's a completely different place than what was reported, as per usual when it comes to these type of issues. 😄

This line is the problem:

url: Uri.parse(urlDetails.urlOrFallback),

Screenshot 2023-04-28 at 14 00 34

@vlazdra
Copy link
Author

vlazdra commented Apr 28, 2023

It was this change that was introduced a month ago. I just came around to update the dependencies in my project.

24f71aa#diff-88768c3d418bb22a5112992f1828b4a2a9ffcca36f9080b9b5127e962f6880d8R85

@marandaneto
Copy link
Contributor

@vlazdra Right, that makes sense.
#1414
This fixes the issue with the error, another PR has to follow up to fix the formatting.

@marandaneto marandaneto moved this from Needs More Information to In Progress in [DEPRECATED] Mobile SDKs Apr 28, 2023
@marandaneto marandaneto self-assigned this Apr 28, 2023
@vlazdra
Copy link
Author

vlazdra commented Apr 28, 2023

Closing the issue since the PR (#1414) has been merged.
Thansk @marandaneto 🙌

@vlazdra vlazdra closed this as completed Apr 28, 2023
@github-project-automation github-project-automation bot moved this from In Progress to Done in [DEPRECATED] Mobile SDKs Apr 28, 2023
@marandaneto
Copy link
Contributor

@krystofwoldrich raise a new issue and assign it to @denrase , related to #1412 (comment)
The format exception is fixed but not the formatting, the output is still wrong, thanks.

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

No branches or pull requests

3 participants