Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
121 commits
Select commit Hold shift + click to select a range
5532b56
java4shell: knowledge table for CVE-2026-114938 with sources
devGregA Nov 17, 2026
d96bc7f
java4shell: detector for Java runtimes, images and source trees (WIP,…
devGregA Nov 17, 2026
feddaa8
java4shell: unit tests for the VM library reader, verdicts, mitigatio…
devGregA Nov 17, 2026
e9a55c2
java4shell: source-tree scan and fix tests, fuzzers in CI
devGregA Nov 17, 2026
9c2e11d
java4shell: record the observed out-of-bounds write per release and m…
devGregA Nov 17, 2026
817730e
java4shell: parity fixtures, results and README
devGregA Nov 17, 2026
f8f171f
java4shell: Tomcat setenv.sh covers the JVM catalina.sh starts
devGregA Nov 17, 2026
2b2e44f
java4shell: fixes from an independent review
devGregA Nov 17, 2026
abd7c21
java4shell: the lead's advisory facts, Oracle's Java 8 Performance Pa…
devGregA Nov 18, 2026
142c824
java4shell: read musl version lines; never clear on the release file …
devGregA Nov 18, 2026
024e781
java4shell: builds before the fixed build and pre-release JDKs are no…
devGregA Nov 18, 2026
d03d317
java4shell: a mitigated runtime stays vulnerable
devGregA Nov 18, 2026
300fa30
java4shell: a command that turns the decoder back on voids the mitiga…
devGregA Nov 18, 2026
0545fd2
java4shell: settings files count only what the launcher passes to java
devGregA Nov 18, 2026
1fdfa6e
java4shell: cap what one target makes the detector keep
devGregA Nov 18, 2026
e96edfa
java4shell: more install syntax, vendor packages and version names
devGregA Nov 18, 2026
66a4124
java4shell: fix states the checked digest, refuses shared ARGs, keeps…
devGregA Nov 18, 2026
48cd303
java4shell: partly read images, guarded platform lookup, JDK archives
devGregA Nov 18, 2026
a092f13
java4shell: word the CVE-to-fix mapping as inferred and drop certaint…
devGregA Nov 18, 2026
f9666e5
java4shell: registry-path tests, more fuzzers, crash-log bounds, dead…
devGregA Nov 18, 2026
384b1d0
java4shell: parity asserts where each version came from; musl and bui…
devGregA Nov 18, 2026
611e73f
java4shell: OpenJ9 only from an OpenJ9 VM library
devGregA Nov 18, 2026
c389540
java4shell: self-built JDKs are unknown at a build boundary; -LTS is …
devGregA Nov 18, 2026
fc57271
java4shell: a closer model of setenv.sh
devGregA Nov 18, 2026
d110598
java4shell: runtime downloads recorded by name; plain units do not co…
devGregA Nov 18, 2026
5fcfc22
java4shell: package names only as install arguments
devGregA Nov 18, 2026
be4c798
java4shell: compare the base OS on every image move, by distribution …
devGregA Nov 18, 2026
416c81d
java4shell: dates from the knowledge package; wording nits
devGregA Nov 18, 2026
7427e27
java4shell: install forms the argument parser dropped
devGregA Nov 18, 2026
accee68
engine: contain a panic in VisitHead like one in Visit
devGregA Nov 18, 2026
e03713f
java4shell: the os-release probe keeps to --max-file-size
devGregA Nov 18, 2026
25ea009
java4shell: setenv.sh stops at return or exit; an exec of java that u…
devGregA Nov 18, 2026
88646ff
java4shell: Ubuntu YY.04 and YY.10 are different bases
devGregA Nov 18, 2026
881f5be
java4shell: apk @repo tags and package names with a variable for the …
devGregA Nov 18, 2026
11572af
Build with Go 1.27.4 for GO-2026-6859 (net/http)
devGregA Nov 18, 2026
62f3d8b
Build the image with Go 1.27.4 too
devGregA Nov 18, 2026
f2f83ca
engine: a detector's own size limit keeps a larger file from being read
devGregA Nov 18, 2026
04f572b
java4shell: a size limit for each file kept, so a larger one is never…
devGregA Nov 18, 2026
60f76ec
sshole: a size limit for start scripts and kept files, so a larger on…
devGregA Nov 18, 2026
21206aa
source: fuzz Tar with a reader's own limit
devGregA Nov 18, 2026
aef1de9
engine: name each detector's limit in the record; detector IDs looked…
devGregA Nov 18, 2026
e6b1ea2
java4shell: test five-part and vendor patch versions on every path
devGregA Nov 18, 2026
d919f43
java4shell: gofmt the five-part tests
devGregA Nov 18, 2026
2e9c7fa
java4shell: judge GraalVM as GraalVM
devGregA Nov 18, 2026
03c6dab
java4shell: Red Hat backport table, RHEL layout and UBI images
devGregA Nov 18, 2026
9d8d108
java4shell: CVSS 8.1, the advisories, and vendor status of 2026-11-18
devGregA Nov 18, 2026
e4a4ec6
java4shell: fuzz the rpm comparison and seed the new repo forms
devGregA Nov 18, 2026
544c765
parity: java4shell GraalVM CE images, Debian sid five-part package, R…
devGregA Nov 18, 2026
0fefb5e
engine: over-limit files recorded per detector; LimitVisitor; Exists …
devGregA Nov 18, 2026
afd68ce
sshole: a file the verdict reads over the limit is a gap and never cl…
devGregA Nov 18, 2026
3cdfdb0
java4shell: a JVM settings file over the limit is a coverage gap
devGregA Nov 18, 2026
b4caaa1
java4shell: Red Hat rows clear only a confirmed build of their own st…
devGregA Nov 18, 2026
eae6a1b
java4shell: gofmt
devGregA Nov 18, 2026
9c5261b
java4shell: GraalVM's own numbers clear only what was checked (review…
devGregA Nov 18, 2026
9ac80cf
java4shell: rpm installs the repo scan dropped or cleared; Microsoft'…
devGregA Nov 18, 2026
54e60ef
java4shell: test a GraalVM row whose first fixed build follows OpenJD…
devGregA Nov 18, 2026
0a5bdf6
java4shell: FACTS.md corrections from the review (F5)
devGregA Nov 18, 2026
3e89cbc
README: the Red Hat table's stream and witness rules
devGregA Nov 18, 2026
18a6b9d
emudhra: botocore's bundle is cleared only on a certifi bundle that w…
devGregA Nov 18, 2026
563ee5e
engine: files over --max-file-size are told to the detectors that wan…
devGregA Nov 18, 2026
b94f7bf
sshole: never clear on a start script or include it did not read; gap…
devGregA Nov 18, 2026
c146f59
java4shell: no 'mitigated' when the command's start script was not read
devGregA Nov 18, 2026
7c1b4c7
java4shell: a Red Hat row needs RHEL; a library that is not the row's…
devGregA Nov 18, 2026
fc0cb55
java4shell: carry the build after a patch number; six-number rpm vers…
devGregA Nov 18, 2026
964b16c
java4shell: rpm and dnf forms that gave nothing (round 2, item 2)
devGregA Nov 18, 2026
0895c71
java4shell: GraalVM clears capped at the releases looked at; rows per…
devGregA Nov 18, 2026
f895079
java4shell: numbers that are not Java versions are not checked anywhe…
devGregA Nov 18, 2026
314ecc2
java4shell: gofmt
devGregA Nov 18, 2026
e4124bd
java4shell: asdf musl/jre/lite names; unsettled version-file pins are…
devGregA Nov 18, 2026
a359b55
java4shell: gofmt
devGregA Nov 18, 2026
ab1c8b3
java4shell: six-number versions are judged by their update (round 3, …
devGregA Nov 18, 2026
6213ff8
java4shell: carry +N builds in asdf, mise and jenv names, and Corrett…
devGregA Nov 18, 2026
4766b4b
java4shell: Java package files and patterns no reader knows are not c…
devGregA Nov 18, 2026
f0fdcf8
java4shell: javafx/crac, GA and EA names, Corretto apk, Zulu and JBR …
devGregA Nov 18, 2026
8db5550
engine: files met but not read are told to detectors; duplicate entri…
devGregA Nov 18, 2026
4c64e50
sshole: never clear on what could not be read; a start script behind …
devGregA Nov 18, 2026
9f7b3eb
java4shell: settings gaps only with a runtime; unread files and dupli…
devGregA Nov 18, 2026
5c027ef
emudhra: forget an earlier entry for a path an image names again
devGregA Nov 18, 2026
eb09dd4
brotli, php2shell: forget an earlier entry for a path an image names …
devGregA Nov 18, 2026
14f6a40
java4shell: '=' in package file paths; mise short versions are moving…
devGregA Nov 18, 2026
945eb05
java4shell: gofmt
devGregA Nov 18, 2026
74156bb
sshole: start scripts that start sshd in different ways are each judg…
devGregA Nov 18, 2026
805ecd5
image: flatten layers with paths relative to the root; first entry wi…
devGregA Nov 18, 2026
2ca3f48
sshole: what a directory that cannot be listed hides is unknown
devGregA Nov 18, 2026
fa555cc
engine, java4shell, emudhra: forgetting a path costs what it held
devGregA Nov 18, 2026
86e15b4
engine: one skip record per path
devGregA Nov 18, 2026
54b3716
engine: FuzzLimits checks the one record per path, with the input tha…
devGregA Nov 18, 2026
c2a4031
image: agree with a docker export on deep symlinks, hard links to hid…
devGregA Nov 18, 2026
11cb3fe
sshole: a script the command passes as an argument does not clear on …
devGregA Nov 18, 2026
5a2f1af
Merge commit '945eb057ae5183d8d54bc9ffd6eb0e272b63652f' into night-j4…
devGregA Nov 18, 2026
a941b18
java4shell: a Red Hat row does not clear on /usr/lib/os-release when …
devGregA Nov 18, 2026
5ff3529
java4shell: nor when /etc could not be listed
devGregA Nov 18, 2026
c18c7e1
java4shell: /usr/lib/os-release speaks for the target only when /etc/…
devGregA Nov 18, 2026
ab9090c
sshole: what the command passes as an argument never lowers the verdict
devGregA Nov 18, 2026
8ae698a
image: a backslash in an entry name is a character, not a separator
devGregA Nov 18, 2026
187a274
engine, emudhra, brotli, php2shell: a member is forgotten with the fi…
devGregA Nov 18, 2026
2c2d19b
image: a file written through a lower layer's link stays read
devGregA Nov 18, 2026
f6b7ae9
engine: a path named again under a directory that was a link is not f…
devGregA Nov 18, 2026
6748a50
java4shell: every VM library of a runtime is judged; the worst verdic…
devGregA Nov 18, 2026
7275259
java4shell: a VM library that is a link to a file with another name m…
devGregA Nov 18, 2026
b55ad82
java4shell: past the cap on VM libraries the scan clears nothing
devGregA Nov 18, 2026
ba373e0
java4shell: one string does not make a runtime OpenJ9
devGregA Nov 18, 2026
aa47625
java4shell: no mitigation is reported past a start script that was no…
devGregA Nov 18, 2026
80ac050
java4shell, refs: a RUN that installs Java is read the way the builde…
devGregA Nov 18, 2026
1a69140
java4shell: image references, directories and rpm names the source-tr…
devGregA Nov 18, 2026
657a46a
java4shell: a version file or setup-java step this scan cannot read i…
devGregA Nov 18, 2026
37dd76b
java4shell: Jib, buildpack and toolchain settings are read across lin…
devGregA Nov 18, 2026
fe38fc8
java4shell: fix says what was not checked and does not change a .env …
devGregA Nov 18, 2026
8dbc868
java4shell: FACTS.md says how several VM libraries, linked libraries …
devGregA Nov 18, 2026
7f25a68
ci: fuzz FuzzFlatten, FuzzLimits and FuzzRPM like the other fuzzers
devGregA Nov 18, 2026
e257b1a
java4shell: README and FACTS.md match the sources: 43 parity cases, C…
devGregA Nov 18, 2026
e0356fb
sshole: a -c after the shell's script, a script found on PATH and an …
devGregA Nov 18, 2026
18539ac
java4shell: a VM library that was not read or cannot be judged never …
devGregA Nov 18, 2026
a83f30a
java4shell: a Compose build argument is judged, not marked on every D…
devGregA Nov 18, 2026
edb2f90
refs, java4shell: a Dockerfile the parser refuses is still read, and …
devGregA Nov 18, 2026
8380f0b
image, engine: writes through a link are settled by following the lin…
devGregA Nov 18, 2026
f914c97
java4shell: Jib's base image wherever the from block has it, BP_JVM_V…
devGregA Nov 18, 2026
74bac0e
java4shell: the large-Dockerfile test does not bound allocations unde…
devGregA Nov 18, 2026
03747ba
Merge branch 'worktree-j4s-pr9-docs' into worktree-j4s-pr9-final-head
devGregA Nov 18, 2026
0196e2b
README: a VM library that was not read or cannot be judged makes the …
devGregA Nov 18, 2026
d465d6c
java4shell: the catalog names the CPUs as README and FACTS.md do
devGregA Nov 18, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ jobs:
run: |
go test ./internal/source -run '^$' -fuzz '^FuzzTar$' -fuzztime 30s
go test ./internal/archive -run '^$' -fuzz '^FuzzWalk$' -fuzztime 30s
go test ./internal/image -run '^$' -fuzz '^FuzzFlatten$' -fuzztime 30s
go test ./internal/engine -run '^$' -fuzz '^FuzzLimits$' -fuzztime 30s
go test ./detectors/emudhra/internal/detect -run '^$' -fuzz '^FuzzScan$' -fuzztime 30s
go test ./detectors/php2shell/internal/detect -run '^$' -fuzz '^FuzzInspect$' -fuzztime 20s
go test ./detectors/brotli/internal/fingerprint -run '^$' -fuzz '^FuzzFingerprint$' -fuzztime 30s
Expand All @@ -33,6 +35,16 @@ jobs:
go test ./detectors/sshole/internal/assess -run '^$' -fuzz '^FuzzAccounts$' -fuzztime 30s
go test ./detectors/sshole/internal/assess -run '^$' -fuzz '^FuzzStartup$' -fuzztime 30s
go test ./detectors/sshole/internal/repo -run '^$' -fuzz '^FuzzScanText$' -fuzztime 30s
go test ./detectors/java4shell/internal/jvm -run '^$' -fuzz '^FuzzInspect$' -fuzztime 30s
go test ./detectors/java4shell/internal/jvm -run '^$' -fuzz '^FuzzSettings$' -fuzztime 30s
go test ./detectors/java4shell/internal/knowledge -run '^$' -fuzz '^FuzzParse$' -fuzztime 20s
go test ./detectors/java4shell/internal/knowledge -run '^$' -fuzz '^FuzzRPM$' -fuzztime 15s
go test ./detectors/java4shell/internal/repo -run '^$' -fuzz '^FuzzScanText$' -fuzztime 30s
go test ./detectors/java4shell/internal/jvm -run '^$' -fuzz '^FuzzParseRelease$' -fuzztime 15s
go test ./detectors/java4shell/internal/assess -run '^$' -fuzz '^FuzzAPKOwners$' -fuzztime 15s
go test ./detectors/java4shell/internal/assess -run '^$' -fuzz '^FuzzDpkgOwners$' -fuzztime 15s
go test ./detectors/java4shell/internal/assess -run '^$' -fuzz '^FuzzRun$' -fuzztime 30s
go test ./detectors/java4shell -run '^$' -fuzz '^FuzzReadCrash$' -fuzztime 15s
for f in FuzzParseDpkgStatus FuzzParseAPKInstalled FuzzParseHeaderBlob FuzzReadBDB FuzzReadNDB FuzzResolver; do
go test ./detectors/php2shell/internal/pkgdb -run '^$' -fuzz "^$f\$" -fuzztime 15s
done
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.27.3 AS build
FROM golang:1.27.4 AS build
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
Expand Down
11 changes: 10 additions & 1 deletion README.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions detectors/all/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package all
import (
_ "github.com/DefectDojo/earlylight/detectors/brotli"
_ "github.com/DefectDojo/earlylight/detectors/emudhra"
_ "github.com/DefectDojo/earlylight/detectors/java4shell"
_ "github.com/DefectDojo/earlylight/detectors/php2shell"
_ "github.com/DefectDojo/earlylight/detectors/sshole"
)
37 changes: 34 additions & 3 deletions detectors/brotli/brotli.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,52 @@ func (d *Detector) Wants(_ string, head []byte, _ bool) bool {
}

// NewScan starts a filesystem or image scan.
func (d *Detector) NewScan(engine.TargetKind) engine.Scan { return &scan{} }
func (d *Detector) NewScan(engine.TargetKind) engine.Scan { return &scan{foundIn: map[string][]int{}} }

type scan struct {
findings []engine.Finding
// foundIn indexes findings by the file the walk met (a member under
// the file that holds it); gone marks those a later entry dropped.
foundIn map[string][]int
gone []bool
}

type scan struct{ findings []engine.Finding }
// Forget drops what was found in p, and inside it: an image names it
// again, and the last entry is the file. "Inside it" is what the engine
// said is a member of p, not a path that starts the same way (a directory
// can be named "app!"). It costs what p held, not every finding.
func (s *scan) Forget(p string) {
for _, i := range s.foundIn[p] {
s.gone[i] = true
}
delete(s.foundIn, p)
}

func (s *scan) Visit(f engine.File) []engine.Skip {
if !archive.IsExecutable(f.Data) && !fingerprint.IsWasm(f.Data) {
return nil
}
if x, ok := assess.File(f.Path, f.Data); ok {
outer := f.Path
if f.Member && f.Outer != "" {
outer = f.Outer
}
s.foundIn[outer] = append(s.foundIn[outer], len(s.findings))
s.findings = append(s.findings, finding(x))
s.gone = append(s.gone, false)
}
return nil
}

func (s *scan) Finish(engine.TargetContext) []engine.Finding { return s.findings }
func (s *scan) Finish(engine.TargetContext) []engine.Finding {
out := make([]engine.Finding, 0, len(s.findings))
for i, f := range s.findings {
if !s.gone[i] {
out = append(out, f)
}
}
return out
}

var verdicts = map[assess.Status]engine.Verdict{
assess.Vulnerable: engine.Vulnerable,
Expand Down
68 changes: 68 additions & 0 deletions detectors/brotli/forget_internal_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package brotli

import (
"fmt"
"testing"
"time"

"github.com/DefectDojo/earlylight/detectors/brotli/internal/testbin"
"github.com/DefectDojo/earlylight/internal/engine"
)

var vulnerable = testbin.ELF([]testbin.Symbol{{Name: "BrotliDecoderDecompressStream", Defined: true}}, testbin.Table("1.0.9"))

func testbinFixed() []byte {
return testbin.ELF([]testbin.Symbol{{Name: "BrotliDecoderDecompressStream", Defined: true}}, testbin.Table("1.2.1"))
}

func paths(fs []engine.Finding) string {
var out []string
for _, f := range fs {
out = append(out, f.Path)
}
return fmt.Sprint(out)
}

// When an image names a path again, what was found in the first entry,
// and inside it, is dropped. Final review A3: "inside it" is what the
// engine says is a member of it, not a path that starts the same way: a
// directory named "a!" next to a file "a" is not an archive.
func TestForget(t *testing.T) {
s := (&Detector{}).NewScan(engine.Image).(*scan)
s.Visit(engine.File{Path: "/a", Data: vulnerable})
s.Visit(engine.File{Path: "/a!/x.so", Data: vulnerable, Member: true, Outer: "/a"})
s.Visit(engine.File{Path: "/ab", Data: vulnerable})
s.Visit(engine.File{Path: "/b", Data: vulnerable})
s.Visit(engine.File{Path: "/opt/app", Data: []byte("hello")})
s.Visit(engine.File{Path: "/opt/app!/libbrotlidec.so.1", Data: vulnerable}) // a file in the directory "app!"
s.Forget("/a")
s.Forget("/opt/app")
if got := paths(s.Finish(nil)); got != "[/ab /b /opt/app!/libbrotlidec.so.1]" {
t.Errorf("after Forget: %s", got)
}
s.Forget("/opt/app!/libbrotlidec.so.1")
s.Visit(engine.File{Path: "/a", Data: vulnerable})
if got := paths(s.Finish(nil)); got != "[/ab /b /a]" {
t.Errorf("after the second Forget: %s", got)
}
}

// Final review A6: forgetting a path costs what the path held, not every
// finding kept.
func TestForgetIsCheap(t *testing.T) {
s := (&Detector{}).NewScan(engine.Image).(*scan)
for i := 0; i < 20000; i++ {
s.Visit(engine.File{Path: fmt.Sprintf("/lib/%d.so", i), Data: vulnerable})
}
start := time.Now()
for i := 0; i < 100000; i++ {
s.Forget("/x")
s.Visit(engine.File{Path: "/x", Data: []byte("x")})
}
if d := time.Since(start); d > 5*time.Second {
t.Errorf("100,000 repeats over 20,000 findings took %s", d)
}
if n := len(s.Finish(nil)); n != 20000 {
t.Errorf("%d findings, want 20000", n)
}
}
217 changes: 217 additions & 0 deletions detectors/brotli/layers_internal_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
package brotli

import (
"archive/tar"
"bytes"
"io"
"os"
"path/filepath"
"testing"

"github.com/google/go-containerregistry/pkg/name"
v1 "github.com/google/go-containerregistry/pkg/v1"
"github.com/google/go-containerregistry/pkg/v1/empty"
"github.com/google/go-containerregistry/pkg/v1/mutate"
"github.com/google/go-containerregistry/pkg/v1/tarball"

"github.com/DefectDojo/earlylight/internal/engine"
)

// entry is one layer entry: a file with data, a directory (dir) or a
// symbolic link (link).
type entry struct {
name string
data []byte
dir bool
link string
}

func archiveOf(t *testing.T, layers ...[]entry) string {
t.Helper()
var ls []v1.Layer
for _, es := range layers {
var buf bytes.Buffer
tw := tar.NewWriter(&buf)
for _, e := range es {
h := &tar.Header{Name: e.name, Mode: 0o755, Typeflag: tar.TypeReg, Size: int64(len(e.data))}
switch {
case e.dir:
h.Typeflag = tar.TypeDir
case e.link != "":
h.Typeflag, h.Linkname = tar.TypeSymlink, e.link
}
if err := tw.WriteHeader(h); err != nil {
t.Fatal(err)
}
tw.Write(e.data)
}
tw.Close()
b := buf.Bytes()
l, err := tarball.LayerFromOpener(func() (io.ReadCloser, error) { return io.NopCloser(bytes.NewReader(b)), nil })
if err != nil {
t.Fatal(err)
}
ls = append(ls, l)
}
img, err := mutate.AppendLayers(empty.Image, ls...)
if err != nil {
t.Fatal(err)
}
p := filepath.Join(t.TempDir(), "image.tar")
if err := tarball.WriteToFile(p, name.MustParseReference("test/brotli:1"), img); err != nil {
t.Fatal(err)
}
return p
}

// Final review A4: an image whose upper layer names a library as it is
// written, lib/libbrotlidec.so.1, over a base where lib is a link to
// usr/lib (crane append, Bazel, Jib): the container has the library, and
// the scan reports it. The path it landed on is a coverage gap.
func TestWrittenThroughALink(t *testing.T) {
p := archiveOf(t,
[]entry{{name: "usr", dir: true}, {name: "usr/lib", dir: true}, {name: "lib", link: "usr/lib"}, {name: "usr/lib/other", data: []byte("x")}},
[]entry{{name: "lib/libbrotlidec.so.1", data: vulnerable}})
tg := engine.ScanImage([]engine.Detector{&Detector{}}, "docker-archive:"+p, engine.Options{})
if tg.Error != "" || len(tg.Findings) != 1 || tg.Findings[0].Verdict != engine.Vulnerable || tg.Findings[0].Path != "/lib/libbrotlidec.so.1" {
t.Errorf("error %q findings %+v", tg.Error, tg.Findings)
}
if len(tg.Skipped) != 1 || tg.Skipped[0].Path != "/usr/lib/libbrotlidec.so.1" || tg.Gaps() != 1 {
t.Errorf("skipped %+v", tg.Skipped)
}
// A lower file at the path it landed on was replaced: what it held is
// forgotten, the file written through the link is kept.
fixed := testbinFixed()
p = archiveOf(t,
[]entry{{name: "usr/lib", dir: true}, {name: "lib", link: "usr/lib"}, {name: "usr/lib/libbrotlidec.so.1", data: fixed}},
[]entry{{name: "lib/libbrotlidec.so.1", data: vulnerable}})
tg = engine.ScanImage([]engine.Detector{&Detector{}}, "docker-archive:"+p, engine.Options{})
if len(tg.Findings) != 1 || tg.Findings[0].Verdict != engine.Vulnerable || tg.Findings[0].Path != "/lib/libbrotlidec.so.1" {
t.Errorf("replaced through the link: findings %+v", tg.Findings)
}
// A higher layer then names the real path: that entry is the file, and
// what was written through the link before it is forgotten.
p = archiveOf(t,
[]entry{{name: "usr/lib", dir: true}, {name: "lib", link: "usr/lib"}},
[]entry{{name: "lib/libbrotlidec.so.1", data: fixed}},
[]entry{{name: "usr/lib/libbrotlidec.so.1", data: vulnerable}})
tg = engine.ScanImage([]engine.Detector{&Detector{}}, "docker-archive:"+p, engine.Options{})
if len(tg.Findings) != 1 || tg.Findings[0].Verdict != engine.Vulnerable || tg.Findings[0].Path != "/usr/lib/libbrotlidec.so.1" || tg.Gaps() != 1 {
t.Errorf("the real path written afterwards: findings %+v skipped %+v", tg.Findings, tg.Skipped)
}
// Written both ways in one layer: the layer's order decides, and the
// later entry is the file.
p = archiveOf(t,
[]entry{{name: "usr/lib", dir: true}, {name: "lib", link: "usr/lib"}},
[]entry{{name: "lib/libbrotlidec.so.1", data: fixed}, {name: "usr/lib/libbrotlidec.so.1", data: vulnerable}})
tg = engine.ScanImage([]engine.Detector{&Detector{}}, "docker-archive:"+p, engine.Options{})
if len(tg.Findings) != 1 || tg.Findings[0].Verdict != engine.Vulnerable || tg.Findings[0].Path != "/usr/lib/libbrotlidec.so.1" || tg.Gaps() != 1 {
t.Errorf("written both ways: findings %+v skipped %+v", tg.Findings, tg.Skipped)
}
}

// Second final review, finding 2: layer layouts where the container has
// the vulnerable library (checked with docker load and docker export) and
// the scan reported only a coverage gap, exit 0, where main reports the
// library. Each is settled now: by following the links as the runtime did,
// by the order of a layer's entries, or by reading both entries a layer
// has for one path.
func TestLayersThatDroppedAFinding(t *testing.T) {
fixed := testbinFixed()
const lib = "libbrotlidec.so.1"
for name, c := range map[string]struct {
layers [][]entry
want string // the path of the one vulnerable finding
}{
"a link chain": {[][]entry{
{{name: "opt/real", dir: true}, {name: "usr", dir: true}, {name: "usr/lib", link: "../opt/real"}, {name: "lib", link: "usr/lib"}},
{{name: "lib/" + lib, data: vulnerable}}}, "/lib/" + lib},
"a link to the root, over a clean file": {[][]entry{
{{name: "r", link: "/"}, {name: "usr/lib", dir: true}, {name: "usr/lib/" + lib, data: fixed}},
{{name: "r/usr/lib/" + lib, data: vulnerable}}}, "/r/usr/lib/" + lib},
".. across a link: the clean file lands elsewhere": {[][]entry{
{{name: "opt/real", dir: true}, {name: "opt/lib64", dir: true}, {name: "usr/lib", link: "/opt/real"}, {name: "lib", link: "usr/lib/../lib64"},
{name: "usr/lib64", dir: true}, {name: "usr/lib64/" + lib, data: vulnerable}},
{{name: "lib/" + lib, data: fixed}}}, "/usr/lib64/" + lib},
"both names in one layer, the real path last": {[][]entry{
{{name: "usr/lib", dir: true}, {name: "lib", link: "usr/lib"}},
{{name: "lib/" + lib, data: vulnerable}, {name: "usr/lib/" + lib, data: vulnerable}}}, "/usr/lib/" + lib},
"both names in one layer, the link's last": {[][]entry{
{{name: "usr/lib", dir: true}, {name: "lib", link: "usr/lib"}},
{{name: "usr/lib/" + lib, data: vulnerable}, {name: "lib/" + lib, data: vulnerable}}}, "/lib/" + lib},
"two links to one directory": {[][]entry{
{{name: "usr/lib", dir: true}, {name: "lib", link: "usr/lib"}, {name: "lib64", link: "usr/lib"}},
{{name: "lib/" + lib, data: vulnerable}},
{{name: "lib64/" + lib, data: vulnerable}}}, "/lib64/" + lib},
"one path twice in one layer": {[][]entry{
{{name: "usr/lib", dir: true}, {name: "usr/lib/" + lib, data: vulnerable}, {name: "usr/lib/" + lib, data: vulnerable}}}, "/usr/lib/" + lib},
"one path twice in one layer, clean then vulnerable": {[][]entry{
{{name: "usr/lib", dir: true}, {name: "usr/lib/" + lib, data: fixed}, {name: "usr/lib/" + lib, data: vulnerable}}}, "/usr/lib/" + lib},
} {
tg := engine.ScanImage([]engine.Detector{&Detector{}}, "docker-archive:"+archiveOf(t, c.layers...), engine.Options{})
var got []string
for _, f := range tg.Findings {
if f.Verdict == engine.Vulnerable {
got = append(got, f.Path)
}
}
if tg.Error != "" || len(got) != 1 || got[0] != c.want {
t.Errorf("%s: error %q, vulnerable at %v, want %s (findings %+v, skipped %+v)", name, tg.Error, got, c.want, tg.Findings, tg.Skipped)
}
}
// The last entry is the file the other way round too: vulnerable then
// clean in one layer is clean.
tg := engine.ScanImage([]engine.Detector{&Detector{}}, "docker-archive:"+archiveOf(t,
[]entry{{name: "usr/lib", dir: true}, {name: "usr/lib/" + lib, data: vulnerable}, {name: "usr/lib/" + lib, data: fixed}}), engine.Options{})
if tg.Error != "" || tg.Count(engine.Vulnerable) != 0 || tg.Gaps() != 0 {
t.Errorf("vulnerable then clean in one layer: findings %+v skipped %+v", tg.Findings, tg.Skipped)
}
}

// Final review A5: a docker export names d/lib twice, and d is a link that
// points somewhere else by the second time: the two entries are two files
// (e/lib and o/lib), so the first is not forgotten.
func TestNamedAgainThroughAMovedLink(t *testing.T) {
export := func(es ...entry) string {
var buf bytes.Buffer
tw := tar.NewWriter(&buf)
for _, e := range es {
h := &tar.Header{Name: e.name, Mode: 0o755, Typeflag: tar.TypeReg, Size: int64(len(e.data))}
switch {
case e.dir:
h.Typeflag = tar.TypeDir
case e.link != "":
h.Typeflag, h.Linkname = tar.TypeSymlink, e.link
}
if err := tw.WriteHeader(h); err != nil {
t.Fatal(err)
}
tw.Write(e.data)
}
tw.Close()
p := filepath.Join(t.TempDir(), "rootfs.tar")
if err := os.WriteFile(p, buf.Bytes(), 0o600); err != nil {
t.Fatal(err)
}
return p
}
clean := []byte("clean")
for name, c := range map[string]struct {
entries []entry
want int
}{
"the link moves": {[]entry{{name: "e", dir: true}, {name: "o", dir: true}, {name: "d", link: "e"}, {name: "d/libbrotlidec.so.1", data: vulnerable},
{name: "d", link: "o"}, {name: "d/libbrotlidec.so.1", data: clean}}, 1},
"a link above moves": {[]entry{{name: "e/s", dir: true}, {name: "o/s", dir: true}, {name: "d", link: "e"}, {name: "d/s/libbrotlidec.so.1", data: vulnerable},
{name: "d", link: "o"}, {name: "d/s/libbrotlidec.so.1", data: clean}}, 1},
"the link becomes a directory": {[]entry{{name: "e", dir: true}, {name: "d", link: "e"}, {name: "d/libbrotlidec.so.1", data: vulnerable},
{name: "d", dir: true}, {name: "d/libbrotlidec.so.1", data: clean}}, 1},
// No link: the last entry is the file.
"a plain directory": {[]entry{{name: "d", dir: true}, {name: "d/libbrotlidec.so.1", data: vulnerable}, {name: "d/libbrotlidec.so.1", data: clean}}, 0},
} {
tg := engine.ScanImage([]engine.Detector{&Detector{}}, "rootfs:"+export(c.entries...), engine.Options{})
if tg.Error != "" || len(tg.Findings) != c.want {
t.Errorf("%s: error %q, %d findings, want %d: %+v", name, tg.Error, len(tg.Findings), c.want, tg.Findings)
}
}
}
Loading
Loading