Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,42 @@ public interface LlmAssistant {
"As a software architect, and based on your previous answer, generate other potential missing endpoints that are not mentioned in the OpenAPI file. For example, if there is GET /product/1, suggest DELETE /product/1 if it's not mentioned")
HttpRequestList complete();

@SystemMessage(
"You are a web application security expert reviewing potential false positives. Answer only in JSON.")
@UserMessage(
"Your task is to review the following finding from ZAP (Zed Attack Proxy).\n"
+ "The confidence level is a pull down field which allows you to specify how confident you are in the validity of the finding : \n"
+ "- 0 if it's False Positive\n"
+ "- 1 if it's Low\n"
+ "- 2 if it's Medium\n"
+ "- 3 if it's High\n"
+ "\n"
+ "The alert is described as follows : {{description}}\n"
+ "\n"
+ "As evidence, the HTTP response contains :\n"
+ "---\n"
+ "{{evidence}}\n"
+ "---\n"
+ "Provide a short consistent explanation of the new score.\n")
static final String PRIMARY_SYSTEM_MSG =
"You are a web application security expert reviewing potential false positives. Answer only in JSON.";
static final String PRIMARY_PROMPT =
"""
Your task is to review the following finding from ZAP (Zed Attack Proxy).
The confidence level is a pull down field which allows you to specify how confident you are in the validity of the finding:
- 0 if it's False Positive
- 1 if it's Low
- 2 if it's Medium
- 3 if it's High

The alert is described as follows : {{description}}

As evidence, the HTTP response contains:
---
{{evidence}}
---
""";

static final String PRIMARY_GOAL = "Provide a short consistent explanation of the new score.\n";
static final String PRIMARY_PROMPT_WITH_OTHERINFO =
PRIMARY_PROMPT
+ """
Also, here's some additional information that may be useful for you to reach your conclusion:
---
{{otherinfo}}
""";

@SystemMessage(PRIMARY_SYSTEM_MSG)
@UserMessage(PRIMARY_PROMPT + PRIMARY_GOAL)
Confidence review(@V("description") String description, @V("evidence") String evidence);

@SystemMessage(PRIMARY_SYSTEM_MSG)
@UserMessage(PRIMARY_PROMPT_WITH_OTHERINFO + PRIMARY_GOAL)
Confidence review(
@V("description") String description,
@V("evidence") String evidence,
@V("otherinfo") String otherinfo);
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.util.Map;
import java.util.stream.Collectors;
import org.apache.commons.httpclient.util.HttpURLConnection;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.parosproxy.paros.Constant;
Expand Down Expand Up @@ -170,7 +171,13 @@ public void reviewAlert(Alert alert) {
LOGGER.debug("Reviewing alert : {}", alert.getName());
LOGGER.debug("Confidence level from ZAP : {}", alert.getConfidence());
Stats.incCounter("stats.llm.alertreview.call");
llmConfidence = llmAssistant.review(alert.getDescription(), alert.getEvidence());
if (StringUtils.isBlank(alert.getOtherInfo())) {
llmConfidence = llmAssistant.review(alert.getDescription(), alert.getEvidence());
} else {
llmConfidence =
llmAssistant.review(
alert.getDescription(), alert.getEvidence(), alert.getOtherInfo());
}

if (llmConfidence.getLevel() == alert.getConfidence()) {
Stats.incCounter("stats.llm.alertreview.result.same");
Expand Down Expand Up @@ -207,7 +214,7 @@ public void reviewAlert(Alert alert) {
}

private static boolean isPreviouslyReviewed(Alert alert) {
return !alert.getTags().containsKey(AI_REVIEWED_TAG_KEY);
return alert.getTags().containsKey(AI_REVIEWED_TAG_KEY);
}

private static String getUpdatedOtherInfo(Alert alert, Confidence llmConfidence) {
Expand Down