Skip to content

fix: add ping to Docker base image to fix Command Injection levels (#540)#541

Merged
preetkaran20 merged 3 commits intoSasanLabs:masterfrom
zeel2104:fix/command-injection-ping-540
Mar 28, 2026
Merged

fix: add ping to Docker base image to fix Command Injection levels (#540)#541
preetkaran20 merged 3 commits intoSasanLabs:masterfrom
zeel2104:fix/command-injection-ping-540

Conversation

@zeel2104
Copy link
Copy Markdown
Contributor

Fixes #540

 The Docker container was missing the ping utility, causing all 
 Command Injection levels to fail with "ping not found".
 
 Changes:
 - Added Dockerfile.base with ping installed for both Alpine (local) 
   and Debian (CI) base images
 - Updated build.gradle jib config to use the new base images

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 51.52%. Comparing base (c45f88f) to head (9bfe069).
⚠️ Report is 7 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master     #541      +/-   ##
============================================
+ Coverage     51.48%   51.52%   +0.03%     
  Complexity      420      420              
============================================
  Files            65       65              
  Lines          2451     2467      +16     
  Branches        256      261       +5     
============================================
+ Hits           1262     1271       +9     
- Misses         1079     1082       +3     
- Partials        110      114       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread build.gradle Outdated
// docker build --target local -t vulnerableapp-base-local:latest -f Dockerfile.base .
from {
image = 'eclipse-temurin:17-jre-alpine'
image = 'docker://vulnerableapp-base-local:latest'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there any other way than this. we don't want to manage docker image separately also jib is used in github workflows and if we start using docker file we need to do many changes in workflows as well.
is there a small docker image with ping functionality?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @preetkaran20, I tested all eclipse-temurin:17-jre variants (alpine, jammy, focal) , none include ping by default and Jib cannot run apt-get during build, so there's no way to use a base image without a separate Dockerfile.
As an alternative, I've updated the fix to handle this directly in CommandInjection.java, it now detects when ping is missing and returns a clear error message instead of a cryptic 'not found' error. This requires no Docker or workflow changes but only a single Java file is changed.
Let me know if you'd like a different approach!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then can you create a GitHub action to create the base image using your docker file and refer that base image in build.gradle.

Ensure creating base image that supports multiple architectures like current image does.

@zeel2104 zeel2104 force-pushed the fix/command-injection-ping-540 branch 2 times, most recently from 74fea99 to 56be25f Compare March 24, 2026 05:01
@zeel2104 zeel2104 force-pushed the fix/command-injection-ping-540 branch from 56be25f to 52e31d1 Compare March 24, 2026 05:02
Comment thread Dockerfile.base Outdated

RUN apk add --no-cache iputils

FROM eclipse-temurin:17-jre-jammy AS ci
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need jammy? I think line 1 and 3 would be enough.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i.e.
FROM eclipse-temurin:17-jre-alpine
RUN apk add --no-cache iputils

Comment thread build.gradle Outdated
}
}

def isLocalJibDockerBuild =
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think in all the cases we can just rely on base image in docker hub instead of local builds. I think you added this to make testing easier for baseclass but i think we are just adding iputils package so we don't need this.

Comment thread build.gradle Outdated
image = 'eclipse-temurin:17-jre-alpine'
// Local builds still use a Docker daemon image so contributors can iterate
// without publishing anything first.
image = isLocalJibDockerBuild
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

always choose the built image name that we will build using docker.yml

Comment thread .github/workflows/docker.yml Outdated
./gradlew jib \
-Djib.to.image=sasanlabs/owasp-vulnerableapp:unreleased \
-Djib.to.tags=$GITVERSION_SEMVER,latest
-Pvulnerableapp.base.image=${BASE_IMAGE}:${{ steps.gitversion.outputs.semver }} \
Copy link
Copy Markdown
Member

@preetkaran20 preetkaran20 Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think if we update build.gradle, we can remove this part and make it simple.

Copy link
Copy Markdown
Member

@preetkaran20 preetkaran20 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the change.

@zeel2104
Copy link
Copy Markdown
Contributor Author

Updated this based on the review feedback:

  • simplified Dockerfile.base to a single Alpine image with iputils
  • updated build.gradle to always use the published DockerHub base image
  • removed the extra Jib base-image override from docker.yml

I also reran the local Gradle build and it passed.

Copy link
Copy Markdown
Member

@preetkaran20 preetkaran20 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Thank you. Merging the PR now.

@preetkaran20 preetkaran20 merged commit 4010158 into SasanLabs:master Mar 28, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Command Injection throws Ping not found error

3 participants