Skip to content

Commit 7ca04a8

Browse files
committed
Log attacks
1 parent e9c6223 commit 7ca04a8

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

agent_api/src/main/java/dev/aikido/agent_api/storage/AttackQueue.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ public static void attackDetected(Attack attack, ContextObject context) {
2727
StatisticsStore.incrementAttacksBlocked(attack.operation); // Also increment blocked attacks.
2828
}
2929

30+
// we want to log the attack at this stage, to make sure that even if it is only detected, we still see logs
31+
if (ServiceConfigStore.getConfig().isBlockingEnabled()) {
32+
logger.error("Blocking attack: %s", attack);
33+
} else {
34+
logger.error("Detected attack (Blocking disabled): %s", attack);
35+
}
36+
3037
// generate attack API event
3138
APIEvent detectedAttack = createAPIEvent(attack, context);
3239
add(detectedAttack);

agent_api/src/main/java/dev/aikido/agent_api/vulnerabilities/Attack.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package dev.aikido.agent_api.vulnerabilities;
22

3+
import com.google.gson.Gson;
34
import dev.aikido.agent_api.context.User;
45

56
import java.util.Map;
@@ -26,14 +27,7 @@ public Attack(String op, Vulnerabilities.Vulnerability vulnerability, String sou
2627

2728
@Override
2829
public String toString() {
29-
return "Attack{" +
30-
"operation='" + operation + '\'' +
31-
", kind='" + kind + '\'' +
32-
", source='" + source + '\'' +
33-
", pathToPayload='" + pathToPayload + '\'' +
34-
", metadata=" + metadata +
35-
", payload='" + payload + '\'' +
36-
", stack='" + stack + '\'' +
37-
", user=" + user.id() + '}';
30+
Gson gson = new Gson();
31+
return gson.toJson(this);
3832
}
3933
}

0 commit comments

Comments
 (0)