koajs / koajs/cors

Should default options allow null origin?

Open
#89 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
742
Forks
83
PR merge metrics
No merged PRs in 30d

Description

When using the default options, as the docs describe, without defining an origin, the response will set Access-Control-Allow-Origin to the request Origin header.

Enable cors with default options:
  origin: request Origin header

But if hit with a request that sets Origin: null, then the response will be Access-Control-Allow-Origin: null.

There's a lot of sources that say don't do this...
https://w3c.github.io/webappsec-cors-for-developers/#avoid-returning-access-control-allow-origin-null

I'm not really an expert in this area, but would there be a better default behavior than..

// https://github.com/koajs/cors/blob/master/index.js#L66
origin = options.origin || requestOrigin;

... if the requestOrigin were null?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with index.js around line 66, then read the linked W3C guidance to understand the security implications of reflecting a null Origin. Review the existing middleware behavior and tests, and clarify the intended default policy before defining completion as an agreed behavior with regression coverage.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
backend, security
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.