Skip to content

Null value of Access-Control-Allow-Origin #975

@ToyB0x

Description

@ToyB0x

Describe the bug

It seems that MDN states that null should not be used for the value of Access-Control-Allow-Origin, but looking at the implementation below, it seems that null is returned. (See also 7.4. Avoid returning Access-Control-Allow-Origin: "null")

} else {
// There is no origin found in the headers, so we should return null
headers['Access-Control-Allow-Origin'] = 'null';
}

To Reproduce Steps to reproduce the behavior:

Run the existing test below.

it('should return null if the sent origin does not match', () => {
const request = new Request('http://localhost:4002/graphql', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
origin: 'http://localhost:4002',
},
});
const headers = getCORSHeadersByRequestAndOptions(request, corsOptionsWithMultipleOrigins);
expect(headers?.['Access-Control-Allow-Origin']).toBe('null');
});
});

Expected behavior

A server can respond to requests from disallowed origins without including Access-Control-Allow-Origin header.
In this case, the browser blocks the request based on the Same-Origin Policy.

Environment:

  • @whatwg-node/server: 0.9.18

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions