Skip to content

Consider https for same origin check #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 3, 2024
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
Loading