Skip to content
This repository was archived by the owner on May 3, 2022. It is now read-only.

Commit f6aae3d

Browse files
Merge pull request #27 from actions/redirect-auth-issue
Redirects should not pass authorization to different domain
2 parents ab10999 + cde0b32 commit f6aae3d

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

__tests__/basics.test.ts

+46
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,52 @@ describe('basics', () => {
179179
done()
180180
})
181181

182+
it('does not pass auth with diff hostname redirects', async done => {
183+
let headers = {
184+
accept: 'application/json',
185+
authorization: 'shhh'
186+
}
187+
let res: httpm.HttpClientResponse = await _http.get(
188+
'https://httpbin.org/redirect-to?url=' +
189+
encodeURIComponent('https://www.httpbin.org/get'),
190+
headers
191+
)
192+
193+
expect(res.message.statusCode).toBe(200)
194+
let body: string = await res.readBody()
195+
let obj: any = JSON.parse(body)
196+
// httpbin "fixes" the casing
197+
expect(obj.headers['Accept']).toBe('application/json')
198+
expect(obj.headers['Authorization']).toBeUndefined()
199+
expect(obj.headers['authorization']).toBeUndefined()
200+
expect(obj.url).toBe('https://www.httpbin.org/get')
201+
202+
done()
203+
})
204+
205+
it('does not pass Auth with diff hostname redirects', async done => {
206+
let headers = {
207+
Accept: 'application/json',
208+
Authorization: 'shhh'
209+
}
210+
let res: httpm.HttpClientResponse = await _http.get(
211+
'https://httpbin.org/redirect-to?url=' +
212+
encodeURIComponent('https://www.httpbin.org/get'),
213+
headers
214+
)
215+
216+
expect(res.message.statusCode).toBe(200)
217+
let body: string = await res.readBody()
218+
let obj: any = JSON.parse(body)
219+
// httpbin "fixes" the casing
220+
expect(obj.headers['Accept']).toBe('application/json')
221+
expect(obj.headers['Authorization']).toBeUndefined()
222+
expect(obj.headers['authorization']).toBeUndefined()
223+
expect(obj.url).toBe('https://www.httpbin.org/get')
224+
225+
done()
226+
})
227+
182228
it('does basic head request', async done => {
183229
let res: httpm.HttpClientResponse = await _http.head(
184230
'http://httpbin.org/get'

index.ts

+10
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,16 @@ export class HttpClient {
386386
// which will leak the open socket.
387387
await response.readBody()
388388

389+
// strip authorization header if redirected to a different hostname
390+
if (parsedRedirectUrl.hostname !== parsedUrl.hostname) {
391+
for (let header in headers) {
392+
// header names are case insensitive
393+
if (header.toLowerCase() === 'authorization') {
394+
delete headers[header]
395+
}
396+
}
397+
}
398+
389399
// let's make the request with the new redirectUrl
390400
info = this._prepareRequest(verb, parsedRedirectUrl, headers)
391401
response = await this.requestRaw(info, data)

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@actions/http-client",
3-
"version": "1.0.7",
3+
"version": "1.0.8",
44
"description": "Actions Http Client",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)