rrezartprebreza/spring-boot-skills / skills/spring-boot-4/spring-ai-security
spring-ai-security
VerifiedUse when threat-modeling or hardening a Spring AI RAG, chat, or tool-calling workflow against prompt injection, unauthorized actions, data exposure, or unbounded execution. Ordinary model-provider integration alone does not require this review.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 5.1 KB |
| agents/openai.yaml | config | 269 B |
| examples/bad-boundary.md | markdown | 354 B |
| examples/good-boundary.md | markdown | 644 B |
| templates/DocumentReadTool.java | other | 2.9 KB |
templates/DocumentReadTool.java
View on GitHubpackage com.example.aisecurity;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
public final class DocumentReadTool {
public record Caller(UUID tenantId, UUID accountId, Set<String> permissions) {
public Caller {
Objects.requireNonNull(tenantId);
Objects.requireNonNull(accountId);
permissions = Set.copyOf(permissions);
}
}
public interface Reader {
Optional<String> findAuthorized(UUID documentId, UUID tenantId, UUID accountId);
}
public static final class CallBudget {
private final AtomicInteger remaining;
public CallBudget(int maxCalls) {
if (maxCalls < 1 || maxCalls > 16) {
throw new IllegalArgumentException("Invalid tool call limit");
}
remaining = new AtomicInteger(maxCalls);
}
private void acquire() {
if (remaining.getAndUpdate(value -> value > 0 ? value - 1 : 0) == 0) {
throw new IllegalStateException("Tool call budget exhausted");
}
}
}
private final Caller caller;
private final Reader reader;
private final CallBudget budget;
private final int maxResultChars;
// Share the turn's budget across tool instances, retries and model iterations.
public DocumentReadTool(Caller caller, Reader reader, CallBudget budget, int maxResultChars) {
this.caller = Objects.requireNonNull(caller);
this.reader = Objects.requireNonNull(reader);
this.budget = Objects.requireNonNull(budget);
if (maxResultChars < 1 || maxResultChars > 8000) {
throw new IllegalArgumentException("Invalid tool limits");
}
this.maxResultChars = maxResultChars;
}
// This is the only model-facing argument. The adapter must not expose Caller or Reader.
public String read(String documentId) {
budget.acquire();
if (!caller.permissions().contains("documents:read")) {
throw new SecurityException("Document access denied");
}
if (documentId == null || documentId.length() != 36) {
throw new IllegalArgumentException("Expected a canonical document UUID");
}
UUID id = UUID.fromString(documentId);
if (!id.toString().equalsIgnoreCase(documentId)) {
throw new IllegalArgumentException("Expected a canonical document UUID");
}
String body = reader.findAuthorized(id, caller.tenantId(), caller.accountId())
.orElseThrow(() -> new SecurityException("Document unavailable"));
if (body.length() > maxResultChars) {
throw new IllegalStateException("Document exceeds tool result limit");
}
// Return as untrusted document content; the adapter must not promote it to instructions.
return body;
}
}
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |