Skip to content

Commit ed51d13

Browse files
committed
docker: avoid the use of the ADD instruction
1 parent 701ac83 commit ed51d13

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
## These should be flagged
2+
3+
# <expect-error>
4+
ADD ./source /destination
5+
6+
# <expect-error>
7+
ADD https://example.com/file.tar.gz /destination/
8+
9+
# <expect-error>
10+
ADD archive.tar.gz /extract-here/
11+
12+
# <expect-error>
13+
ADD ["file1", "file2", "/dest/"]
14+
15+
# <expect-error>
16+
ADD --chown=1000:1000 sourcefile /destination/
17+
18+
## These are safe and should not be flagged
19+
20+
# Using COPY instead of ADD
21+
COPY ./source /destination
22+
23+
COPY ["file1", "file2", "/dest/"]
24+
25+
# Comments containing "ADD" should not trigger detection
26+
# This is an example: ADD should not be used

checkers/docker/avoid_add.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
language: dockerfile
2+
name: avoid_add
3+
message: "Avoid using the 'ADD' instruction in Dockerfiles, prefer 'COPY' instead for copying files"
4+
category: antipattern
5+
severity: warning
6+
7+
pattern: |
8+
(add_instruction) @avoid_add
9+
10+
description: |
11+
The 'ADD' instruction in Dockerfiles should be avoided due to its unintended side effects,
12+
such as automatic archive extraction and remote URL downloads, which can introduce security risks.
13+
If you only need to copy files into the image, prefer the use of 'COPY'.

0 commit comments

Comments
 (0)