python / python/cpython

wsgiref.validate is too restrictive regarding HTTP_CONTENT_LENGTH/TYPE

Aperta
#140,894 8 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

stdlib type-feature
Lingua principale
Python
Stelle
77.2k
Fork
35.9k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

Bug report

Bug description:

PEP 3333 specifies that certain CGI environment variables must be placed in the environ dictionary.

The environ dictionary is required to contain these CGI environment variables, as defined by the Common Gateway Interface specification

The CONTENT_TYPE and CONTENT_LENGTH environ variables must be set as follows:

CONTENT_TYPE
The contents of any Content-Type fields in the HTTP request. May be empty or absent.
CONTENT_LENGTH
The contents of any Content-Length fields in the HTTP request. May be empty or absent.

Additionally, HTTP headers must be converted to variables as follows:

HTTP_ Variables
Variables corresponding to the client-supplied HTTP request headers (i.e., variables whose names begin with "HTTP_"). The presence or absence of these variables should correspond with the presence or absence of the appropriate HTTP header in the request.

So if the client sends an HTTP Content-Length header, it must be converted into a CONTENT_LENGTH variable, and may be converted into a HTTP_CONTENT_LENGTH variable. However, the CGI specification makes the following additional comment about Content-Length and Content-Type:

The server is not required to create meta-variables for all the header fields that it receives. In particular, it SHOULD remove any header fields carrying authentication information, such as 'Authorization'; or that are available to the script in other variables, such as 'Content-Length' and 'Content-Type'. The server MAY remove header fields that relate solely to client-side communication issues, such as 'Connection'.

In particular note that HTTP_CONTENT_LENGTH should be removed, not must.


On the other hand, wsgiref.validate.validator checks

  • That HTTP_CONTENT_TYPE and HTTP_CONTENT_LENGTH are not in the environment (these headers should appear as CONTENT_LENGTH and CONTENT_TYPE).

I believe this is too restrictive because WSGI servers are not required to remove these headers. In particular, nginx (link to the FastCGI documentation, but similar behavior is present for SCGI and UWSGI) passes all HTTP headers by default except Status and X-Accel-.... Instead, the validator should check that if HTTP_CONTENT_TYPE is present that CONTENT_TYPE is also present (and similarly for CONTENT_TYPE).

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia da wsgiref.validate.validator e verifica come gestisce HTTP_CONTENT_TYPE e HTTP_CONTENT_LENGTH nel dizionario environ. Controlla, se presenti, i test esistenti del validator per queste variabili. Il lavoro è completo quando il validator accetta una variabile HTTP_ se è presente la variabile CONTENT_ corrispondente, continuando però a rifiutare una variabile HTTP_ senza la relativa controparte CONTENT_.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
backend-api-design
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
42/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.