-
Notifications
You must be signed in to change notification settings - Fork 9
Potential fix for code scanning alert no. 1: Shell command built from environment values #150
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
Open
athal7
wants to merge
1
commit into
main
Choose a base branch
from
alert-autofix-1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔒 Security & Privacy | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: athal7/opencode-devcontainers
Length of output: 4486
🏁 Script executed:
Repository: athal7/opencode-devcontainers
Length of output: 49997
🌐 Web query:
Docker CLI ps --filter label exact value filter syntax special characters comma newline💡 Result:
The Docker CLI
psfilter syntax for labels is designed to match containers based on the presence of a label key or a specific key-value pair [1]. Syntax and Usage: - Existence check: Use--filter "label=key"to match any container that has the specified label, regardless of its value [1]. - Exact match: Use--filter "label=key=value"to match containers where the labelkeyhas the exact valuevalue[1][2]. Handling Special Characters: - Commas: Historically, commas in label values could cause parsing errors with the--filterflag [3]. While improvements in later versions of the Docker CLI have mitigated many such issues, it is recommended to wrap the entire filter string in quotes [1][4]. - Newlines: Newline characters are generally not supported within the label values when passed via the CLI--filterflag because the flag expects a standard string format [4]. - General Best Practice: To ensure special characters are handled correctly, always enclose the entire filter argument in single or double quotes, such as--filter "label=my.key=some,value". Filter Operators: - Equality: The=operator is used for standard matching [4]. - Inequality: Some commands support the!=operator (e.g.,label!=keyorlabel!=key=value) to exclude containers with specific labels [4][5]. However, support for!=can vary across different Docker commands and versions; while it is well-supported inprune[5], its use inpshas historically been inconsistent across different versions [6]. If you encounter issues with complex strings or special characters, verify your Docker version and consider using--formatcombined with standard shell tools (likegreporjq) if the native--filtersyntax remains restrictive [7].Citations:
🏁 Script executed:
Repository: athal7/opencode-devcontainers
Length of output: 50385
🏁 Script executed:
Repository: athal7/opencode-devcontainers
Length of output: 533
🌐 Web query:
Moby Docker CLI label filter comma parsing source filters label key value💡 Result:
In the Docker CLI, the --filter flag for labels does not support comma-separated parsing for label values, as the parser interprets the equals sign (=) as the delimiter between the filter key and the filter value [1]. Technical Details and Constraints: 1. Parsing Logic: The Docker CLI filter parser splits the argument on the first equals sign encountered using
strings.SplitN(arg, "=", 2)[1]. For a filter provided as --filter "label=mykey=myvalue", the parser identifies "label" as the field name and "mykey=myvalue" as the value to match [1]. 2. Comma Interpretation: If a label value contains a comma (e.g., "value1,value2"), the CLI treats the entire string (including the comma) as part of the value [2]. Historically, early versions of the Docker CLI had bugs where commas in filter values could cause parsing errors [2], but modern versions correctly handle them as literal characters within the value [2]. 3. Multiple Labels: To filter by multiple labels or multiple label values, you must provide the --filter flag multiple times [3][4]. - Logical OR: Using the same filter key multiple times (e.g., --filter "label=key1=val1" --filter "label=key1=val2") acts as a logical OR in some contexts like event filtering [5], though behavior varies by specific command implementation. - Logical AND: Combining different filter keys acts as a logical AND [4]. 4. Recommended Approach: If you need to match a label value that includes a comma, ensure your filter string correctly defines the key and value. For example, to match a label "env" with the value "prod,internal", use: docker ps --filter "label=env=prod,internal" The key point is that the CLI does not treat commas as list delimiters; it treats them as literal characters within the value component of the key-value pair [2].Citations:
🏁 Script executed:
Repository: athal7/opencode-devcontainers
Length of output: 17562
Sanitize every workspace value used in a Docker label filter.
findContainerIdandgetContainerPortstill interpolateworkspacewithoutsanitizeDockerFilterValue. Move the helper to a shared module and apply it at both sinks. Add regression tests for rejected control characters.