Skip to content

Assistant custom message fix suggestion#2

Open
stuartcmehrens wants to merge 1 commit intomasterfrom
add-assistant-custom-message-example
Open

Assistant custom message fix suggestion#2
stuartcmehrens wants to merge 1 commit intomasterfrom
add-assistant-custom-message-example

Conversation

@stuartcmehrens
Copy link

No description provided.

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");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(&quot;param&quot;)</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(&quot;foo&quot;+param+&quot;bar&quot;);</a>"]
        end
    end
    %% Class Assignment
    Source:::invis
    Sink:::invis

    Traces0:::invis
    File0:::invis

    %% Connections

    Source --> Traces0
    Traces0 --> Sink

Loading
Ignore this finding from crlf-injection-logs-deepsemgrep-javaorg-copy.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Semgrep Assistant suggests the following fix: Sanitize the param variable using Jsoup.clean before logging it.

View step-by-step instructions
  1. Import Jsoup at the top of your file if it is not already imported:

    import org.jsoup.Jsoup;
  2. Sanitize the param variable using Jsoup.clean before logging it:

    String sanitizedParam = Jsoup.clean(param, Whitelist.none());
  3. Replace the original param in 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:

Suggested change
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant