Skip to content

Base64 encoding incorrectly applied to application/jwk-set+json #265

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

Closed
jeremyhewett opened this issue Jul 27, 2023 · 4 comments · Fixed by #307
Closed

Base64 encoding incorrectly applied to application/jwk-set+json #265

jeremyhewett opened this issue Jul 27, 2023 · 4 comments · Fixed by #307

Comments

@jeremyhewett
Copy link

It seems the adapter treats a response with Content-Type header application/jwk-set+json as binary and base64 encodes it. The response should actually be plain JSON.

Specific scenario: I'm deploying an application based on node-oidc-provider, and the /jwks endpoint returns a base64 encoded string instead of plain JSON. The Content-Type header set by node-oidc-provider is application/jwk-set+json which is not configurable (and is apparently the correct value for this response). When I do change it to application/json (with a hack), then I get the correct response in plain JSON.

@bnusunny
Copy link
Contributor

Which version of the adapter did you see this problem? The adapter relies on lambda-http crate from AWS Lambda Rust Runtime to processing the response. lambda-http crates does treat "+json" suffix as text. Here is the link to the code.

And as related note, lambda-http crate won't be able to cover all text based contexn-types. In v0.8.0, lambda-http treats the following content-types as text.

Prefixes:

  • "text"
  • "application/json"
  • "application/javascript"
  • "application/xml"
  • "application/yaml"

Suffixes:

  • "+xml"
  • "+yaml"
  • "+json"

For other content-types, lambda-http will treat them as binary data and base64 encode it. And if you use API Gateway REST API to trigger the Lambda function, you need to configure binaryMediaTypes to handle the binary response. Details are in API Gateway Developer guide here.

@mluksch
Copy link

mluksch commented Oct 28, 2023

Same here with graphql-yoga + nextjs. With "Content-Type"-Response Header: "application/graphql-response+json; charset=utf-8". Is the charset a problem here maybe?

@bnusunny
Copy link
Contributor

Oh, the charset part causes the issue. This code here assumes Content-Type ends with the media type, which is not true.

I will fix this issue in Rust Runtime first.

@mluksch
Copy link

mluksch commented Oct 29, 2023

Awesome. Thank you :)

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