Skip to content
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

fix(query): apt-get Missing '-y' To Avoid Manual Input #7060

Merged
merged 29 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
9fc4f33
fix(query): apt-get Missing '-y' To Avoid Manual Input
ArturRibeiro-CX May 17, 2024
a198481
-q & --quiet positive test addition and positive expected results update
ArturRibeiro-CX May 17, 2024
7f1d61e
Merge branch 'master' into AST-42923
ArturRibeiro-CX May 17, 2024
af00f77
update main_test with bicepParser
ArturRibeiro-CX May 17, 2024
dfd15b1
fix order issue
ArturRibeiro-CX May 17, 2024
91e698a
Update main_test.go
ArturRibeiro-CX May 17, 2024
a0997b3
update query name and description for better understanding
ArturRibeiro-CX May 17, 2024
2a136f9
Merge branch 'AST-42923' of https://github.com/Checkmarx/kics into AS…
ArturRibeiro-CX May 17, 2024
13f106e
addition of cloudProvider common as it is a required property of meta…
ArturRibeiro-CX May 17, 2024
9659e6a
change directory name and documentation to reflect query name change
ArturRibeiro-CX May 20, 2024
b5f4163
change directory name and documentation to reflect query name change
ArturRibeiro-CX May 20, 2024
b73e4c4
fix rego query changes
ArturRibeiro-CX May 20, 2024
75a0f5e
revert REGO query
ArturRibeiro-CX May 20, 2024
a5dec38
query name change from flag to flags
ArturRibeiro-CX May 20, 2024
e1712f9
fix false positive for --quiet or -q flags for manual input
ArturRibeiro-CX May 20, 2024
12dfcd9
Merge branch 'master' into AST-42923
ArturRibeiro-CX May 20, 2024
2dbfb07
fix unit tests error
ArturRibeiro-CX May 20, 2024
54fdf04
Merge branch 'master' into AST-42923
ArturRibeiro-CX May 20, 2024
1af7041
Merge branch 'master' into AST-42923
ArturRibeiro-CX May 21, 2024
c93aff7
Merge branch 'master' into AST-42923
ArturRibeiro-CX May 21, 2024
c505ad9
Merge branch 'master' into AST-42923
ArturRibeiro-CX May 22, 2024
3b25d63
Merge branch 'master' into AST-42923
ArturRibeiro-CX May 22, 2024
4f1b539
Merge branch 'master' into AST-42923
ArturRibeiro-CX May 23, 2024
d32faa9
Merge branch 'master' into AST-42923
ArturRibeiro-CX May 23, 2024
12ae8f4
Merge branch 'master' into AST-42923
ArturRibeiro-CX May 27, 2024
a6cf59a
Merge branch 'master' into AST-42923
ArturRibeiro-CX May 29, 2024
67fe8ba
Merge branch 'master' into AST-42923
ArturRibeiro-CX Jun 5, 2024
6487c54
Merge branch 'master' into AST-42923
ArturRibeiro-CX Jun 7, 2024
63e9665
update import statement to only import contains
ArturRibeiro-CX Jun 7, 2024
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
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"id": "77783205-c4ca-4f80-bb80-c777f267c547",
"queryName": "APT-GET Missing '-y' To Avoid Manual Input",
"queryName": "APT-GET Missing Flags To Avoid Manual Input",
"severity": "LOW",
"category": "Supply-Chain",
"descriptionText": "Check if apt-get calls use the flag -y to avoid user manual input.",
"descriptionText": "Check if apt-get calls use flags to avoid user manual input.",
"descriptionUrl": "https://docs.docker.com/engine/reference/builder/#run",
"platform": "Dockerfile",
"descriptionID": "2064113b",
"cloudProvider": "common",
"cwe": "710",
"oldSeverity": "MEDIUM"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package Cx

import data.generic.dockerfile as dockerLib
import future.keywords.contains

CxPolicy[result] {
resource := input.document[i].command[name][_]
resource.Cmd == "run"

count(resource.Value) == 1

commands := resource.Value[j]
command := dockerLib.getCommands(commands)[_]
isAptGet(command)

not avoidManualInput(command)

result := {
"documentId": input.document[i].id,
"searchKey": sprintf("FROM={{%s}}.{{%s}}", [name, resource.Original]),
"issueType": "IncorrectValue",
"keyExpectedValue": sprintf("{{%s}} should avoid manual input", [resource.Original]),
"keyActualValue": sprintf("{{%s}} doesn't avoid manual input", [resource.Original]),
}
}

CxPolicy[result] {
resource := input.document[i].command[name][_]
resource.Cmd == "run"

count(resource.Value) > 1

dockerLib.arrayContains(resource.Value, {"apt-get", "install"})

not avoidManualInputInList(resource.Value)

result := {
"documentId": input.document[i].id,
"searchKey": sprintf("FROM={{%s}}.{{%s}}", [name, resource.Original]),
"issueType": "IncorrectValue",
"keyExpectedValue": sprintf("{{%s}} should avoid manual input", [resource.Original]),
"keyActualValue": sprintf("{{%s}} doesn't avoid manual input", [resource.Original]),
}
}

isAptGet(command) {
regex.match("apt-get (-(-)?[a-zA-Z]+ *)*install", command)
}

avoidManualInputInList(command) {
flags := ["-y", "--yes", "--assume-yes", "-qy", "-q=2", "-qq"]
flagfound := contains(command[_], flags[_])
flagfound
} else {
flagsquiet := ["-q","--quiet"]
quietflag := {z | command[y] == flagsquiet[_]; z := y}
count(quietflag) == 2
}

avoidManualInput(command) {
regex.match("apt-get (-(-)?[a-zA-Z]+ *)*(-([A-Za-z])*y|--yes|-qq|-q=2|--assume-yes|(-q|--quiet)(.*(-q|--quiet)){1}) (-(-)?[a-zA-Z]+ *)*install", command)
}

avoidManualInput(command) {
regex.match("apt-get (-(-)?[a-zA-Z]+ *)*install (-(-)?[a-zA-Z]+ *)*(-([A-Za-z])*y|--yes|-qq|-q=2|--assume-yes|(-q|--quiet)(.*(-q|--quiet)){1})", command)
}

avoidManualInput(command) {
regex.match("apt-get (-(-)?[a-zA-Z]+ *)*install ([A-Za-z0-9\\W]+ *)*(-([A-Za-z])*y|--yes|-qq|-q=2|--assume-yes|(-q|--quiet)(.*(-q|--quiet)){1})", command)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM node:12
RUN apt-get --yes install apt-utils
RUN ["sudo", "apt-get", "--yes" ,"install", "apt-utils"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM node:12
RUN sudo apt-get -qq install apt-utils
RUN ["apt-get", "-qq", "install", "apt-utils"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM node:12
RUN apt-get --assume-yes install apt-utils
RUN ["sudo", "apt-get", "--assume-yes", "install", "apt-utils"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM node:12
RUN sudo apt-get -q=2 install apt-utils
RUN ["apt-get", "-q=2", "install", "apt-utils"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM node:12
RUN apt-get --quiet --quiet install sl
RUN ["apt-get", "--quiet", "--quiet" ,"install", "apt-utils"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM node:12
RUN apt-get -q -q install sl
RUN ["apt-get", "-q", "-q", "apt-utils"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM node:12
RUN ["sudo", "apt-get", "-q" ,"install", "apt-utils"]
RUN sudo apt-get -q install apt-utils
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM node:12
RUN ["sudo", "apt-get", "--quiet", "install", "apt-utils"]
RUN sudo apt-get --quiet install apt-utils
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM node:12
RUN sudo apt-get --quiet install sl
RUN ["apt-get", "--quiet" ,"install", "apt-utils"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM node:12
RUN sudo apt-get -q install sl
RUN ["apt-get", "-q", "install", "apt-utils"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
[
{
"queryName": "APT-GET Missing Flags To Avoid Manual Input",
"severity": "LOW",
"line": 2,
"filename": "positive1.dockerfile"
},
{
"queryName": "APT-GET Missing Flags To Avoid Manual Input",
"severity": "LOW",
"line": 3,
"filename": "positive1.dockerfile"
},
{
"queryName": "APT-GET Missing Flags To Avoid Manual Input",
"severity": "LOW",
"line": 4,
"filename": "positive1.dockerfile"
},
{
"queryName": "APT-GET Missing Flags To Avoid Manual Input",
"severity": "LOW",
"line": 2,
"filename": "positive2.dockerfile"
},
{
"queryName": "APT-GET Missing Flags To Avoid Manual Input",
"severity": "LOW",
"line": 3,
"filename": "positive2.dockerfile"
},
{
"queryName": "APT-GET Missing Flags To Avoid Manual Input",
"severity": "LOW",
"line": 4,
"filename": "positive2.dockerfile"
},
{
"queryName": "APT-GET Missing Flags To Avoid Manual Input",
"severity": "LOW",
"line": 2,
"filename": "positive3.dockerfile"
},
{
"queryName": "APT-GET Missing Flags To Avoid Manual Input",
"severity": "LOW",
"line": 2,
"filename": "positive4.dockerfile"
},
{
"queryName": "APT-GET Missing Flags To Avoid Manual Input",
"severity": "LOW",
"line": 3,
"filename": "positive4.dockerfile"
},
{
"queryName": "APT-GET Missing Flags To Avoid Manual Input",
"severity": "LOW",
"line": 3,
"filename": "positive5.dockerfile"
},
{
"queryName": "APT-GET Missing Flags To Avoid Manual Input",
"severity": "LOW",
"line": 2,
"filename": "positive5.dockerfile"
},
{
"queryName": "APT-GET Missing Flags To Avoid Manual Input",
"severity": "LOW",
"line": 3,
"filename": "positive6.dockerfile"
},
{
"queryName": "APT-GET Missing Flags To Avoid Manual Input",
"severity": "LOW",
"line": 2,
"filename": "positive6.dockerfile"
},
{
"queryName": "APT-GET Missing Flags To Avoid Manual Input",
"severity": "LOW",
"line": 3,
"filename": "positive7.dockerfile"
},
{
"queryName": "APT-GET Missing Flags To Avoid Manual Input",
"severity": "LOW",
"line": 2,
"filename": "positive7.dockerfile"
}
]

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion docs/queries/all-queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ This page contains all queries.
|WORKDIR Path Not Absolute<br/><sup><sub>6b376af8-cfe8-49ab-a08d-f32de23661a4</sub></sup>|Dockerfile|<span style="color:#edd57e">Low</span>|Build Process|<a href="../dockerfile-queries/6b376af8-cfe8-49ab-a08d-f32de23661a4" target="_blank">Query details</a><br><a href="https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#workdir">Documentation</a><br/>|
|Healthcheck Instruction Missing<br/><sup><sub>b03a748a-542d-44f4-bb86-9199ab4fd2d5</sub></sup>|Dockerfile|<span style="color:#edd57e">Low</span>|Insecure Configurations|<a href="../dockerfile-queries/b03a748a-542d-44f4-bb86-9199ab4fd2d5" target="_blank">Query details</a><br><a href="https://docs.docker.com/engine/reference/builder/#healthcheck">Documentation</a><br/>|
|Shell Running A Pipe Without Pipefail Flag<br/><sup><sub>efbf148a-67e9-42d2-ac47-02fa1c0d0b22</sub></sup>|Dockerfile|<span style="color:#edd57e">Low</span>|Insecure Defaults|<a href="../dockerfile-queries/efbf148a-67e9-42d2-ac47-02fa1c0d0b22" target="_blank">Query details</a><br><a href="https://docs.docker.com/engine/reference/builder/#run">Documentation</a><br/>|
|APT-GET Missing '-y' To Avoid Manual Input<br/><sup><sub>77783205-c4ca-4f80-bb80-c777f267c547</sub></sup>|Dockerfile|<span style="color:#edd57e">Low</span>|Supply-Chain|<a href="../dockerfile-queries/77783205-c4ca-4f80-bb80-c777f267c547" target="_blank">Query details</a><br><a href="https://docs.docker.com/engine/reference/builder/#run">Documentation</a><br/>|
|APT-GET Missing Flags To Avoid Manual Input<br/><sup><sub>77783205-c4ca-4f80-bb80-c777f267c547</sub></sup>|Dockerfile|<span style="color:#edd57e">Low</span>|Supply-Chain|<a href="../dockerfile-queries/77783205-c4ca-4f80-bb80-c777f267c547" target="_blank">Query details</a><br><a href="https://docs.docker.com/engine/reference/builder/#run">Documentation</a><br/>|
|Missing Flag From Dnf Install<br/><sup><sub>7ebd323c-31b7-4e5b-b26f-de5e9e477af8</sub></sup>|Dockerfile|<span style="color:#edd57e">Low</span>|Supply-Chain|<a href="../dockerfile-queries/7ebd323c-31b7-4e5b-b26f-de5e9e477af8" target="_blank">Query details</a><br><a href="https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#run">Documentation</a><br/>|
|Run Using 'wget' and 'curl'<br/><sup><sub>fc775e75-fcfb-4c98-b2f2-910c5858b359</sub></sup>|Dockerfile|<span style="color:#edd57e">Low</span>|Supply-Chain|<a href="../dockerfile-queries/fc775e75-fcfb-4c98-b2f2-910c5858b359" target="_blank">Query details</a><br><a href="https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#run">Documentation</a><br/>|
|Run Using apt<br/><sup><sub>b84a0b47-2e99-4c9f-8933-98bcabe2b94d</sub></sup>|Dockerfile|<span style="color:#edd57e">Low</span>|Supply-Chain|<a href="../dockerfile-queries/b84a0b47-2e99-4c9f-8933-98bcabe2b94d" target="_blank">Query details</a><br><a href="https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#run">Documentation</a><br/>|
Expand Down
2 changes: 1 addition & 1 deletion docs/queries/dockerfile-queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ This page contains all queries from Dockerfile.
|WORKDIR Path Not Absolute<br/><sup><sub>6b376af8-cfe8-49ab-a08d-f32de23661a4</sub></sup>|<span style="color:#edd57e">Low</span>|Build Process|<a href="../dockerfile-queries/6b376af8-cfe8-49ab-a08d-f32de23661a4" target="_blank">Query details</a><br><a href="https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#workdir">Documentation</a><br/>|
|Healthcheck Instruction Missing<br/><sup><sub>b03a748a-542d-44f4-bb86-9199ab4fd2d5</sub></sup>|<span style="color:#edd57e">Low</span>|Insecure Configurations|<a href="../dockerfile-queries/b03a748a-542d-44f4-bb86-9199ab4fd2d5" target="_blank">Query details</a><br><a href="https://docs.docker.com/engine/reference/builder/#healthcheck">Documentation</a><br/>|
|Shell Running A Pipe Without Pipefail Flag<br/><sup><sub>efbf148a-67e9-42d2-ac47-02fa1c0d0b22</sub></sup>|<span style="color:#edd57e">Low</span>|Insecure Defaults|<a href="../dockerfile-queries/efbf148a-67e9-42d2-ac47-02fa1c0d0b22" target="_blank">Query details</a><br><a href="https://docs.docker.com/engine/reference/builder/#run">Documentation</a><br/>|
|APT-GET Missing '-y' To Avoid Manual Input<br/><sup><sub>77783205-c4ca-4f80-bb80-c777f267c547</sub></sup>|<span style="color:#edd57e">Low</span>|Supply-Chain|<a href="../dockerfile-queries/77783205-c4ca-4f80-bb80-c777f267c547" target="_blank">Query details</a><br><a href="https://docs.docker.com/engine/reference/builder/#run">Documentation</a><br/>|
|APT-GET Missing Flags To Avoid Manual Input<br/><sup><sub>77783205-c4ca-4f80-bb80-c777f267c547</sub></sup>|<span style="color:#edd57e">Low</span>|Supply-Chain|<a href="../dockerfile-queries/77783205-c4ca-4f80-bb80-c777f267c547" target="_blank">Query details</a><br><a href="https://docs.docker.com/engine/reference/builder/#run">Documentation</a><br/>|
|Missing Flag From Dnf Install<br/><sup><sub>7ebd323c-31b7-4e5b-b26f-de5e9e477af8</sub></sup>|<span style="color:#edd57e">Low</span>|Supply-Chain|<a href="../dockerfile-queries/7ebd323c-31b7-4e5b-b26f-de5e9e477af8" target="_blank">Query details</a><br><a href="https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#run">Documentation</a><br/>|
|Run Using 'wget' and 'curl'<br/><sup><sub>fc775e75-fcfb-4c98-b2f2-910c5858b359</sub></sup>|<span style="color:#edd57e">Low</span>|Supply-Chain|<a href="../dockerfile-queries/fc775e75-fcfb-4c98-b2f2-910c5858b359" target="_blank">Query details</a><br><a href="https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#run">Documentation</a><br/>|
|Run Using apt<br/><sup><sub>b84a0b47-2e99-4c9f-8933-98bcabe2b94d</sub></sup>|<span style="color:#edd57e">Low</span>|Supply-Chain|<a href="../dockerfile-queries/b84a0b47-2e99-4c9f-8933-98bcabe2b94d" target="_blank">Query details</a><br><a href="https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#run">Documentation</a><br/>|
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: APT-GET Missing '-y' To Avoid Manual Input
title: APT-GET Missing Flag To Avoid Manual Input
hide:
toc: true
navigation: true
Expand All @@ -16,11 +16,11 @@ hide:
</style>

- **Query id:** 77783205-c4ca-4f80-bb80-c777f267c547
- **Query name:** APT-GET Missing '-y' To Avoid Manual Input
- **Query name:** APT-GET Missing Flags To Avoid Manual Input
- **Platform:** Dockerfile
- **Severity:** <span style="color:#edd57e">Low</span>
- **Category:** Supply-Chain
- **URL:** [Github](https://github.com/Checkmarx/kics/tree/master/assets/queries/dockerfile/apt_get_missing_yes_flag_to_avoid_manual_input)
- **URL:** [Github](https://github.com/Checkmarx/kics/tree/master/assets/queries/dockerfile/apt_get_missing_flags_to_avoid_manual_input)

### Description
Check if apt-get calls use the flag -y to avoid user manual input.<br>
Expand Down
2 changes: 1 addition & 1 deletion test/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,4 +303,4 @@ func getQueryFilter() *source.QueryInspectorParameters {
ExcludeQueries: source.ExcludeQueries{ByIDs: []string{}, ByCategories: []string{}},
InputDataPath: "",
}
}
}
Loading