Allow opting out of the default charset being appended to the request `Content-Type` header
Mantenedores costumam responder em até 1 dia
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 2/5
- Tempo estimado
- 1-3 horas
- Facilidade para iniciantes
- 72/100
Direção de pesquisa
Comece por AwsProxyHttpServletRequestReader.java e ContainerConfig.java para rastrear como o conjunto de caracteres padrão é adicionado e configurado. Em seguida, leia ou execute AwsProxyHttpServletRequestReaderTest; adicione testes para desativar a opção, para o comportamento padrão inalterado e para um parâmetro charset= existente. O trabalho estará concluído quando a desativação deixar o Content-Type recebido inalterado e o comportamento padrão continuar intacto.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
- Framework version: 3.0.2 (also confirmed identical in 3.0.3 and on
main) - Implementations: All (core
AwsProxyHttpServletRequestReader)
Scenario
AwsProxyHttpServletRequestReader.readRequest(...) rewrites the incoming Content-Type header on the
proxy event before the servlet request is built (and so before any filter runs):
// AwsProxyHttpServletRequestReader.java#L55
request.getMultiValueHeaders().putSingle(HttpHeaders.CONTENT_TYPE, getContentTypeWithCharset(contentType, config));
If the client sent a Content-Type without a charset parameter, getContentTypeWithCharset appends
"; charset=" + config.getDefaultContentCharset(), which defaults to ISO-8859-1:
AwsProxyHttpServletRequestReader.javaL55: the mutation onto the eventAwsProxyHttpServletRequestReader.javaL82-L98:getContentTypeWithCharsetContainerConfig.javaL27:DEFAULT_CONTENT_CHARSET = "ISO-8859-1"ContainerConfig.javaL278-L291: getter/setter
This breaks any application that has to see the request headers exactly as the client sent them.
The case I hit is request-signature verification: the client signs a set of request components that
includes Content-Type (e.g. an HTTP message signature, a proof-of-possession token whose claims
hash the request headers, or an HMAC scheme). A servlet filter then recomputes the signature input
from HttpServletRequest. Because the container has already changed application/json to
application/json; charset=ISO-8859-1, the recomputed hash never matches and every request that
omits a charset fails verification.
There is currently no way to turn this off through ContainerConfig:
setDefaultContentCharset(null)producesContent-Type: application/json; charset=nullsetDefaultContentCharset("")producesContent-Type: application/json; charset=
Both still change the header. The only workarounds are to replace or subclass the request reader, or to
reverse-engineer the exact appended suffix inside the verifier and retry with it stripped. Both
depend on container internals.
(Related background: #175 covered how a forced default charset interacts badly with
application/json, which RFC 8259 defines as UTF-8 and which has no charset parameter.)
Expected behavior
There should be a supported way to make the container leave the client's Content-Type unmodified.
The default behavior can stay as it is.
Actual behavior
Whenever no charset is present, the header is always rewritten, and no configuration value avoids it.
Steps to reproduce
- Build an
AwsProxyRequestwith headerContent-Type: application/json(no charset). - Run it through
AwsProxyHttpServletRequestReader.readRequest(...). Calling
setDefaultContentCharset(null)on theContainerConfigfirst doesn't change the outcome. - Observe
servletRequest.getHeader("Content-Type")returnsapplication/json; charset=ISO-8859-1
(or; charset=null), and that the original event's multi-value headers were mutated as well.
Proposed fix
Make the append opt-out-able, default unchanged. Two options, happy to go with whichever the
maintainers prefer:
Option A: treat a null/blank charset as "don't append" (smallest diff, no new API)
private String getContentTypeWithCharset(String headerValue, ContainerConfig config) {
if (headerValue == null || "".equals(headerValue.trim())) {
return headerValue;
}
if (headerValue.contains("charset=")) {
return headerValue;
}
String charset = config.getDefaultContentCharset();
if (charset == null || charset.trim().isEmpty()) {
return headerValue;
}
...
}
Users opt out with config.setDefaultContentCharset(null). Downside: it gives null a special meaning
that isn't obvious from the API, so the setDefaultContentCharset Javadoc would need to document it.
Right now null just produces a malformed charset=null value, so nobody can depend on the current
behavior.
Option B: explicit boolean flag (more readable intent)
Add ContainerConfig#setAppendDefaultContentCharset(boolean) (default true) and check it in
getContentTypeWithCharset. It's a slightly bigger change (field, getter/setter, default init, guard),
but the setting explains itself.
Either way the default (ISO-8859-1 appended) stays the same, so existing users aren't affected. I'm
happy to open a PR with the change plus tests in AwsProxyHttpServletRequestReaderTest. The tests would
cover: no suffix when opted out, the default path still appending, and an existing charset= left as is.
- Linguagem predominante
- Java
- Estrelas
- 1.6k
- Forks
- 575
- Merge médio
- 1d 15h
- PRs com merge (30d)
- 12
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de aws/serverless-java-container
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 88/100
aws/serverless-java-container#1715 ·
Mantenedores costumam responder em até 1 dia
-
Support for API Gateway mTLS clientCert fieldTalvez já em andamento @2748109647 assumiu há 10 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 48/100
aws/serverless-java-container#1726 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 35/100
aws/serverless-java-container#1579 · 3 comentários · 1 reação ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 42/100
aws/serverless-java-container#1568 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 42/100
aws/serverless-java-container#1551 ·
Mantenedores costumam responder em até 1 dia
Todas as issues de aws/serverless-java-container
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
ls1intum/thesis-management#1473 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
LunaDeerMC/Dominion#301 · 1 comentário ·
-
[FEATURE] Expose external refresh, node-level translog and warmer statsTalvez já em andamento Um pull request vinculado a esta issue está aberto ou já foi mesclado. Abertauntriaged
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
opensearch-project/opensearch-prometheus-exporter#680 ·
Mantenedores costumam responder em até 2 dias
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 85/100