Skip to content

Commit

Permalink
Merge pull request #81 from t27duck/80_samehost_https
Browse files Browse the repository at this point in the history
Consider https for same origin check
  • Loading branch information
marcelolx authored Oct 3, 2024
2 parents f3460a1 + 1e04ca7 commit 7e77fb3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
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

0 comments on commit 7e77fb3

Please sign in to comment.