Skip to content

Commit 1e04ca7

Browse files
committed
Consider https for same origin check
Closes #80 Adds an additional check in `sameHostname` to not include the CSRF token for https requests on different domains.
1 parent f3460a1 commit 1e04ca7

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

Diff for: __tests__/fetch_request.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,16 @@ describe('header handling', () => {
223223

224224
describe('csrf token inclusion', () => {
225225
// window.location.hostname is "localhost" in the test suite
226-
test('csrf token is not included in headers if url hostname is not the same as window.location', () => {
226+
test('csrf token is not included in headers if url hostname is not the same as window.location (http)', () => {
227227
const request = new FetchRequest("get", "http://removeservice.com/test.json")
228228
expect(request.fetchOptions.headers).not.toHaveProperty("X-CSRF-Token")
229229
})
230230

231+
test('csrf token is not included in headers if url hostname is not the same as window.location (https)', () => {
232+
const request = new FetchRequest("get", "https://removeservice.com/test.json")
233+
expect(request.fetchOptions.headers).not.toHaveProperty("X-CSRF-Token")
234+
})
235+
231236
test('csrf token is included in headers if url hostname is the same as window.location', () => {
232237
const request = new FetchRequest("get", "http://localhost/test.json")
233238
expect(request.fetchOptions.headers).toHaveProperty("X-CSRF-Token")

Diff for: src/fetch_request.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export class FetchRequest {
4949
}
5050

5151
sameHostname () {
52-
if (!this.originalUrl.startsWith('http:')) {
52+
if (!this.originalUrl.startsWith('http:') && !this.originalUrl.startsWith('https:')) {
5353
return true
5454
}
5555

0 commit comments

Comments
 (0)