Fix UnicodeDecodeError in WinAdvFirewall on non-English Windows locales - #4300
Open
arielbosquez wants to merge 1 commit into
Open
Fix UnicodeDecodeError in WinAdvFirewall on non-English Windows locales#4300arielbosquez wants to merge 1 commit into
arielbosquez wants to merge 1 commit into
Conversation
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.
What does this PR do?
WinAdvFirewall.is_enabled()callssubprocess.check_output("netsh advfirewall show currentprofile")and decodes the output with.decode()(defaulting to UTF-8). On Windows systems where the OEM code page is not UTF-8 (e.g. CP850 on Spanish-language Windows),netshoutput containing accented characters causes an unhandledUnicodeDecodeError. This crashes the Agent's setup phase before it can begin scanning or propagating — the Agent completes initial recon and reports to the Island, but silently never proceeds past_setup().Reproduced with:
This PR replaces
netsh-based text parsing inis_enabled(),add_firewall_rule(), andremove_firewall_rule()with PowerShell'sNetSecuritymodule (Get-NetFirewallProfile,New-NetFirewallRule,Remove-NetFirewallRule), reading results as structured JSON. PowerShell object property names are locale-independent, unlikenetsh's human-readable output, so this fixes the crash for any non-English Windows locale, not just Spanish.The legacy
WinFirewallclass (pre-Vista, unreachable on any currently-supported Windows version) received a minimalerrors="ignore"safety patch on its own.decode()call, rather than a full rewrite, given its limited relevance today.No related issue filed prior to this PR.
PR Checklist
Testing Checklist