Fix command injection via crafted Wi-Fi QR code - #36
Open
ph-rast wants to merge 3 commits into
Open
Conversation
Scanned QR content was parsed into an associative array via eval. The value side was quoted with @q, but the key (${element%%:*}) was left unquoted, so a command substitution placed in the key position of a crafted QR code was executed by eval as the invoking user. Replace urimap_str with urimap_parse, which populates the array by nameref and assigns keys/values directly, removing the eval entirely. For a declare -A array the subscript is a plain string, so hostile keys are inert. Normal WiFi:S:...;T:...;P:...; codes still parse unchanged. Reachable via all scan modes (-s, -q, -f, -p). CWE-78.
Restore legacy escaped-semicolon handling
legacy mode escapes corrected to original. Got doubled during copy-paste
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.
Fix command injection via crafted Wi-Fi QR code
Summary
Audited wifi-qr with Claude Opus 4.8. Audit returned a security issue:
Scanned QR content is parsed into an associative array with
eval(incall_wifi_scan,via
urimap_str). The value side of each field is safely quoted with@Q, but thekey side (
${element%%:*}) is interpolated into theevalunquoted. Since QR contentis fully attacker-controlled, a command substitution placed in the key position is
executed by the shell.
Because the tool's purpose is to scan untrusted QR codes, this lets anyone who can get
a user to scan a QR image/code they control run arbitrary commands as that user.
-s,-q,-f FILE,-pReproduce
The decoded string flows
zbarcam/zbarimg --raw→wifiqrdata→urimap_str "${wifiqrdata:5:-1}"→eval, so everything between theWIFI:prefix andthe trailing
;reacheseval.Root cause
evalre-parses its argument as shell. The value is protected by@Q, but the key isnot, so an unquoted
$(...)/ backtick in the key position is command-substituted. Theintermediate
evalis also unnecessary — the consumer only reads a fixed set of keys.Fix
Remove the
evalentirely:urimap_strbecomesurimap_parse, which receives the targetassociative array by nameref and assigns keys/values directly. For a
declare -Aarraythe subscript is treated as a string, so a hostile key is inert. The legacy pre-processing
block is left byte-for-byte identical to the original.
Testing
-Llegacy mode.codes, percent-encoded values, empty passwords, legacy escaped-semicolon inputs,
values with spaces, and reordered fields.
-f).