-
-
Notifications
You must be signed in to change notification settings - Fork 620
feat(docker): introduce Java 26 dev/build container and build-secret challenge #2650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sandeshkuldharme1
wants to merge
9
commits into
OWASP:master
Choose a base branch
from
sandeshkuldharme1:feat/jdk22-build-container
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
aa1c276
feat(docker): introduce JDK 22 build container and challenge
sandeshkuldharme1 3884ebd
fix: resolve UTF-8 BOM and configure Java 26 devcontainer
sandeshkuldharme1 41a017f
fix(encoding): strip UTF-8 BOM from Java source files
sandeshkuldharme1 ad15ce8
style: apply spotless formatting and add Javadoc
sandeshkuldharme1 63c3fa8
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] 42cd957
feat: add Challenge 67 components and update contributing guide for d…
sandeshkuldharme1 b1d7a93
feat: refactor Challenge 67 to Dev Container secret leak and add comp…
sandeshkuldharme1 c612007
Update pr-preview.yml
sandeshkuldharme1 873afba
fix(ci): add permissions for pages preview deployment
sandeshkuldharme1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| { | ||
| "name": "OWASP WrongSecrets (Java 26 & Node.js 26 Dev Container)", | ||
| "image": "eclipse-temurin:26-jdk-jammy", | ||
| "features": { | ||
| "ghcr.io/devcontainers/features/node:1": { | ||
| "version": "26" | ||
| }, | ||
| "ghcr.io/devcontainers/features/python:1": { | ||
| "version": "3.12" | ||
| }, | ||
| "ghcr.io/devcontainers/features/terraform:1": { | ||
| "version": "latest", | ||
| "tflint": "latest" | ||
| }, | ||
| "ghcr.io/devcontainers-contrib/features/terraform-docs:1": {}, | ||
| "ghcr.io/devcontainers/features/docker-in-docker:2": { | ||
| "enableOnStartup": true | ||
| }, | ||
| "ghcr.io/devcontainers/features/git:1": {}, | ||
| "ghcr.io/devcontainers/features/common-utils:2": { | ||
| "installZsh": true, | ||
| "configureZshAsDefaultShell": true | ||
| } | ||
| }, | ||
| "containerEnv": { | ||
| "DEVCONTAINER_SECRET": "WSECR-devcontainer-token-774921" | ||
| }, | ||
| "forwardPorts": [8080, 8090], | ||
| "portsAttributes": { | ||
| "8080": { | ||
| "label": "WrongSecrets Web UI", | ||
| "onAutoForward": "notify" | ||
| }, | ||
| "8090": { | ||
| "label": "WrongSecrets Vault UI", | ||
| "onAutoForward": "silent" | ||
| } | ||
| }, | ||
| "customizations": { | ||
| "vscode": { | ||
| "extensions": [ | ||
| "vscjava.vscode-java-pack", | ||
| "ms-azuretools.vscode-docker", | ||
| "redhat.vscode-yaml", | ||
| "redhat.vscode-xml", | ||
| "eamodio.gitlens", | ||
| "dbaeumer.vscode-eslint", | ||
| "esbenp.prettier-vscode", | ||
| "asciidoctor.asciidoctor-vscode", | ||
| "hashicorp.terraform" | ||
| ], | ||
| "settings": { | ||
| "java.configuration.runtimes": [ | ||
| { | ||
| "name": "JavaSE-26", | ||
| "path": "/opt/java/openjdk", | ||
| "default": true | ||
| } | ||
| ], | ||
| "java.compile.nullAnalysis.mode": "automatic" | ||
| } | ||
| } | ||
| }, | ||
| "postCreateCommand": "chmod +x ./mvnw && ./mvnw dependency:resolve -DskipTests && npm install && pip install pre-commit && pre-commit install && pre-commit install --hook-type commit-msg", | ||
| "remoteUser": "root" | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -92,7 +92,7 @@ jobs: | |||||
| uses: docker/build-push-action@v6 | ||||||
| with: | ||||||
| context: . | ||||||
| push: true | ||||||
| push: false | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah no, please keep this true, i understand it will fail for first time contributors and on forks, but that is fine :) we use it all the time for new feature testing
Suggested change
|
||||||
| platforms: linux/amd64,linux/arm64 | ||||||
| tags: ${{ steps.meta.outputs.tags }} | ||||||
| labels: ${{ steps.meta.outputs.labels }} | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/main/java/org/owasp/wrongsecrets/challenges/docker/Challenge67.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package org.owasp.wrongsecrets.challenges.docker; | ||
|
|
||
| import org.owasp.wrongsecrets.challenges.FixedAnswerChallenge; | ||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| /** Challenge for finding secrets leaked in Dev Container configurations and environments. */ | ||
| @Component | ||
| public class Challenge67 extends FixedAnswerChallenge { | ||
|
|
||
| private final String devcontainerSecret; | ||
|
|
||
| /** | ||
| * Constructor for creating a new Challenge67 object. | ||
| * | ||
| * @param devcontainerSecret The secret configured in the Dev Container environment. | ||
| */ | ||
| public Challenge67( | ||
| @Value("${DEVCONTAINER_SECRET:WSECR-devcontainer-token-774921}") String devcontainerSecret) { | ||
| this.devcontainerSecret = devcontainerSecret; | ||
| } | ||
|
|
||
| @Override | ||
| public String getAnswer() { | ||
| return this.devcontainerSecret; | ||
| } | ||
| } |
20 changes: 20 additions & 0 deletions
20
src/main/resources/challenges/challenge-67/challenge-67.snippet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| <div id="devcontainer-challenge-container" style="border: 1px solid #ccc; border-radius: 8px; padding: 20px; margin: 20px; background-color: #f9f9f9;"> | ||
| <h4>🐳 Dev Container Configuration Inspector</h4> | ||
| <p>Development containers allow teams to share reproducible development environments. However, committing hardcoded environment variables or secrets into <code>.devcontainer/devcontainer.json</code> can expose sensitive credentials to anyone with repository access.</p> | ||
|
|
||
| <div style="background-color: #1e1e1e; color: #d4d4d4; padding: 15px; border-radius: 6px; font-family: monospace; font-size: 13px; overflow-x: auto; margin-top: 15px;"> | ||
| <span style="color: #6a9955;">// .devcontainer/devcontainer.json excerpt</span><br> | ||
| {<br> | ||
| <span style="color: #9cdcfe;">"name"</span>: <span style="color: #ce9178;">"OWASP WrongSecrets (Java 26 & Node.js 26 Dev Container)"</span>,<br> | ||
| <span style="color: #9cdcfe;">"image"</span>: <span style="color: #ce9178;">"eclipse-temurin:26-jdk-jammy"</span>,<br> | ||
| <span style="color: #9cdcfe;">"containerEnv"</span>: {<br> | ||
| <span style="color: #9cdcfe;">"DEVCONTAINER_SECRET"</span>: <span style="color: #ce9178;">"WSECR-devcontainer-token-774921"</span><br> | ||
| },<br> | ||
| <span style="color: #9cdcfe;">"postCreateCommand"</span>: <span style="color: #ce9178;">"chmod +x ./mvnw && ./mvnw dependency:resolve -DskipTests && npm install && pip install pre-commit && pre-commit install"</span><br> | ||
| } | ||
| </div> | ||
|
|
||
| <div class="devcontainer-tip" style="margin-top: 15px; font-size: 12px; color: #666;"> | ||
| 💡 Tip: Check the <code>DEVCONTAINER_SECRET</code> environment variable defined in the Dev Container configuration. | ||
| </div> | ||
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| === Dev Container Secret Leak | ||
|
|
||
| Development containers (Dev Containers) allow teams to define reproducible development environments using containerization tools like VS Code Remote - Containers and GitHub Codespaces. By encapsulating tools, runtimes, and dependencies within `.devcontainer/devcontainer.json`, developers can get started without installing complex local software stacks. | ||
|
|
||
| However, developers frequently make the mistake of embedding sensitive tokens, passwords, API keys, or private registry access credentials directly into `.devcontainer/devcontainer.json` (such as in `containerEnv`, `remoteEnv`, or lifecycle scripts) and committing them to version control. | ||
|
|
||
| To solve this challenge: | ||
|
|
||
| . Inspect the `.devcontainer/devcontainer.json` configuration file in the project repository or review the configuration snippet in the UI. | ||
| . Identify the leaked `DEVCONTAINER_SECRET` or token defined in the container environment. | ||
| . Submit the discovered secret in the input field below. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| You can solve this challenge using the following steps: | ||
|
|
||
| 1. Inspect the Dev Container configuration file: | ||
| - Open the `.devcontainer/devcontainer.json` file in the root of the repository. | ||
| - Look for the `containerEnv` or `remoteEnv` sections where environment variables are defined. | ||
|
|
||
| 2. Inspect the running container environment: | ||
| - If running inside a dev container or Docker container, check the environment variables with `printenv DEVCONTAINER_SECRET` or `echo $DEVCONTAINER_SECRET`. | ||
|
|
||
| 3. Review the UI snippet provided on this challenge page for the exposed configuration. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| = Dev Container Configuration Secret Exposure | ||
|
|
||
| *Why Hardcoding Secrets in Dev Containers is a Critical Security Risk* | ||
|
|
||
| Dev Containers are shared development environments configured via `.devcontainer/devcontainer.json`. Because these files are typically tracked in version control, hardcoding secrets into devcontainer definitions presents several security dangers: | ||
|
|
||
| 1. **Exposure to All Repository Readers**: Anyone with read access to the source repository (or public forks and clones in open-source projects) can read secrets hardcoded in `.devcontainer/devcontainer.json`. | ||
| 2. **Environment Variable Leakage**: Credentials defined in `containerEnv` or `remoteEnv` are injected into every process inside the container, making them accessible to any script, child process, or diagnostic tool running in the container. | ||
| 3. **Persistent in Git History**: Once committed, removing the secret requires git history rewrites, and stale keys often remain valid indefinitely if rotation is not performed. | ||
|
|
||
| *Remediation and Best Practices:* | ||
|
|
||
| - **Use GitHub Codespaces Secrets / VS Code Dev Container Secrets**: Inject secrets dynamically via Codespaces repository/user secrets or VS Code settings rather than hardcoding them in configuration files. | ||
| - **Use Local Environment Substitution**: Reference host environment variables dynamically in `devcontainer.json` using `${localEnv:MY_SECRET}` syntax. | ||
| - **Use `.env` files with `.gitignore`**: Place development secrets in local `.env` files that are explicitly excluded from version control in `.gitignore`. | ||
| - **Adopt Secret Management Solutions**: Fetch secrets at runtime using dedicated secret managers (e.g., HashiCorp Vault, AWS Secrets Manager, Azure Key Vault, GCP Secret Manager). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/test/java/org/owasp/wrongsecrets/challenges/docker/Challenge67Test.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package org.owasp.wrongsecrets.challenges.docker; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
| import org.owasp.wrongsecrets.challenges.Spoiler; | ||
|
|
||
| class Challenge67Test { | ||
|
|
||
| private static final String DEFAULT_SECRET = "WSECR-devcontainer-token-774921"; | ||
|
|
||
| @Test | ||
| void spoilerShouldRevealAnswer() { | ||
| var challenge = new Challenge67(DEFAULT_SECRET); | ||
|
|
||
| assertThat(challenge.spoiler()).isEqualTo(new Spoiler(DEFAULT_SECRET)); | ||
| } | ||
|
|
||
| @Test | ||
| void rightAnswerShouldSolveChallenge() { | ||
| var challenge = new Challenge67(DEFAULT_SECRET); | ||
|
|
||
| assertThat(challenge.answerCorrect(DEFAULT_SECRET)).isTrue(); | ||
| } | ||
|
|
||
| @Test | ||
| void incorrectAnswerShouldNotSolveChallenge() { | ||
| var challenge = new Challenge67(DEFAULT_SECRET); | ||
|
|
||
| assertThat(challenge.answerCorrect("wrong-secret-token")).isFalse(); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @sandeshkuldharme1 ! I think we are missing a few components voor a devcontainer yet. Can you add those please?