Skip to content
Merged
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
7 changes: 6 additions & 1 deletion __tests__/fetch_request.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,16 @@ describe('header handling', () => {

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

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

test('csrf token is included in headers if url hostname is the same as window.location', () => {
const request = new FetchRequest("get", "http://localhost/test.json")
expect(request.fetchOptions.headers).toHaveProperty("X-CSRF-Token")
Expand Down
2 changes: 1 addition & 1 deletion src/fetch_request.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class FetchRequest {
}

sameHostname () {
if (!this.originalUrl.startsWith('http:')) {
if (!this.originalUrl.startsWith('http:') && !this.originalUrl.startsWith('https:')) {
return true
}

Expand Down