Repository navigation
fix(better_networking): normalise URL before OAuth 1.0 signing - #1970
Draft
vibhanshu-s wants to merge 1 commit into
Draft
vibhanshu-s wants to merge 1 commit into
vibhanshu-s wants to merge 1 commit into
Conversation
…2#1969) generateOAuth1AuthHeader parsed the raw request URL with Uri.parse and read uri.origin, which throws for URLs without an http/https scheme (e.g. api.example.com/v1 or localhost:8080), even though the request path accepts them via getValidRequestUri. Normalise the URL with getValidRequestUri (honouring the configured default scheme) before building the signature base string.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
OAuth 1.0 requests no longer fail for URLs without an explicit scheme (e.g.
api.example.com/v1,localhost:8080/x). The URL is normalised exactly as the request itself is, before the signature base string is built.Fixes #1969
Root cause
generateOAuth1AuthHeaderdidUri.parse(request.url)on the raw user input and then readuri.origin, which Dart only defines for absolute http/https URIs. Scheme defaulting and localhost/IP handling happen ingetValidRequestUri, which runs only afterhandleAuth. The result wasOAuth 1.0 authentication failed: Bad state: Origin is only applicable to schemes http and httpsbefore any network call.Implementation
generateOAuth1AuthHeadernow callsgetValidRequestUri(request.url, null, defaultUriScheme: ...)and throws anArgumentErrorwith the validator's message if the URL is invalid.handleAuthandgenerateOAuth1AuthHeadertake an optionaldefaultUriScheme(defaultkDefaultUriScheme), and bothhttp_service.dartcall sites pass the request's configured default scheme, so the signed base URI matches the URI that is actually sent.Design decisions
getValidRequestUrirather than a second normaliser so signing and sending cannot drift apart.buildGrpcMetadata) are unaffected.Changes
packages/better_networking/lib/utils/auth/oauth1_utils.dart: normalise URL viagetValidRequestUri.packages/better_networking/lib/utils/auth/handle_auth.dart: accept and forwarddefaultUriScheme.packages/better_networking/lib/services/http_service.dart: passdefaultUriSchemetohandleAuth(2 call sites).packages/better_networking/test/utils/auth/auth_handling_test.dart: regression tests.Tests added
api.apidash.dev/users,localhost:8080/users,127.0.0.1:8080/users) adds anOAuth ...Authorization header with anoauth_signature.ftp://) throws a descriptiveOAuth 1.0 authentication failed ... Unsupported URL Schemeexception.Verification performed
Generated from recorded command results, not from agent claims.
inspectionthen re-run with --trust)Limitations / risks
flutter testnordart analyze/format has been run and the regression tests have not been shown to fail before the fix. This PR is therefore a draft; CI results should be treated as the first verification.consumer-key/consumer-secret), not real credentials.Repository PR checklist
PR Description
Add your description
Related Issues
Video Demo
Checklist
mainbranch before making this PRflutter upgradeand verify)flutter test) and all tests are passingAdded/updated tests?
We encourage you to add relevant test cases.
OS on which you have developed and tested the feature?