-
Notifications
You must be signed in to change notification settings - Fork 16
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
$request_body overwritten (MINOR) #69
Comments
Could you provide a bit more info please, so that we have the best chance of resolving your issue quickly. It seems you're calling an API and receiving an unexpected response:
|
The issue is not related to the function of the plugin itself. I’m getting the correct request body forwarded by nginx to the API server. The issue is seen only when I try to access the value $request_body from within location directive for example for logging So to reproduce :
|
I think somehow nginx is confusing the original request body with the introspection request
|
Ah - I understand your issue now. The module does write its own request body in order to send the introspection request. So this could be a case of needing to set a variable to capture the original request body, before this happens. I will run it by people internally, then take a closer look a little later, to see if we can find you a workaround. |
I reproduced this, with the following Docker based configuration. If the module does not run its introspection subrequest then a POST request body is logged correctly. Yet when the introspection subrequest is run, nginx seems to update the $request_body variable as you say. worker_processes 1;
error_log /dev/stdout info;
daemon on;
load_module modules/ngx_curity_http_phantom_token_module.so;
events { worker_connections 1024; }
http {
sendfile on;
proxy_cache_path cache levels=1:2 keys_zone=api_cache:10m max_size=10g inactive=60m use_temp_path=off;
log_format postdata $request_body;
server {
listen 8080;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
location /api {
access_log /dev/stdout postdata;
resolver 127.0.0.11;
phantom_token on;
phantom_token_client_credential test-nginx secret2;
phantom_token_introspection_endpoint curity;
proxy_pass "http://mockbin.com/request";
}
location curity {
resolver 127.0.0.11;
proxy_pass http://identityserver:8443/oauth/v2/oauth-introspect;
proxy_cache_methods POST;
proxy_cache api_cache;
proxy_cache_key $request_body;
proxy_ignore_headers Set-Cookie;
}
}
} Log entries for successful API calls in the
When cache configuration is removed, or the below entry is removed, the logging works as expected. Yet this is not an acceptable solution since the cache key then no longer works correctly and multiple access tokens return the same cached JWT.
So perhaps, after the subrequest completes, the parent request context needs to be restored in order for logging of request bodies to work. A couple of related posts below but a solution would require care. Also, we do not recommend logging of request bodies in production so perhaps this is a developer only requirement. In the meantime I see you have found a LUA based workaround so we will put this on hold. |
as a workaround I used Lua to save request body access_by_lua '
ngx.req.read_body()
ngx.var.req_body = ngx.req.get_body_data()
'; |
Nginx $request_body is being overwritten with “token=…” when I try to inspect it in the logs.
Any workaround?
The text was updated successfully, but these errors were encountered: