-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: prevent the SDK from adding forbidden headers to requests (#85)
* fix: prevent the SDK from adding forbidden headers to requests, include uuid in file download URL generation * fix getFileUrl relavant test * chore: fix formatting * PubNub SDK v4.1.2 release. Co-authored-by: Mohit Tejani <[email protected]> Co-authored-by: Client Engineering Bot <60980775+Client Engineering [email protected]>
- Loading branch information
1 parent
a8bf178
commit bbd67d2
Showing
10 changed files
with
76 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const _forbiddenHeaders = [ | ||
'Accept-Charset', | ||
'Accept-Encoding', | ||
'Access-Control-Request-Headers', | ||
'Access-Control-Request-Method', | ||
'Connection', | ||
'Content-Length', | ||
'Cookie', | ||
'Date', | ||
'DNT', | ||
'Expect', | ||
'Feature-Policy', | ||
'Host', | ||
'Keep-Alive', | ||
'Origin', | ||
'Proxy-', | ||
'Sec-', | ||
'Referer', | ||
'TE', | ||
'Trailer', | ||
'Transfer-Encoding', | ||
'Upgrade', | ||
'Via', | ||
]; | ||
|
||
bool isHeaderForbidden(String header) { | ||
return _forbiddenHeaders | ||
.any((element) => element.matchAsPrefix(header) != null); | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
part of '../file_test.dart'; | ||
|
||
final _getFileUrl = | ||
'https://ps.pndsn.com/v1/files/test/channels/channel/files/fileId/fileName?pnsdk=PubNub-Dart%2F${PubNub.version}'; | ||
'https://ps.pndsn.com/v1/files/test/channels/channel/files/fileId/fileName?pnsdk=PubNub-Dart%2F${PubNub.version}&uuid=test'; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import 'package:test/test.dart'; | ||
|
||
import 'package:pubnub/src/networking/utils.dart'; | ||
|
||
void main() { | ||
group('Networking utils', () { | ||
test('isHeaderForbidden should return true for Content-Length header', () { | ||
expect(isHeaderForbidden('Content-Length'), equals(true)); | ||
}); | ||
|
||
test('isHeaderForbidden should return true for any Sec- or Proxy- header', () { | ||
expect(isHeaderForbidden('Sec-Test-1'), equals(true)); | ||
expect(isHeaderForbidden('Sec-Random-2'), equals(true)); | ||
expect(isHeaderForbidden('Proxy-Whatever'), equals(true)); | ||
}); | ||
|
||
test('isHeaderForbidden should return false for any other header not specified', () { | ||
expect(isHeaderForbidden('X-Custom-Header'), equals(false)); | ||
expect(isHeaderForbidden('Content-Type'), equals(false)); | ||
}); | ||
}); | ||
} |