Skip to content
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

Suggestion: allow to skip origin checks #61

Closed
ptrxyz opened this issue Feb 24, 2023 · 2 comments
Closed

Suggestion: allow to skip origin checks #61

ptrxyz opened this issue Feb 24, 2023 · 2 comments
Assignees

Comments

@ptrxyz
Copy link

ptrxyz commented Feb 24, 2023

We are planning to use this service i a dynamic environment where we can not foresee the origin URLs upfront. Would it be possible to allow skipping the origin checks altogether, if, for example, an environment variable is set? Obviously the service would then be publicly available, but in our case, we are fine with this or can handle it through origin checks in the network infrastructure.

I suggest something to the extend of replacing

if (!ALLOWED_ORIGINS.includes(parseOrigin(origin))) {

with:

const skip_origin_check = "SKIP_ORIGIN_CHECK" in process.env && process.env.SKIP_ORIGIN_CHECK == 1
if (!skip_origin_check && !ALLOWED_ORIGINS.includes(parseOrigin(origin)) ) {
...
@ptrxyz
Copy link
Author

ptrxyz commented Feb 24, 2023

Hm, wait, this seems to be client side code. Of course process.env is not available then. So then, the ALLOWED_ORIGIN check is probably not for security anyway?

Can we get a build flag to disable it or maybe load the ALLOWED_ORIGINS list from a json file that I can simply clear before building?

How does this look to you:

src/allowed_origins.json:

[
    "https://nmrxiv.org",
    "http://nmrxiv.org",
    "http://localhost",
    "http://localhost:3000",
    "http://127.0.0.1:",
    "http://127.0.0.1:3000",
    "http://test.nmrxiv.org",
    "http://193.196.39.168",
    "http://193.196.39.168:3000",
    "https://nodejsdev.nmrxiv.org"
]

events.ts:

// in your events.ts
// replace the ALLOWED_ORIGINS definition with an import
import ALLOWED_ORIGINS from '../allowed_origins.json';
...
const skipOriginCheck = ALLOWED_ORIGINS.length == 0 || ALLOWED_ORIGINS.includes('*');
if (!skipOriginCheck && !ALLOWED_ORIGINS.includes(parseOrigin(origin))) {
    throw new Error(`Invalid Origin ${origin}`);
}
...

@hamed-musallam
Copy link
Collaborator

@ptrxyz

Thanks for your suggestions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants