Skip to content

fix(query): changed all dockerfile queries for case insensitive support of dockerfile commands#8006

Open
cx-andre-pereira wants to merge 102 commits intoCheckmarx:masterfrom
cx-andre-pereira:Dockerfile_queries_fix_for_case_insensitivity
Open

fix(query): changed all dockerfile queries for case insensitive support of dockerfile commands#8006
cx-andre-pereira wants to merge 102 commits intoCheckmarx:masterfrom
cx-andre-pereira:Dockerfile_queries_fix_for_case_insensitivity

Conversation

@cx-andre-pereira
Copy link
Copy Markdown
Contributor

@cx-andre-pereira cx-andre-pereira commented Mar 23, 2026

Reason for Proposed Changes

The changes from #7995 (included in this PR) enable scanned Dockerfiles to recognize valid case-insensitive syntax. However, none of the existing Dockerfile queries were prepared for this — all of them contain hardcoded uppercase references to Docker commands.

Additionally, testing revealed that the existing query logic, payload generation, and engine line-searching logic did not support multiple FROM statements associated with the same image within a single document. In such cases, only the first FROM statement would produce results; the engine was unable to flag any subsequent occurrences.

Proposed Changes


New auxiliary functions

Two new helper functions were added to the common library dockerfile.rego:

  • get_original_from_command — Extracts the FROM command with its original casing along with the LineHint value for that command.
  • add_line_hint — Appends the extracted LineHint to the string using ^ as a separator.

The LineHint value enables the engine to distinguish between multiple FROM statements referencing the same image.


Query updates

  • All queries now use these two auxiliary functions to generate their searchKey value. On the engine side, preserving the original casing of FROM enables more precise searching through the source file. The LineHint value is consumed by docker_detect and stripped by the vulnerability_builder before results are emitted.

Parser changes

  • The parser was updated so that each FROM statement generates a distinct object. Previously, all FROM commands referencing the same image were merged into a single object.

Test coverage

  • A new positive and negative sample was added to every test folder. These mirror the existing positive/positive1 and negative/negative1 tests but use all-lowercase commands.

  • A new E2E test (107) was added, it tests that the payload/results of a scan on a multistage dockerfile sample with duplicate FROM statements is parsed/flagged as expected.

  • New test based on OriginalData4 added to the docker_detect_test file, also checks that a multistage sample with duplicate FROM statements flags properly.

  • TestDockerSearchKeyLineHintRemoval was added to the vulnerability_builder_test file, as the name implies it checks that the LineHint appended to the searchKey value of a sample dockefile query is removed properly.


Updated Documentation/Script

  • The query creation documentation was updated to reflect these changes, specifically for Dockerfile query searchKey value attribution.
  • The validate_search_line.py CI script was updated to account for the fact that Dockerfile queries do not currently support searchLine values. The script now excludes all queries under the dockerfile queries folder.

I submit this contribution under the Apache-2.0 license.

…es and all files with prefix 'dockerfile.' as well as all files with the '.dockerfile' extension type in a case insensitive matter (improvement on first commit)
…sion, added support for all ubi8/debian files in case of valid dockerfile structure, added support for lower case dockerfile commands - most queries will have issues with this but relevant text files are properly detected as a 'dockerfile' as intended
…rors, fixed 'gitignore' files exclusion, docker parser will handle said case like before but with explicit 'gitignore' extension rather than 'possibleDockerfile' like before
…sion so that it 1- gets detected regardless of syntax inside 2- gets detected withouth checking syntax inside through the code optimizing detection speed for said files
…wice and minor simplificaton of query arguments
…test 105, improved uni tests to include new case insensitive samples
… unnecessary 'gitignore' case in analyzer's workers
…have to be explicitly set as unwanted to allign with '.gitignore' behaviour
cx-andre-pereira and others added 30 commits April 9, 2026 15:53
…140477--Improvement-to-dockerfile-scanning
… 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
…rfile_queries_fix_for_case_insensitivity
…umentation to reflect specific dockerfile searchKey building
…rfile_queries_fix_for_case_insensitivity
…ine FROM statements are compatible, fixed whitespace support for ARG/comments in dockerfiles and fix new E2E results
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community Community contribution docker Docker query dockerfile query New query feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants