Skip to content
Open
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
5 changes: 5 additions & 0 deletions .changeset/brave-owls-redirect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"react-native-app-auth": patch
---

Stop native OAuth endpoint redirects when custom headers are present so credential-bearing headers cannot be forwarded to another origin.
4 changes: 4 additions & 0 deletions docs/docs/usage/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,7 @@ See specific example [configurations for your provider](/docs/category/providers
- **androidAllowCustomBrowsers** - (`string[]`) (default: undefined) _ANDROID_ override the used browser for authorization. If no value is provided, all browsers are allowed.
- **androidTrustedWebActivity** - (`boolean`) (default: `false`) _ANDROID_ Use [`EXTRA_LAUNCH_AS_TRUSTED_WEB_ACTIVITY`](https://developer.chrome.com/docs/android/trusted-web-activity/) when opening web view.
- **connectionTimeoutSeconds** - (`number`) configure the request timeout interval in seconds. This must be a positive number. The default values are 60 seconds on iOS and 15 seconds on Android.

Native discovery, token, and registration requests do not follow HTTP redirects when custom headers
are present. Configure the final endpoint URL directly so credential-bearing headers cannot be
forwarded to a redirected origin.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public void setConnectionTimeout (int timeout) {
public HttpURLConnection openConnection(@NonNull Uri uri) throws IOException {
HttpURLConnection conn = connectionBuilder.openConnection(uri);

if (headers != null) {
if (headers != null && !headers.isEmpty()) {
conn.setInstanceFollowRedirects(false);
for (Map.Entry<String, String> header: headers.entrySet()) {
conn.setRequestProperty(header.getKey(), header.getValue());
}
Expand Down
15 changes: 13 additions & 2 deletions packages/react-native-app-auth/ios/RNAppAuth.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#import <React/RCTConvert.h>
#import "RNAppAuthAuthorizationFlowManager.h"

@interface RNAppAuth()<RNAppAuthAuthorizationFlowManagerDelegate> {
@interface RNAppAuth()<RNAppAuthAuthorizationFlowManagerDelegate, NSURLSessionTaskDelegate> {
id<OIDExternalUserAgentSession> _currentSession;
}
@end
Expand Down Expand Up @@ -554,10 +554,21 @@ - (void)configureUrlSession: (NSDictionary*) headers sessionTimeout: (double) se

configuration.timeoutIntervalForRequest = sessionTimeout;

NSURLSession* session = [NSURLSession sessionWithConfiguration:configuration];
NSURLSession* session = headers.count > 0
? [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:nil]
: [NSURLSession sessionWithConfiguration:configuration];
[OIDURLSessionProvider setSession:session];
}

- (void)URLSession:(NSURLSession *)session
task:(NSURLSessionTask *)task
willPerformHTTPRedirection:(NSHTTPURLResponse *)response
newRequest:(NSURLRequest *)request
completionHandler:(void (^)(NSURLRequest *_Nullable))completionHandler
{
completionHandler(nil);
}

/*
* Take raw OIDAuthorizationResponse and turn it to response format to pass to JavaScript caller
*/
Expand Down