Skip to content

Commit 5944797

Browse files
New 'python' samples to test for edge case 'from' statements on files without extension or within docker folder, adjusted readPossibleDockerfile to an improved regex based logic, adjusted file.Dockerfile to test for whitespaces before a from statement
1 parent 264839f commit 5944797

4 files changed

Lines changed: 15 additions & 2 deletions

File tree

pkg/utils/get_extension.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"os"
77
"path/filepath"
8+
"regexp"
89
"strings"
910

1011
"github.com/Checkmarx/kics/v2/internal/constants"
@@ -85,7 +86,8 @@ func readPossibleDockerFile(path string) bool {
8586
if strings.HasPrefix(scanner.Text(), "#") || strings.HasPrefix(strings.ToLower(scanner.Text()), "arg") || scanner.Text() == "" {
8687
continue
8788
} else {
88-
return strings.HasPrefix(strings.ToLower(scanner.Text()), "from ")
89+
matched, _ := regexp.MatchString(`(?i)FROM\s+\S+(\s*$|\s+AS\s+\S+\s*$)`, scanner.Text())
90+
return matched
8991
}
9092
}
9193
return false

test/fixtures/dockerfile/case_insensitive_tests/file.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ arg BASE_IMAGE=ubuntu:22.04
33

44
# Comments after arg
55

6-
from alpine:3.19 as builder
6+
from alpine:3.19 as builder
77

88
copy . .
99

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from urllib import request
2+
3+
def main():
4+
print("coiso")
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from urllib import request
2+
3+
def main():
4+
print("coiso")
5+
# I love the RUN docker funtion and the FROM too
6+
7+

0 commit comments

Comments
 (0)