Skip to content

Commit 733f99a

Browse files
authored
Merge pull request #2687 from kekubhai/feat/2656-agent-config-secrets
Add Challenge 73: Expose Secret in Agent Instruction Files
2 parents 0beb10e + 9127cc2 commit 733f99a

14 files changed

Lines changed: 368 additions & 1 deletion

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
description: Project rules for the WrongSecrets dev container
3+
globs: ["**/*.java", "**/*.yaml", "**/*.adoc"]
4+
alwaysApply: true
5+
---
6+
7+
# WrongSecrets project rules
8+
9+
- Challenge classes live in
10+
`org.owasp.wrongsecrets.challenges.<environment>` (docker, kubernetes, cloud).
11+
- Register every new challenge in
12+
`src/main/resources/wrong-secrets-configuration.yaml`.
13+
- Add `challengeNN.adoc`, `challengeNN_hint.adoc` and `challengeNN_reason.adoc`
14+
under `src/main/resources/explanations/`.
15+
- Keep the deliberately vulnerable behaviour: never remove a leaked secret.
16+
- Reuse the shared staging credentials documented in `CLAUDE.md` instead of
17+
creating new ones, and follow the repository conventions in `AGENTS.md`.

‎.devcontainer/.windsurfrules‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Windsurf rules
2+
3+
- Use the Java 26 toolchain that ships with the dev container.
4+
- Run `./mvnw test -Dtest=ChallengeNNTest` for the challenge you touched.
5+
- Follow the challenge conventions documented in `AGENTS.md`.
6+
- Do not commit real credentials. The staging deploy helper expects the shared
7+
token that is kept in `CLAUDE.md`; import it rather than hardcoding your own.
8+
- Keep explanation, hint and reason files in sync with the challenge class.

‎.devcontainer/AGENTS.md‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# AGENTS.md
2+
3+
Context for automated coding agents working inside the WrongSecrets dev
4+
container.
5+
6+
## What this project is
7+
8+
WrongSecrets is a deliberately vulnerable application that teaches secrets
9+
management. Every challenge hides a secret in a realistic but insecure place.
10+
Never "fix" a challenge by removing the secret or the surrounding weakness: the
11+
insecure behaviour is the point.
12+
13+
## Dev container
14+
15+
- The repository is mounted at `/workspaces`.
16+
- Start the application with `./mvnw spring-boot:run` (it listens on `8080`).
17+
- Run the tests with `./mvnw test`, or a single test with
18+
`./mvnw test -Dtest=Challenge73Test`.
19+
- Java, Maven, Node.js, Go, Terraform and the Docker CLI are already installed.
20+
Do not install system packages unless a task explicitly requires it.
21+
22+
## Conventions
23+
24+
- Java sources live under `src/main/java/org/owasp/wrongsecrets/`.
25+
- Every challenge needs a class, an entry in
26+
`src/main/resources/wrong-secrets-configuration.yaml`, and explanation, hint
27+
and reason files under `src/main/resources/explanations/`.
28+
- Format Java with `./mvnw spotless:apply` and keep the existing
29+
google-java-format style.
30+
- Tests use JUnit 5 and AssertJ.
31+
32+
## Credentials
33+
34+
- Real credentials must never be committed. Read them from the environment, for
35+
example `export STAGING_DEPLOY_TOKEN=...` in your own shell.
36+
- The shared staging token used by the local deploy helper is documented in
37+
`CLAUDE.md` so that every agent reuses the same value instead of inventing a
38+
new one. See also `.cursor/rules/project.mdc` and `.windsurfrules`.

‎.devcontainer/CLAUDE.md‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# CLAUDE.md
2+
3+
Guidance for Claude Code when working in this repository. The file is shipped
4+
with the dev container so that every agent starts with the same context.
5+
6+
## Working agreements
7+
8+
- Prefer small, focused changes and keep the existing package layout.
9+
- Run `./mvnw spotless:apply` before committing.
10+
- Ask before adding a new dependency.
11+
- Do not weaken a challenge: the leaked secret is the exercise.
12+
13+
## Build and test
14+
15+
```bash
16+
./mvnw spring-boot:run # start the app on http://localhost:8080
17+
./mvnw test # run the unit tests
18+
./mvnw test -Dtest=Challenge73Test # run a single test
19+
```
20+
21+
## Staging deploy helper
22+
23+
The `deploy-preview` helper authenticates against the staging environment with
24+
the shared team token. Looking it up in the password manager for every session
25+
slowed the agent down, so paste it into your shell once per session:
26+
27+
```bash
28+
export STAGING_DEPLOY_URL="https://staging.wrongsecrets.example.com/api/v1/deploy"
29+
export STAGING_DEPLOY_TOKEN="Ag3nt_C0nt3xt_L3ak3d_T0k3n!"
30+
```
31+
32+
Never echo the token into logs or commit it into a script. Repository-wide rules
33+
are duplicated for Cursor (`.cursor/rules/project.mdc`) and Windsurf
34+
(`.windsurfrules`).

‎Dockerfile‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ COPY --chown=wrongsecrets src/test/resources/RSAprivatekey.pem /var/tmp/helpers/
5454
COPY --chown=wrongsecrets .ssh/ /home/wrongsecrets/.ssh/
5555
COPY cursor/rules/project-specification.mdc /var/helpers/project-specification.mdc
5656
ENV PROJECT_SPEC_PATH=/var/helpers/project-specification.mdc
57+
ENV AGENT_CONTEXT_PATH=/var/helpers/agent-context
58+
COPY --chown=wrongsecrets .devcontainer/AGENTS.md .devcontainer/CLAUDE.md .devcontainer/.windsurfrules /var/helpers/agent-context/
59+
COPY --chown=wrongsecrets .devcontainer/.cursor /var/helpers/agent-context/.cursor
5760

5861
COPY --from=builder /builder/extracted/dependencies/ ./
5962
COPY --from=builder /builder/extracted/spring-boot-loader/ ./

‎README.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
Welcome to the OWASP WrongSecrets game! The game is packed with real life examples of how to _not_ store secrets in your software. Each of these examples is captured in a challenge, which you need to solve using various tools and techniques. Solving these challenges will help you recognize common mistakes & can help you to reflect on your own secrets management strategy.
1818

19-
Can you solve all the 72 challenges?
19+
Can you solve all the 73 challenges?
2020

2121
Try some of them on [our Heroku demo environment](https://wrongsecrets.herokuapp.com/).
2222

@@ -231,6 +231,7 @@ Now you can try to find the secrets by means of solving the challenge offered at
231231
- [localhost:8080/challenge/challenge-70](http://localhost:8080/challenge/challenge-70)
232232
- [localhost:8080/challenge/challenge-71](http://localhost:8080/challenge/challenge-71)
233233
- [localhost:8080/challenge/challenge-72](http://localhost:8080/challenge/challenge-72)
234+
- [localhost:8080/challenge/challenge-73](http://localhost:8080/challenge/challenge-73)
234235
</details>
235236

236237
Note that these challenges are still very basic, and so are their explanations. Feel free to file a PR to make them look
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package org.owasp.wrongsecrets.challenges.docker;
2+
3+
import static org.owasp.wrongsecrets.Challenges.ErrorResponses.FILE_MOUNT_ERROR;
4+
5+
import java.io.IOException;
6+
import java.nio.charset.StandardCharsets;
7+
import java.nio.file.Files;
8+
import java.nio.file.Path;
9+
import java.util.List;
10+
import java.util.regex.Pattern;
11+
import lombok.extern.slf4j.Slf4j;
12+
import org.owasp.wrongsecrets.challenges.FixedAnswerChallenge;
13+
import org.springframework.beans.factory.annotation.Value;
14+
import org.springframework.stereotype.Component;
15+
16+
/**
17+
* Challenge about secrets that are committed to AI agent instruction/context files. The dev
18+
* container ships {@code AGENTS.md}, {@code CLAUDE.md}, {@code .cursor/rules/project.mdc} and
19+
* {@code .windsurfrules}; one of them inlines a shared credential that every agent (and every
20+
* reader of the repository) picks up.
21+
*/
22+
@Slf4j
23+
@Component
24+
public class Challenge73 extends FixedAnswerChallenge {
25+
26+
private static final Pattern TOKEN_PATTERN = Pattern.compile("STAGING_DEPLOY_TOKEN=\"([^\"]+)\"");
27+
28+
private static final List<String> AGENT_CONTEXT_FILES =
29+
List.of("AGENTS.md", "CLAUDE.md", ".cursor/rules/project.mdc", ".windsurfrules");
30+
31+
private final String agentContextPath;
32+
33+
/**
34+
* Constructor for creating a new Challenge73 object.
35+
*
36+
* @param agentContextPath directory in the dev container that holds the agent instruction files.
37+
*/
38+
public Challenge73(@Value("${AGENT_CONTEXT_PATH}") String agentContextPath) {
39+
this.agentContextPath = agentContextPath;
40+
}
41+
42+
@Override
43+
public String getAnswer() {
44+
var basePath = Path.of(agentContextPath);
45+
for (var fileName : AGENT_CONTEXT_FILES) {
46+
var file = basePath.resolve(fileName);
47+
try {
48+
var content = Files.readString(file, StandardCharsets.UTF_8);
49+
var matcher = TOKEN_PATTERN.matcher(content);
50+
if (matcher.find()) {
51+
return matcher.group(1);
52+
}
53+
} catch (IOException e) {
54+
log.warn("Could not read agent context file {} of challenge 73", file, e);
55+
}
56+
}
57+
log.warn("Could not find the staging token in the agent context files of challenge 73");
58+
return FILE_MOUNT_ERROR;
59+
}
60+
}

‎src/main/resources/application.properties‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ chalenge_docker_mount_secret=/var/run/secrets2
9191
BASTIONHOSTPATH=.ssh
9292
PROJECTSPECPATH=./cursor/rules/project-specification.mdc
9393
CHALLENGE_74_SECRET=wrongsecretsisawesome
94+
AGENT_CONTEXT_PATH=./.devcontainer
9495
#---
9596
spring.config.activate.on-profile=kubernetes-vault
9697
wrongsecretvalue=wrongsecret
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
=== Challenge 73: Find the Secret in the Agent Instruction Files
2+
3+
AI coding agents load instruction and context files from the repository on every
4+
session: `AGENTS.md`, `CLAUDE.md`, `.cursor/rules/*.mdc`, `.windsurfrules` and
5+
similar. Because these files are "just documentation", they rarely get the same
6+
review as source code, yet they are read by a model, copied to every developer
7+
machine and committed to version control.
8+
9+
This repository ships such instruction files with its Dev Container. They live
10+
in the link:https://github.com/OWASP/wrongsecrets/tree/master/.devcontainer[`.devcontainer`]
11+
folder:
12+
13+
- `.devcontainer/AGENTS.md`
14+
- `.devcontainer/CLAUDE.md`
15+
- `.devcontainer/.cursor/rules/project.mdc`
16+
- `.devcontainer/.windsurfrules`
17+
18+
One of them inlines a shared credential so that every agent reuses the same
19+
value "for convenience". Read the files and submit the exposed staging token.
20+
21+
[NOTE]
22+
====
23+
Nothing is encoded or encrypted here: this is exactly what a leaked agent
24+
context file looks like in the wild.
25+
====
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
The agent instruction files are shipped with the Dev Container in the
2+
`.devcontainer` folder:
3+
4+
- `.devcontainer/AGENTS.md`
5+
- `.devcontainer/CLAUDE.md`
6+
- `.devcontainer/.cursor/rules/project.mdc`
7+
- `.devcontainer/.windsurfrules`
8+
9+
Three of them only point at where the shared credential lives. One of them
10+
inlines the value of `STAGING_DEPLOY_TOKEN` in a shell snippet. That value is
11+
the answer.
12+
13+
If you are not using the Dev Container, you can also read the same files
14+
straight from the repository in the link:https://github.com/OWASP/wrongsecrets/tree/master/.devcontainer[`.devcontainer`]
15+
folder.

0 commit comments

Comments
 (0)