Skip to content
Merged
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
40 changes: 40 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,46 @@ Each entry follows this format:
- **Decision** — Key design decisions and their reasoning
- **Files** — Links to modified files

## 🔒 CodeQL Remediation — Array Bounds, Arithmetic Overflow, Log Injection (2026-04-26)

**Repo:** EDDI (`fix/codeql-remediation-pr455`)

**What changed:** Remediated all CodeQL findings from PR #455 scan — 4 High severity (array bounds, arithmetic overflow) and 77 Medium severity (log injection / CWE-117).

### High Severity (4 findings)

- **CronDescriber.java** — Added `v >= 0` lower-bound guard in `formatSet()`. `CronParser.parseField()` could theoretically return negative values, causing `ArrayIndexOutOfBoundsException`. (2 findings)
- **RestConversationStore.java** — Clamped pagination parameters (`index`, `limit`) at method entry, added `Integer.MAX_VALUE` overflow guard on `index++`. Prevents infinite loop if user provides max-int index. (1 finding)
- **DescriptorStore.java** — Replaced `index * effectiveLimit` (int×int overflow) with `(long) index * effectiveLimit` + `Math.min(skipLong, Integer.MAX_VALUE)`. Resolves all 30 CodeQL annotations (same finding across generic instantiations). (1 finding, 30 annotations)

### Medium Severity — Log Injection (77 findings)

Created `LogSanitizer.java` in `ai.labs.eddi.utils` — replaces `\r`, `\n`, `\t` with `_` and strips remaining control characters from log values. Applied `sanitize()` wrapper to user-controlled values across 13 files:

| File | Values sanitized |
|------|-----------------|
| RestSecretStore | `tenantId`, `keyName` |
| RagIngestionService | `kbId`, `documentName` |
| ExpressionProvider | `expression` |
| ToolRateLimiter | `toolName` |
| ToolCostTracker | `toolName`, `conversationId` |
| ToolCacheService | `toolName` |
| McpToolProviderManager | `serverName`, URL |
| LlmTask | `conversationId` |
| EmbeddingStoreFactory | `storeType`, `kbId`, config params |
| ConversationSummarizer | `conversationId` |
| ChatModelRegistry | `tenantId`, `keyName` |
| AgentOrchestrator | `agentId`, `userId`, budget error |
| RestSlackWebhook | `eventType`, `eventId` |

**Note:** 4 earlier files (InMemoryConversationCoordinator, NatsConversationCoordinator, RestAgentEngineStreaming, InMemoryTenantQuotaStore) already had inline `sanitizeForLog()` from PR #424 review. These pre-existing fixes remain; the new `LogSanitizer` centralizes the pattern for all remaining files.

**Files (new):** `LogSanitizer.java`
**Files (modified):** CronDescriber, RestConversationStore, DescriptorStore + 13 log injection files
**Verification:** `mvnw compile` — BUILD SUCCESS.

---

## 🔒 OpenSSF Scorecard: Fuzzing + SLSA Provenance + Signed Releases (2026-04-23)

**Repo:** EDDI (`chore/scorecard-improvements`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import jakarta.ws.rs.core.Response;
import org.jboss.logging.Logger;

import static ai.labs.eddi.utils.LogSanitizer.sanitize;

import java.net.URI;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -214,24 +216,8 @@ private void syncDescriptor(String resourceId, AgentGroupConfiguration config) {
documentDescriptorStore.setDescriptor(resourceId, descriptorVersion, descriptor);
}
} catch (Exception e) {
LOG.warnf(e, "Failed to sync group descriptor name/description for id=%s", sanitizeForLog(resourceId));
LOG.warnf(e, "Failed to sync group descriptor name/description for id=%s", sanitize(resourceId));
}
}

private String sanitizeForLog(String value) {
if (value == null) {
return null;
}

StringBuilder sanitized = new StringBuilder(value.length());
for (int i = 0; i < value.length(); i++) {
char c = value.charAt(i);
if (c == '\r' || c == '\n' || c == '\t' || c < 0x20 || c == 0x7F) {
sanitized.append('_');
} else {
sanitized.append(c);
}
}
return sanitized.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import jakarta.ws.rs.core.Response;
import org.jboss.logging.Logger;

import static ai.labs.eddi.utils.LogSanitizer.sanitize;

import java.util.Map;

/**
Expand Down Expand Up @@ -43,7 +45,7 @@ public Response ingestDocument(String ragConfigId, Integer version, String kbId,
try {
ragConfig = restRagStore.readRag(ragConfigId, version);
} catch (Exception e) {
LOGGER.warnf("Failed to load RAG config %s v%d: %s", ragConfigId, version, e.getMessage());
LOGGER.warnf("Failed to load RAG config %s v%d: %s", sanitize(ragConfigId), version, e.getMessage());
return Response.status(Response.Status.NOT_FOUND).entity(Map.of("error", "RAG configuration not found: " + ragConfigId + " v" + version))
.build();
}
Expand All @@ -53,7 +55,8 @@ public Response ingestDocument(String ragConfigId, Integer version, String kbId,

String ingestionId = ragIngestionService.ingest(effectiveKbId, documentContent, documentName, ragConfig);

LOGGER.infof("Ingestion started: id=%s, kb=%s, doc=%s, chars=%d", ingestionId, effectiveKbId, documentName, documentContent.length());
LOGGER.infof("Ingestion started: id=%s, kb=%s, doc=%s, chars=%d", ingestionId, sanitize(effectiveKbId), sanitize(documentName),
documentContent.length());

return Response.accepted(Map.of("ingestionId", ingestionId, "kbId", effectiveKbId, "status", "pending")).build();
}
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/ai/labs/eddi/datastore/DescriptorStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ public List<T> readDescriptors(String type, String filter, Integer index, Intege
}

int effectiveLimit = (limit == null || limit < 1) ? 20 : limit;
int skip = (index != null && index > 0) ? index * effectiveLimit : 0;
int skip;
if (index != null && index > 0) {
long skipLong = (long) index * effectiveLimit;
skip = (int) Math.min(skipLong, Integer.MAX_VALUE);
} else {
skip = 0;
}

IResourceFilter.QueryFilters[] allFilters;
if (!queryFiltersOptional.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import jakarta.ws.rs.sse.SseEventSink;
import org.jboss.logging.Logger;

import static ai.labs.eddi.utils.LogSanitizer.sanitize;

import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -44,18 +46,11 @@ public RestAgentEngineStreaming(IConversationService conversationService) {
this.conversationService = conversationService;
}

private static String sanitizeForLog(String value) {
if (value == null) {
return "null";
}
return value.replace('\n', '_').replace('\r', '_');
}

@Override
public void sayStreaming(String conversationId, Boolean returnDetailed, Boolean returnCurrentStepOnly, List<String> returningFields,
InputData inputData, SseEventSink eventSink, Sse sse) {

final String safeConversationId = sanitizeForLog(conversationId);
final String safeConversationId = sanitize(conversationId);
try {
conversationService.sayStreaming(conversationId, returnDetailed, returnCurrentStepOnly, returningFields, inputData,
new IConversationService.StreamingResponseHandler() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import jakarta.ws.rs.sse.SseEventSink;
import org.jboss.logging.Logger;

import static ai.labs.eddi.utils.LogSanitizer.sanitize;

import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -72,25 +74,18 @@ public List<DeadLetterEntry> getDeadLetters() {
public void replayDeadLetter(String entryId) {
boolean replayed = coordinator.replayDeadLetter(entryId);
if (!replayed) {
throw new NotFoundException("Dead-letter entry not found: " + sanitizeForLog(entryId));
throw new NotFoundException("Dead-letter entry not found: " + sanitize(entryId));
}
log.infof("Dead-letter %s replayed via REST", sanitizeForLog(entryId));
log.infof("Dead-letter %s replayed via REST", sanitize(entryId));
}

@Override
public void discardDeadLetter(String entryId) {
boolean discarded = coordinator.discardDeadLetter(entryId);
if (!discarded) {
throw new NotFoundException("Dead-letter entry not found: " + sanitizeForLog(entryId));
}
log.infof("Dead-letter %s discarded via REST", sanitizeForLog(entryId));
}

private static String sanitizeForLog(String value) {
if (value == null) {
return "null";
throw new NotFoundException("Dead-letter entry not found: " + sanitize(entryId));
}
return value.replace('\n', '_').replace('\r', '_');
log.infof("Dead-letter %s discarded via REST", sanitize(entryId));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,17 @@ public RestConversationStore(
public List<ConversationDescriptor> readConversationDescriptors(Integer index, Integer limit, String filter, String conversationId,
String agentId, Integer agentVersion, ConversationState conversationState,
ConversationDescriptor.ViewState viewState) {
// Sanitize pagination parameters to prevent overflow (CodeQL: integer-overflow)
if (index == null || index < 0) {
index = 0;
}
if (limit == null || limit < 1) {
limit = 20;
}
if (limit > 100) {
limit = 100;
}

try {
List<ConversationDescriptor> conversationDescriptors;
List<ConversationDescriptor> retConversationDescriptors = new LinkedList<>();
Expand Down Expand Up @@ -136,7 +147,11 @@ public List<ConversationDescriptor> readConversationDescriptors(Integer index, I
}
}

index++;
if (index < Integer.MAX_VALUE) {
index++;
} else {
break; // prevent integer overflow
}
} while (!conversationDescriptors.isEmpty() && retConversationDescriptors.size() < limit);

return retConversationDescriptors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,10 @@ private static boolean isWeekends(Set<Integer> dows) {
private static String formatSet(Set<Integer> values, String[] labels) {
if (values.size() == 1) {
int v = values.iterator().next();
return v < labels.length ? labels[v] : String.valueOf(v);
return v >= 0 && v < labels.length ? labels[v] : String.valueOf(v);
}
return values.stream().map(v -> v < labels.length ? labels[v] : String.valueOf(v)).collect(java.util.stream.Collectors.joining(", "));
return values.stream().map(v -> v >= 0 && v < labels.length ? labels[v] : String.valueOf(v))
.collect(java.util.stream.Collectors.joining(", "));
}

private static String substituteNames(String field, Map<String, String> names) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.jboss.logging.Logger;

import static ai.labs.eddi.utils.LogSanitizer.sanitize;

import jakarta.annotation.PostConstruct;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
Expand Down Expand Up @@ -96,16 +98,9 @@ private double computeTotalQueueDepth(Map<String, BlockingQueue<Callable<Void>>>
return queues.values().stream().mapToInt(BlockingQueue::size).sum();
}

private static String sanitizeForLog(String value) {
if (value == null) {
return "null";
}
return value.replace('\n', '_').replace('\r', '_');
}

@Override
public void submitInOrder(String conversationId, Callable<Void> callable) {
final String safeConversationId = sanitizeForLog(conversationId);
final String safeConversationId = sanitize(conversationId);
// Max-size check: only reject truly new conversations, not follow-up messages.
// Note: this check is intentionally non-atomic (soft limit). Two threads
// could both pass the check and briefly exceed maxActiveConversations.
Expand Down Expand Up @@ -166,11 +161,11 @@ public void onComplete(Void result) {
public void onFailure(Throwable t) {
int nextAttempt = attempt + 1;
if (nextAttempt < MAX_RETRIES) {
log.warnf(t, "In-memory task failed (conversationId=%s, attempt=%d/%d), retrying...", sanitizeForLog(conversationId), nextAttempt,
log.warnf(t, "In-memory task failed (conversationId=%s, attempt=%d/%d), retrying...", sanitize(conversationId), nextAttempt,
MAX_RETRIES);
executeWithRetry(conversationId, queue, callable, nextAttempt);
} else {
log.errorf(t, "In-memory task exhausted retries (conversationId=%s, attempts=%d), dead-lettering", sanitizeForLog(conversationId),
log.errorf(t, "In-memory task exhausted retries (conversationId=%s, attempts=%d), dead-lettering", sanitize(conversationId),
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
nextAttempt);
routeToDeadLetter(conversationId, t);
totalProcessed.incrementAndGet();
Expand Down Expand Up @@ -252,7 +247,7 @@ public boolean replayDeadLetter(String entryId) {
if (entry.id().equals(entryId)) {
it.remove();
log.infof("Replayed dead-letter %s for conversation %s (in-memory — task reference lost, removed from DL queue)",
sanitizeForLog(entryId), sanitizeForLog(entry.conversationId()));
sanitize(entryId), sanitize(entry.conversationId()));
return true;
}
}
Expand All @@ -266,7 +261,7 @@ public boolean discardDeadLetter(String entryId) {
DeadLetterEntry entry = it.next();
if (entry.id().equals(entryId)) {
it.remove();
log.infof("Discarded dead-letter %s for conversation %s", sanitizeForLog(entryId), sanitizeForLog(entry.conversationId()));
log.infof("Discarded dead-letter %s for conversation %s", sanitize(entryId), sanitize(entry.conversationId()));
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.jboss.logging.Logger;

import static ai.labs.eddi.utils.LogSanitizer.sanitize;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
Expand Down Expand Up @@ -194,13 +196,6 @@ private void createOrUpdateStream(JetStreamManagement jsm, String name, StreamCo
}
}

private static String sanitizeForLog(String value) {
if (value == null) {
return "null";
}
return value.replace('\n', '_').replace('\r', '_');
}

/**
* Submit a conversation task for ordered processing.
*
Expand All @@ -217,7 +212,7 @@ private static String sanitizeForLog(String value) {
*/
@Override
public void submitInOrder(String conversationId, Callable<Void> callable) {
final String safeConversationId = sanitizeForLog(conversationId);
final String safeConversationId = sanitize(conversationId);
// Max-size check: only reject truly new conversations, not follow-up messages.
// Note: this check is intentionally non-atomic (soft limit).
if (!conversationQueues.containsKey(conversationId) && conversationQueues.size() >= maxActiveConversations) {
Expand Down Expand Up @@ -278,7 +273,7 @@ private void publishAndExecute(String conversationId, BlockingQueue<RetryableCal
m.getPublishDuration().record(Duration.ofNanos(durationNanos));
});
} catch (IOException | JetStreamApiException e) {
log.warnf(e, "Failed to publish to NATS for conversation %s, executing locally", sanitizeForLog(conversationId));
log.warnf(e, "Failed to publish to NATS for conversation %s, executing locally", sanitize(conversationId));
}

// Execute the callable via the runtime thread pool
Expand All @@ -297,13 +292,13 @@ public void onFailure(Throwable t) {
int attempt = retryable.incrementAndGetAttempt();

if (attempt < maxRetries) {
log.warnf(t, "Conversation task failed (conversationId=%s, attempt=%d/%d), retrying...", sanitizeForLog(conversationId), attempt,
log.warnf(t, "Conversation task failed (conversationId=%s, attempt=%d/%d), retrying...", sanitize(conversationId), attempt,
maxRetries);
// Re-execute the same callable (retry)
publishAndExecute(conversationId, queue, retryable);
} else {
log.errorf(t, "Conversation task exhausted retries (conversationId=%s, attempts=%d), " + "routing to dead-letter",
sanitizeForLog(conversationId),
sanitize(conversationId),
attempt);
routeToDeadLetter(conversationId, t);
submitNext(conversationId, queue);
Expand Down Expand Up @@ -332,12 +327,12 @@ private void routeToDeadLetter(String conversationId, Throwable failure) {
failure.getMessage() != null ? failure.getMessage().replace("\"", "\\\"") : "unknown", System.currentTimeMillis());

jetStream.publish(deadLetterSubject, payload.getBytes());
log.infof("Published dead-letter for conversation %s to %s", sanitizeForLog(conversationId), sanitizeForLog(deadLetterSubject));
log.infof("Published dead-letter for conversation %s to %s", sanitize(conversationId), sanitize(deadLetterSubject));

totalDeadLettered.incrementAndGet();
getMetrics().ifPresent(m -> m.getDeadLetterCount().increment());
} catch (IOException | JetStreamApiException e) {
log.errorf(e, "Failed to publish dead-letter for conversation %s", sanitizeForLog(conversationId));
log.errorf(e, "Failed to publish dead-letter for conversation %s", sanitize(conversationId));
}
}

Expand Down Expand Up @@ -452,7 +447,7 @@ public List<DeadLetterEntry> getDeadLetters() {
public boolean discardDeadLetter(String entryId) {
// For NATS, we can't selectively delete individual messages from a stream.
// Instead, we log it and let the operator know.
log.infof("Dead-letter %s acknowledged (NATS stream messages expire via retention policy)", sanitizeForLog(entryId));
log.infof("Dead-letter %s acknowledged (NATS stream messages expire via retention policy)", sanitize(entryId));
return true;
}

Expand Down
Loading
Loading