-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Add configurable verification of HttpOnly cookies in JWTAuthentication filter #7025
Comments
I need some clarifications: In the JWT token, what claim name should be checked? Maybe also from Envoy config? For example: a request has following headers: Authorization: Bearer TOKEN After Envoy Jwt_Authn filter verified the TOKEN, it also needs to verify the cookie. If it has following config: verify_secure_cookie: The filter will look for "jwt_claim_key" field in the TOKEN claim, and verify its value is sha256 of cookie value from "secure_key". Is this correct? I feel it is better to have a separate filter for this function. The verified payload is written to dynamicMetadata in the stream_info. Other filter can access it to perform such verification. |
Absolutely correct. Sorry, forgot to add the claim name. It can be a separate filter, but no one will need to do such a verification somewhere else. It will always be in connection with the token verification, which makes me think it has to be the auth filter. |
Any thoughts ? |
I think these custom operations (e.g. sha256, etc.) seems too specific to be added to jwt filter unless there is a more generic way to specify and support these custom operations and allowing it to be reused in other filters. Maybe you could try to use a Lua filter (https://github.com/envoyproxy/envoy/tree/v1.10.0/examples/lua) to do this? |
Sha256 is not specific. It's a means to transform the data so that it cannot be restored. I don't mind having a general config saying "use sha256 for for hash operations" and "use hash transform" in the JWT filter. But that's premature optimisation or premature generalisation to be precise. Sha256 is already implemented in envoy/common/crypto/utility.cc and is used in /filters/http/common/aws it's just a matter of writing code. |
Sorry I did't mean |
Yangmin, what am I doing wrong ? I'm doing JWT auth and want payload to be in the dynamicMetadata() (see payload_in_metadata: "my_payload") so that the lua filter after jwt_auth can check the token payload. Before JWT_auth filter I capture some headers using another lua filter so that the arguments can be reconstructed. Problem: Logs:
Envoy Config:
|
It's only there when JWT auth is triggered and successfully completes. |
How do i implement such changes in c++ ? |
@andrewtikhonov I am OK to implement such verification feature in jwt_authn filter. |
Am I the only one who requested this ? |
This issue has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in the next 7 days unless it is tagged "help wanted" or other activity occurs. Thank you for your contributions. |
Activity |
Activity |
2 similar comments
Activity |
Activity |
This issue has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in the next 7 days unless it is tagged "help wanted" or other activity occurs. Thank you for your contributions. |
Actually this feature is a must when working with JWT and JS frontends. We have our fronend apps (vuejs, reactjs etc) which communicate with backend via gateway. and its common practice to use httponly cookies with jwt so js apps can't steal them. So without this feature the usage of a gateway for jwt validation before passing valid requests to backend services is obsolete. I tried the lua approach but its also not good/working because of POOR cookie support. there is no way to access cookies in lua except for fetching cookie header and parsing it manually by splitting etc.. I tried using header_to_metadata but this doesn't work as well because so i would vote +5 for this feature. please :) |
so i fount a workaround for this problem. its not that nice but I think it cleaner then processing cookies in lua. So the solution is to use hybrid approach. this is how it looks like in my solution.
The order is important
I would love to skip step 2. not sure if there is a namespace or a way to make header_to_metadata write the value back into headers. or may be we need a new extensions like well at least with this solution no need to mess around cookie parsing from a sting (in lua its quite dirty). a note on
|
btw: cookie/header name is case sensitive in |
@vemod thx a lot for your "patch" as been blocked by CORS policy: Response to preflight request doesn't pass access control check: 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'. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute. In the response envoy always set the response with Access-Control-Allow-Origin: '*'.. Any way to force the response header with the origin instead of *? |
you can force response headers by setting them in lua like in my example with auth request headers. to do that you need to implement |
have you tried to set |
@vemod allow_credentials: true into cors config not working at all with something like this on client side using grpc-web:
Can i declare multiple function with inline_code?
|
@vemod my bad the problem was coming from an old chrome cors extension. |
Title: Add configurable verification of HttpOnly cookies in JWTAuthentication filter
Problem:
Proposal:
Headers:
Envoy config
The text was updated successfully, but these errors were encountered: