-
Notifications
You must be signed in to change notification settings - Fork 31
AMM-1456 : JWT validation #84
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
Changes from 6 commits
cb59cfe
54d149f
d926226
48ed61d
8b203a4
06015ae
b6dae7d
db54cfb
fb8f028
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -113,3 +113,6 @@ logging.level.org.springframework=INFO | |
| logging.path=logs/ | ||
| [email protected]_API_LOGGING_FILE_NAME@ | ||
| [email protected]_SECRET_KEY@ | ||
|
|
||
| [email protected]_DOC_ENABLED@ | ||
| [email protected]_DOC_ENABLED@ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package com.wipro.fhir.utils.http; | ||
|
|
||
|
|
||
| import java.util.*; | ||
|
|
||
| import jakarta.servlet.http.HttpServletRequest; | ||
| import jakarta.servlet.http.HttpServletRequestWrapper; | ||
|
|
||
| public class AuthorizationHeaderRequestWrapper extends HttpServletRequestWrapper{ | ||
| private final String Authorization; | ||
|
|
||
| public AuthorizationHeaderRequestWrapper(HttpServletRequest request, String authHeaderValue) { | ||
| super(request); | ||
| this.Authorization = authHeaderValue; | ||
| } | ||
|
|
||
| @Override | ||
| public String getHeader(String name) { | ||
| if ("Authorization".equalsIgnoreCase(name)) { | ||
| return Authorization; | ||
| } | ||
| return super.getHeader(name); | ||
| } | ||
|
|
||
| @Override | ||
| public Enumeration<String> getHeaders(String name) { | ||
| if ("Authorization".equalsIgnoreCase(name)) { | ||
| return Collections.enumeration(Collections.singletonList(Authorization)); | ||
| } | ||
| return super.getHeaders(name); | ||
| } | ||
|
|
||
| @Override | ||
| public Enumeration<String> getHeaderNames() { | ||
| List<String> names = Collections.list(super.getHeaderNames()); | ||
| if (!names.contains("Authorization")) { | ||
| names.add("Authorization"); | ||
| } | ||
| return Collections.enumeration(names); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -59,6 +59,10 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons | |||||||||||||||||||||||
| boolean status = true; | ||||||||||||||||||||||||
| logger.debug("In preHandle we are Intercepting the Request"); | ||||||||||||||||||||||||
| String authorization = request.getHeader("Authorization"); | ||||||||||||||||||||||||
| if (authorization.equals("")) { | ||||||||||||||||||||||||
| logger.info("Authorization header is null or empty. Skipping HTTPRequestInterceptor."); | ||||||||||||||||||||||||
| return true; // Allow the request to proceed without validation | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
| if (authorization.equals("")) { | |
| logger.info("Authorization header is null or empty. Skipping HTTPRequestInterceptor."); | |
| return true; // Allow the request to proceed without validation | |
| } | |
| // src/main/java/com/wipro/fhir/utils/http/HTTPRequestInterceptor.java | |
| // Lines: ~62-65 | |
| if (authorization == null || authorization.trim().isEmpty()) { | |
| logger.info("Authorization header is null or empty. Skipping HTTPRequestInterceptor."); | |
| return true; // Allow the request to proceed without validation | |
| } |
π€ Prompt for AI Agents
In src/main/java/com/wipro/fhir/utils/http/HTTPRequestInterceptor.java around
lines 62 to 65, the code calls authorization.equals("") without checking if
authorization is null, which can cause a NullPointerException if the
Authorization header is absent. Fix this by first checking if authorization is
null or empty using a safe method like authorization == null ||
authorization.isEmpty(), and update the log message to reflect that the header
may be null or empty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mobile-client bypass may open an authentication hole
Right now any request whose User-Agent contains βokhttpβ AND merely has an
Authorizationheader (regardless of its content) skips JWT validation.An attacker can spoof the UA string and send an empty or bogus header to gain access.
Consider tightening the rule:
Bearerand validate it, orπ€ Prompt for AI Agents