fix(score): replace hardcoded config score with real Dockerfile analysis (closes #44)#53
Merged
Merged
Conversation
… analysis The configuration dimension of the security score was permanently set to 75.0, inflating every reported score by ~15 points regardless of actual Dockerfile quality. This fix implements _calculate_config_score() which analyses the Dockerfile content directly and deducts points for: - Container running as root (no USER directive, or USER root/0): -25 - Exposed credentials via ENV (PASSWORD/SECRET/TOKEN/KEY patterns): -30 - Mutable base image tag (:latest or untagged FROM): -15 - Missing HEALTHCHECK directive: -10 - Sensitive port exposure (22, 23, 3306, 5432, 27017, 6379, 9200): -10 - ADD used instead of COPY (DL3020): -5 - --privileged flag present: -20 Falls back to Hadolint output signals (DL3002, DL3007) when no Dockerfile path is available (e.g. --image-only mode). Smoke-tested: insecure Dockerfile 5/100, clean Dockerfile 100/100. Bumps version to 2026.4.2. Closes #44
d293d14 to
01922e7
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
configurationscore of75.0inscore_calculator.pywith a real_calculate_config_score()method that analyses actual Dockerfile content2026.2.23→2026.4.2for releaseWhat was wrong
Every security score DockSec ever reported was inflated by ~15 points. The 20% configuration weight always contributed a fixed
75 * 0.20 = 15points regardless of whether the container was running as root, had exposed secrets, used:latesttags, etc.What the new method checks
USERdirective / explicitUSER rootorUSER 0ENVsets a credential variable (PASSWORD,SECRET,API_KEY,TOKEN, etc.):latesttag or has no tagHEALTHCHECKdirectiveADDused instead ofCOPY--privilegedflag presentFalls back to Hadolint output signals (
DL3002,DL3007) when no Dockerfile path is available (e.g.--image-onlymode).Test results
Existing test suite: 10 passed, 7 pre-existing failures (unrelated to this change).
Test plan
docksec Dockerfile -i myapp:latestagainst a Dockerfile with noUSER,:latesttag, and an exposedENV PASSWORD=...— config score should be ≤ 30USER, pinned tag,HEALTHCHECK— config score should be 100--image-onlymode (no Dockerfile): verify no crash, fallback to hadolint signals🤖 Generated with Claude Code