Skip to content

Commit dd053df

Browse files
a-orenclaude
andcommitted
fix(providers): detect and reject ARG-substituted FROM targets
When a Dockerfile uses ARG substitution in FROM lines (e.g. FROM ${BASE_IMAGE}), parseFromImage now throws a clear error instead of passing the unresolved variable to downstream functions. TC-4978 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Assisted-by: Claude Code
1 parent e3c9903 commit dd053df

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

src/providers/oci_dockerfile.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ export function parseFromImage(manifestContent) {
5555
if (!lastFrom) {
5656
throw new Error('No FROM line found in Dockerfile')
5757
}
58+
if (lastFrom.includes('${')) {
59+
throw new Error('Dockerfile uses ARG substitution in FROM line — cannot resolve variable references')
60+
}
5861
return lastFrom
5962
}
6063

test/providers/oci_dockerfile.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ suite('testing the Dockerfile/Containerfile data provider', () => {
7777
expect(parseFromImage(content)).to.equal('httpd@sha256:abc123')
7878
})
7979

80+
/** Verifies that ARG-substituted FROM targets are rejected with a clear error. */
81+
test('throws when FROM target uses ARG substitution', () => {
82+
const content = 'ARG BASE_IMAGE=ubuntu:22.04\nFROM ${BASE_IMAGE}\n'
83+
expect(() => parseFromImage(content)).to.throw('Dockerfile uses ARG substitution in FROM line')
84+
})
85+
8086
/** Verifies that an error is thrown when no FROM line is present. */
8187
test('throws when no FROM line found', () => {
8288
const content = 'RUN echo hello\n'

0 commit comments

Comments
 (0)