Quick revision
The short answer
Anyone who can reach the NodePort can send their own X-User header and become any user, including an administrator, because the application cannot tell who set the header. The immediate fix is to remove the NodePort and restrict ingress with NetworkPolicies so only the proxy reaches the pods. The proper fix is to stop trusting a plain header: have the proxy forward a signed token from the identity provider and validate it with Spring Security's resource server support, or require mutual TLS from the proxy, and add tests and runtime checks that requests without proxy credentials are rejected.
What to remember
In this answer, we saw that an application trusting an X-User header from its SSO proxy is fully open to anyone who reaches its NodePort. We removed the exposure with a ClusterIP Service and NetworkPolicies that admit only the proxy, then fixed the design by validating a signed token from the identity provider with Spring Security's resource server support, or by requiring mutual TLS from the proxy, and kept the fix in place with tests, cluster policies and alerts.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Anyone who can reach the NodePort can send their own X-User header and become any user, including an administrator, because the application cannot tell who set the header. The immediate fix is to remove the NodePort and restrict ingress with NetworkPolicies so only the proxy reaches the pods. The proper fix is to stop trusting a plain header: have the proxy forward a signed token from the identity provider and validate it with Spring Security's resource server support, or require mutual TLS from the proxy, and add tests and runtime checks that requests without proxy credentials are rejected.
Why this question is asked
This finding is common in Kubernetes clusters: an application designed to sit behind an SSO proxy was exposed some other way, often for debugging, and nobody noticed that the exposure bypasses all authentication. Interviewers ask it to see whether we recognise the severity immediately, act in the right order, and then fix the design rather than just the symptom. In this answer, we will explain the risk precisely, close the exposure, replace the trusted header with a signed token, look at mutual TLS as an alternative, and add the checks that keep it fixed.
1Why This Is a Critical Risk
The application uses pre-authentication: it believes the X-User header because it assumes only the SSO proxy can send requests to it. A NodePort Service in Kubernetes opens a port, for example 31080, on every node in the cluster and forwards it to the pods. Anyone who can reach a node's IP address on that port, which may be the whole corporate network or worse, can talk to the application directly.
4 messages in order. Play them, or step through them one at a time.
The application cannot tell the two requests apart.
That single command is the whole attack. It needs no stolen credentials and leaves logs that look like the admin did it. So we treat the finding as an active incident: close the exposure first, then check access logs on the NodePort for requests that did not come from the proxy, to find out whether anyone already used it.
2Remove the Direct Exposure
We change the Service type from NodePort to ClusterIP, which is reachable only inside the cluster, and route all external traffic through the ingress that leads to the proxy. Then we add a NetworkPolicy so that, even inside the cluster, only the proxy's pods can open connections to the application's pods. Without a policy, any pod in the cluster, including a compromised one, can still send the header.
Notice that a NetworkPolicy only has an effect if the cluster's network plugin enforces policies; on a cluster without it, the object is accepted and silently ignored. We confirm enforcement by testing from another pod and expecting the connection to fail. This step stops the bleeding, but the design still rests on the network being perfect forever.
3Replace the Header With a Signed Token
The proper fix removes the reason a header could be forged. Instead of a plain username, the proxy forwards a token signed by the identity provider, typically a JWT (JSON Web Token), in the Authorization header. The application validates the signature with the provider's public keys, checks the issuer, audience and expiry, and only then trusts the identity. A forged request without a valid signature fails, wherever it comes from.
The audience check matters: it makes sure a token issued for another application cannot be replayed against this one. In the Spring configuration we replace the header filter with oauth2ResourceServer() and map the token's groups claim to authorities with a JwtAuthenticationConverter. Now the curl command above returns 401, even from inside the cluster.
4Alternative: Mutual TLS Between Proxy and Application
If the proxy cannot forward tokens, mutual TLS is the next best option. The application requires every connection to present a client certificate, and accepts only the certificate of the proxy. The header is then honoured only on connections from that authenticated peer. A service mesh can provide this automatically, with policies that allow only the proxy's workload identity to call the application.
Mutual TLS proves who sent the request, while a signed token proves who the user is. Together they give the strongest result, but either one alone is far better than a header protected only by network layout.
5Keep It Fixed With Tests and Runtime Checks
Fixes like this are often undone months later by someone who adds a debug Service or a second ingress. So we add checks that fail loudly. An integration test sends a request with the old header and no token and expects 401. A test from a pod outside the proxy's namespace expects the connection to be refused. A cluster policy, for example in an admission controller, can forbid NodePort Services in this namespace altogether.
At runtime, the application can log and count requests rejected for missing or invalid tokens, with an alert when they spike, because a sudden stream of forged requests means someone has found a path to it.
| Check | Before | After |
|---|---|---|
| Direct request with X-User: admin | 200, full admin access | connection refused or 401 |
| Request from another pod | accepted | blocked by NetworkPolicy |
| Token for a different application | not checked | 401: wrong audience |
| Valid login through the proxy | 200 | 200, roles from the token |
New NodePort added by mistake | silently exposes the app | rejected by cluster policy |
6Follow-up questions
Why is closing the NodePort not enough?
Because the application still trusts any request that reaches it. A compromised pod, a misconfigured ingress or a future debug Service would reopen the same hole. Validating a signed token makes the application safe on its own, with the network as a second layer.
How do we find out whether the hole was exploited?
We look at access logs for the NodePort and compare them with the proxy's logs: any request to the application that the proxy did not forward is suspect. Requests for admin pages from unusual sources, or actions by users who have no SSO login at that time, are the strongest signals.
Does the proxy still need to strip incoming headers?
Yes. Even with a token, the proxy should remove any incoming X-User or Authorization header from clients before adding its own, so nothing a client sends is mistaken for something the proxy vouched for.
7Conclusion
In this answer, we saw that an application trusting an X-User header from its SSO proxy is fully open to anyone who reaches its NodePort. We removed the exposure with a ClusterIP Service and NetworkPolicies that admit only the proxy, then fixed the design by validating a signed token from the identity provider with Spring Security's resource server support, or by requiring mutual TLS from the proxy, and kept the fix in place with tests, cluster policies and alerts.
Open with
The risk is that the application's whole authentication is the X-User header, and a header is something any client can set. The NodePort opens the pods on every node, so anyone who can reach it can send X-User: admin and get admin access without logging in, and the logs will look like the admin did it.
Then, if they want more
I would treat it as an incident: first switch the Service to ClusterIP and add a NetworkPolicy that only allows the proxy's pods to connect, verify the policy is actually enforced by testing from another pod, and check the logs for requests to the NodePort that did not come from the proxy.
That stops the immediate exposure, but the design still depends on the network being perfect. The proper fix is for the proxy to forward a signed token from the identity provider, typically a JWT, and for the application to validate it with Spring Security's resource server support, checking issuer, audience and expiry, and mapping groups to roles.
Then a forged header is worthless anywhere. If tokens are not possible, mutual TLS so the application only accepts the proxy's certificate is the alternative. Finally I would add tests that requests without valid proxy credentials get 401, a cluster policy against NodePorts in that namespace, and alerts on rejected requests.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Security reference
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "A security review finds that an internal Spring application trusts an X-User header from...": https://scrivio-interview-library.netlify.app/spring-boot/authentication/5e1a48aa8a/