Skip to content

Commit 8d37ed0

Browse files
alan-agius4atscott
authored andcommitted
fix(http): exclude caching for authenticated HTTP requests (#54746)
This update modifies the transfer cache logic to prevent caching of HTTP requests that require authorization. Closes: #54745 PR Close #54746
1 parent 3659553 commit 8d37ed0

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

packages/common/http/src/transfer_cache.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,10 @@ export function transferCacheInterceptorFn(
100100
// POST requests are allowed either globally or at request level
101101
(requestMethod === 'POST' && !globalOptions.includePostRequests && !requestOptions) ||
102102
(requestMethod !== 'POST' && !ALLOWED_METHODS.includes(requestMethod)) ||
103-
requestOptions === false || //
103+
// Do not cache request that require authorization
104+
req.headers.has('authorization') ||
105+
req.headers.has('proxy-authorization') ||
106+
requestOptions === false ||
104107
globalOptions.filter?.(req) === false
105108
) {
106109
return next(req);

packages/common/http/test/transfer_cache_spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,22 @@ describe('TransferCache', () => {
248248
makeRequestAndExpectNone('/test-2?foo=1', 'POST', {transferCache: true});
249249
});
250250

251+
it('should not cache request that requires authorization', async () => {
252+
makeRequestAndExpectOne('/test-auth', 'foo', {
253+
headers: {Authorization: 'Basic YWxhZGRpbjpvcGVuc2VzYW1l'},
254+
});
255+
256+
makeRequestAndExpectOne('/test-auth', 'foo');
257+
});
258+
259+
it('should not cache request that requires proxy authorization', async () => {
260+
makeRequestAndExpectOne('/test-auth', 'foo', {
261+
headers: {'Proxy-Authorization': 'Basic YWxhZGRpbjpvcGVuc2VzYW1l'},
262+
});
263+
264+
makeRequestAndExpectOne('/test-auth', 'foo');
265+
});
266+
251267
describe('caching with global setting', () => {
252268
beforeEach(
253269
withBody('<test-app-http></test-app-http>', () => {

0 commit comments

Comments
 (0)