Skip to content

Commit cbbc1e7

Browse files
authored
Merge pull request #3671 from akto-api-security/bug/threat-client-log
added log in threat client
2 parents e7e5be8 + f554029 commit cbbc1e7

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

apps/threat-detection/src/main/java/com/akto/threat/detection/cache/AccountConfigurationCache.java

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static AccountConfigurationCache getInstance() {
5252
* Thread-safe with double-check locking.
5353
*
5454
* @param dataActor DataActor instance to fetch data if refresh is needed
55-
* @return AccountConfig containing account settings and API collections
55+
* @return AccountConfig containing account settings and API collections, or default config with redact=false if cache fails
5656
*/
5757
public AccountConfig getConfig(DataActor dataActor) {
5858
long currentTime = System.currentTimeMillis();
@@ -67,9 +67,31 @@ public AccountConfig getConfig(DataActor dataActor) {
6767
}
6868
}
6969

70+
if (cachedConfig == null) {
71+
logger.errorAndAddToDb("getConfig returning null - cache refresh failed, returning default config with redact=false");
72+
return getDefaultConfig();
73+
}
74+
7075
return cachedConfig;
7176
}
7277

78+
/**
79+
* Returns a default AccountConfig with redaction disabled.
80+
* Used as fallback when cache refresh fails.
81+
*
82+
* @return Default AccountConfig with accountId=0, isRedacted=false, and empty collections
83+
*/
84+
private AccountConfig getDefaultConfig() {
85+
return new AccountConfig(
86+
0, // accountId
87+
false, // isRedacted = false (as requested)
88+
new ArrayList<>(), // empty apiCollections
89+
new ArrayList<>(), // empty apiInfos
90+
new HashMap<>(), // empty apiCollectionUrlTemplates
91+
new HashMap<>() // empty apiInfoUrlToMethods
92+
);
93+
}
94+
7395
/**
7496
* Force refresh the cache with fresh data from database.
7597
* If refresh fails, keeps the old cache (graceful degradation).
@@ -78,7 +100,16 @@ private void refreshConfig(DataActor dataActor) {
78100
try {
79101
logger.infoAndAddToDb("Refreshing account configuration cache");
80102
AccountSettings accountSettings = dataActor.fetchAccountSettings();
81-
logger.infoAndAddToDb("Fetched accountSettings in configuration cache");
103+
104+
logger.infoAndAddToDb("Fetched accountSettings in configuration cache. accountSettings is null: " + (accountSettings == null));
105+
106+
if (accountSettings == null) {
107+
logger.errorAndAddToDb("fetchAccountSettings returned null. Cannot refresh cache");
108+
return;
109+
}
110+
111+
logger.infoAndAddToDb("AccountSettings ID: " + accountSettings.getId());
112+
82113
List <ApiCollection> apiCollections = new ArrayList<>();
83114
if (accountSettings.getId() != 1758179941) {
84115
apiCollections = dataActor.fetchAllApiCollections();

apps/threat-detection/src/main/java/com/akto/threat/detection/tasks/MaliciousTrafficDetectorTask.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ public void run() {
189189
}
190190

191191
AccountConfig config = AccountConfigurationCache.getInstance().getConfig(dataActor);
192-
Context.accountId.set(config.getAccountId());
193192
Context.isRedactPayload.set(config.isRedacted());
194193

195194
for (ConsumerRecord<String, byte[]> record : records) {
@@ -433,8 +432,8 @@ public static List<SchemaConformanceError> handleSchemaConformFilter(HttpRespons
433432

434433
private void processRecord(HttpResponseParam record) throws Exception {
435434
HttpResponseParams responseParam = buildHttpResponseParam(record);
435+
Context.accountId.set(Integer.parseInt(responseParam.getAccountId()));
436436
String actor = this.threatConfigEvaluator.getActorId(responseParam);
437-
438437
if (actor == null || actor.isEmpty()) {
439438
logger.warnAndAddToDb("Dropping processing of record with no actor IP, account: " + responseParam.getAccountId());
440439
return;

0 commit comments

Comments
 (0)