Customize access-control-allow-origin headers in order to set specific origin domains

Ouverte
#809 3 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
35/100
Type d'issue
Fonctionnalité
Clarté
Plutôt claire
Activité
À l'abandon
Stack technique
javascript
Domaine
backend, cli, security

Piste de recherche

Commencez par suivre la manière dont l’option --cors est analysée et l’endroit où l’en-tête de réponse access-control-allow-origin est défini. Examinez le comportement CORS existant et sa documentation avant de décider comment les origines configurables doivent être représentées. Le travail est considéré comme terminé lorsqu’il permet d’autoriser des domaines spécifiques ou * tout en préservant le comportement correct des requêtes avec identifiants.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

stale
What's the problem this feature will solve?

Currently, with --cors enabled access-control-allow-origin hard coded to *. If http-server is behind features that require authentication (client SSL certs in my case), the fetch spec requires browsers to validate that the requesting server be set as an allowed origin. So when server1 makes a request to server2 it fails because of the wildcard. This is the intended behavior as designed. Firefox currently (correctly) follows the fetch spec but, Chrome and Edge do not. At some point, chrome and edge 'should' eventually be fixed.

Chrome and Edge still send certs unprompted when executing the fetch command, but when fetch is set to {credentials:"include"} in server1 requesting information from server2 you now get this error:

Access to fetch at 'https://server2.tld' from origin 'https://server1.tld' has been blocked by CORS policy: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'.

Describe the solution you'd like

Requesting the ability to customize access-control-allow-origin headers in order to pass specific domains or set * manually.

This will allow http-server to be used correctly with authentication when a fetch is set to { credentials:"include" } .

Alternative Solutions
When requesting server does not have fetch is set to { credentials:"include" }
  • Firefox: in about:config set network.cors_preflight.allow_client_cert to true. Otherwise browser fails preflight because certs are not passed.
  • Chrome: in chrome://flags set Omit TLS client certificates if credential mode disallows to disabled. This is also the default behavior, chrome automatically sends credentials, this is against the spec.
  • Edge: no changes, flags are not available for this setting (default behavior, edge automatically sends credentials, this is against the spec.
When fetch is set to { credentials:"include" } on server1

Fails on all browsers

Access to fetch at 'https://server2.tld' from origin 'https://server1.tld' has been blocked by CORS policy: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'.

Alternate hack

Modify http-server source locally to hard code for my specific use-case, replace access-control-allow-origin = '*' and hard code it to access-control-allow-origin = 'https://server1.tld so it works for me. then enable --cors, start http-server.

Additional context

I'm sure there are other use-cases for setting access-control-allow-origin to custom domains, but for the authentication issue with client SSL certs, it's a must have.

I am aware that solution #760 to issue #729 can potentially fix my problem, but automatically mirroring the origin server will allow any origin to pass credentials, which is not very safe. This fix should only be used for testing and not production.

Langage dominant
JavaScript
Étoiles
14.2k
Forks
1.6k
Métriques de merge des PR
Aucune PR mergée en 30 j

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de http-party/http-server

Toutes les issues de http-party/http-server

Issues similaires

Plus d'issues JavaScript

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.