Repository navigation
[Aikido] Fix shell injection bypass in nested quote context parsing - #749
Closed
aikido-autofix[bot] wants to merge 1 commit into
Closed
aikido-autofix[bot] wants to merge 1 commit into
aikido-autofix[bot] wants to merge 1 commit into
Conversation
…xts by tracking quote state...
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This patch addresses a shell injection vulnerability where nested quote contexts could bypass detection by examining only adjacent characters around user input. The fix implements proper shell quoting state parsing that tracks quote context from the beginning of the command rather than relying on local character analysis. Changes were made to
is_safely_encapsulated.pyto enhance quote context tracking logic, with corresponding test cases added todetect_shell_injection_test.pyandis_safely_encapsulated_test.pyto validate the fix against nested quote scenarios.✅ 1 issue fixed by this PR
user_input = "$(id)"andcommand = 'echo "\'$(id)\'"', it observes matching apostrophes and returnsTrue. Those apostrophes occur inside an active outer double-quoted region and do not disable command substitution.detect_shell_injection()therefore returns before callingcontains_shell_syntax(), which would flag$. The false negative affects the shared detection path used beforeos.systemandsubprocess.Popen(..., shell=True), allowing a request-controlled value already interpolated into such a command to execute with the consuming process's privileges.