|
| 1 | +package org.owasp.wrongsecrets.challenges.docker; |
| 2 | + |
| 3 | +import java.util.List; |
| 4 | +import java.util.Locale; |
| 5 | +import lombok.extern.slf4j.Slf4j; |
| 6 | +import org.owasp.wrongsecrets.challenges.FixedAnswerChallenge; |
| 7 | +import org.springframework.stereotype.Component; |
| 8 | + |
| 9 | +/** |
| 10 | + * Challenge about a retrieval augmented generation (RAG) vector store that indexed development |
| 11 | + * documents containing a synthetic secret. The simulated vector store exposes its indexed text |
| 12 | + * chunks through an unauthenticated search endpoint, exactly like a misconfigured vector database |
| 13 | + * that is reachable without authentication. |
| 14 | + */ |
| 15 | +@Slf4j |
| 16 | +@Component |
| 17 | +public class Challenge76 extends FixedAnswerChallenge { |
| 18 | + |
| 19 | + static final String DEVELOPMENT_SECRET = "vector-store-dev-secret-e5c91a7b"; |
| 20 | + |
| 21 | + private static final List<IndexedChunk> INDEXED_CHUNKS = |
| 22 | + List.of( |
| 23 | + new IndexedChunk( |
| 24 | + "chunk-0", |
| 25 | + "Onboarding guide: the staging environment is reset every night at 02:00 UTC."), |
| 26 | + new IndexedChunk( |
| 27 | + "chunk-1", |
| 28 | + "Runbook: restart the ingestion worker with `kubectl rollout restart" |
| 29 | + + " deployment/ingestion`."), |
| 30 | + new IndexedChunk( |
| 31 | + "chunk-2", |
| 32 | + "Draft API note: the development vector store uses the credential " |
| 33 | + + DEVELOPMENT_SECRET |
| 34 | + + " for the nightly embedding job. Rotate before production."), |
| 35 | + new IndexedChunk( |
| 36 | + "chunk-3", "Meeting notes: evaluation set v3 improved recall from 0.71 to 0.78.")); |
| 37 | + |
| 38 | + /** A single text chunk as it is stored in the simulated vector store. */ |
| 39 | + public record IndexedChunk(String id, String text) {} |
| 40 | + |
| 41 | + @Override |
| 42 | + public String getAnswer() { |
| 43 | + return DEVELOPMENT_SECRET; |
| 44 | + } |
| 45 | + |
| 46 | + /** |
| 47 | + * Simulates a similarity search against the in-app vector store: every indexed chunk whose text |
| 48 | + * contains the query (case-insensitive) is returned, including the chunk that leaks the |
| 49 | + * development secret. |
| 50 | + */ |
| 51 | + public List<IndexedChunk> search(String query) { |
| 52 | + if (query == null || query.isBlank()) { |
| 53 | + return INDEXED_CHUNKS; |
| 54 | + } |
| 55 | + var normalizedQuery = query.toLowerCase(Locale.ROOT); |
| 56 | + return INDEXED_CHUNKS.stream() |
| 57 | + .filter(chunk -> chunk.text().toLowerCase(Locale.ROOT).contains(normalizedQuery)) |
| 58 | + .toList(); |
| 59 | + } |
| 60 | +} |
0 commit comments