Commit ec7c9bb
committed
feat(security): validate user-supplied strings flowing into shell context
Closes the post-#106 security audit follow-up. Adds 9 .validate_*
helpers in R/utils.R (@nord) that reject inputs which would
otherwise be interpolated raw into the generated Dockerfile's shell
commands. Each helper raises stop() with a clear message naming the
offending parameter.
Validators added:
- .validate_FROM (image reference: `^[a-zA-Z0-9][a-zA-Z0-9._/-]*(:tag)?(@sha256:hex)?$`)
- .validate_AS (build-stage name: `^[a-zA-Z0-9][a-zA-Z0-9._-]*$`)
- .validate_repos (https URLs + simple-identifier names; closes the
`dput()`-backtick injection vector on names)
- .validate_extra_sysreqs (Debian package name: `^[a-z0-9][a-z0-9.+-]+$`)
- .validate_renv_version (semver-like, NULL allowed)
- .validate_lockfile (basename: alphanumerics + `._-`)
- .validate_renv_paths_cache (absolute path, no metacharacters)
- .validate_r_version (defensive depth on lockfile-derived value)
- .validate_scalar_logical (factored out from strict_install; used
for use_pak too, closing a real injection vector via
`echo "options(renv.config.pak.enabled = %s, ...)"`)
dock_from_desc() and dock_from_renv() call the relevant validators
at function entry, just after match.arg(github_pat).
The pr-reviewer agent flagged two additional vectors I missed in
the first pass: use_pak (B1, blocked) and names(repos) (B2, blocked
via the dput() backtick path). Both are closed by this commit.
Tests: 9 new expect_error() blocks across test-dock_from_desc.R
and test-dock_from_renv.R, each TDD red-against-buggy. One
existing test patched: renv_version = "banana" -> "1.2.3" since
the new validator rejects non-semver strings (the test was
exercising the install_version code path, which "1.2.3" still
covers).
devtools::test() -> [ FAIL 0 | WARN 3 | SKIP 0 | PASS 302 ].
R CMD check --as-cran: 0 errors / 0 warnings / 1 note (the
"unable to verify current time" host note, unrelated).
Out of scope for this PR (per the threat model agreed with the
maintainer):
- R6 helpers in R/add.R (dock$RUN, dock$COPY, ...) are
author-controlled API; if the author writes a malicious RUN it
is self-foot-shooting, not injection.
- distro is deprecated and ignored at runtime.
- github_pat is match.arg'd against a fixed enum.
NEWS.md gains a `## Security` section above `## New features`.1 parent 859273a commit ec7c9bb
9 files changed
Lines changed: 643 additions & 35 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
27 | 41 | | |
28 | 42 | | |
29 | 43 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
46 | | - | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
47 | 52 | | |
48 | | - | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
49 | 59 | | |
50 | 60 | | |
51 | 61 | | |
52 | 62 | | |
53 | 63 | | |
54 | 64 | | |
55 | | - | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
56 | 68 | | |
57 | 69 | | |
58 | 70 | | |
| |||
103 | 115 | | |
104 | 116 | | |
105 | 117 | | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
116 | 123 | | |
117 | 124 | | |
118 | 125 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
13 | | - | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
14 | 19 | | |
15 | 20 | | |
16 | 21 | | |
17 | | - | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
18 | 28 | | |
19 | | - | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
20 | 32 | | |
21 | 33 | | |
22 | 34 | | |
| |||
28 | 40 | | |
29 | 41 | | |
30 | 42 | | |
31 | | - | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
32 | 49 | | |
33 | 50 | | |
34 | 51 | | |
| |||
139 | 156 | | |
140 | 157 | | |
141 | 158 | | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
142 | 169 | | |
143 | 170 | | |
144 | 171 | | |
| |||
173 | 200 | | |
174 | 201 | | |
175 | 202 | | |
| 203 | + | |
176 | 204 | | |
177 | 205 | | |
178 | 206 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
19 | 26 | | |
20 | 27 | | |
0 commit comments