Conversation
| private final static Logger log = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME); | ||
| protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | ||
| String param = request.getParameter("param"); | ||
| log.info("foo"+param+"bar"); |
There was a problem hiding this comment.
When data from an untrusted source is put into a logger and not neutralized correctly, an attacker could forge log entries or include malicious content. Please use the Jsoup.clean() function to sanitize data.
View Dataflow Graph
flowchart LR
classDef invis fill:white, stroke: none
classDef default fill:#e7f5ff, color:#1c7fd6, stroke: none
subgraph File0["<b>src/assistant-fix-custom-message.java</b>"]
direction LR
%% Source
subgraph Source
direction LR
v0["<a href=https://github.com/Semgrep-Demo/sharpcompress/blob/f78ee75a15268a8dcf55ffb5694c48185e0b0d37/src/assistant-fix-custom-message.java#L13 target=_blank style='text-decoration:none; color:#1c7fd6'>[Line: 13] request.getParameter("param")</a>"]
end
%% Intermediate
subgraph Traces0[Traces]
direction TB
v2["<a href=https://github.com/Semgrep-Demo/sharpcompress/blob/f78ee75a15268a8dcf55ffb5694c48185e0b0d37/src/assistant-fix-custom-message.java#L13 target=_blank style='text-decoration:none; color:#1c7fd6'>[Line: 13] param</a>"]
end
%% Sink
subgraph Sink
direction LR
v1["<a href=https://github.com/Semgrep-Demo/sharpcompress/blob/f78ee75a15268a8dcf55ffb5694c48185e0b0d37/src/assistant-fix-custom-message.java#L14 target=_blank style='text-decoration:none; color:#1c7fd6'>[Line: 14] log.info("foo"+param+"bar");</a>"]
end
end
%% Class Assignment
Source:::invis
Sink:::invis
Traces0:::invis
File0:::invis
%% Connections
Source --> Traces0
Traces0 --> Sink
There was a problem hiding this comment.
Semgrep Assistant suggests the following fix: Sanitize the param variable using Jsoup.clean before logging it.
View step-by-step instructions
-
Import
Jsoupat the top of your file if it is not already imported:import org.jsoup.Jsoup;
-
Sanitize the
paramvariable usingJsoup.cleanbefore logging it:String sanitizedParam = Jsoup.clean(param, Whitelist.none());
-
Replace the original
paramin the log statement with the sanitized version:log.info("foo" + sanitizedParam + "bar");
This ensures that any potentially malicious content in the param variable is neutralized before being logged.
This code change should be a good starting point:
| log.info("foo"+param+"bar"); | |
| // Sanitize the untrusted input using Jsoup.clean() before logging | |
| String sanitizedParam = Jsoup.clean(param, Whitelist.none()); | |
| log.info("foo" + sanitizedParam + "bar"); |
AI-generated comment. Please review the response carefully and leave feedback in the form of a 👍 or 👎 reaction
No description provided.