Skip to content

Fix WiFi PSK special character escaping in wpa_supplicant.conf - #38

Draft
glynhudson with Copilot wants to merge 3 commits into
masterfrom
copilot/fix-37
Draft

glynhudson with Copilot wants to merge 3 commits into
masterfrom
copilot/fix-37

Conversation

Copilot AI commented Sep 15, 2025

Copy link
Copy Markdown
Contributor

WiFi PSKs (passwords) containing special characters were not being properly escaped when written to the wpa_supplicant configuration file, potentially causing configuration corruption and connection failures.

Problem

The setconfig() method in the Wifi class was directly inserting PSK values into the wpa_supplicant.conf file without proper escaping. This could break the configuration file format when passwords contained characters like double quotes, backslashes, or control characters.

For example, a password like my"password would generate:

#psk="my"password"

This malformed configuration could prevent WiFi connections from working.

Solution

  • Added a new private method escapeWpaSupplicantString() that properly escapes special characters for wpa_supplicant.conf format
  • Modified the setconfig() method to escape both SSID and PSK values before writing them to the configuration file
  • Ensures proper escaping of critical characters: double quotes ("), backslashes (\), newlines (\n), tabs (\t), and carriage returns (\r)

Characters Handled

The fix properly handles all the characters mentioned in the issue (&, ', (, ), @, ^, _, |) as well as other potentially problematic characters. Most of these characters don't require escaping when inside quoted strings, but the implementation ensures robust handling of edge cases.

Testing

Comprehensive testing was performed with various password combinations including:

  • All special characters mentioned in the issue
  • Edge cases with quotes, backslashes, and control characters
  • Multiple network configurations
  • Integration testing with the full PSK hashing workflow

The fix is minimal and backward-compatible, ensuring existing configurations continue to work while properly handling special characters going forward.

Fixes #37.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/php-parallel-lint/PHP-Parallel-Lint/zipball/6db563514f27e19595a19f45a4bf757b6401194e
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/6RC9xL /usr/bin/composer install (http block)

If you need me to access, download, or install something from one of these locations, you can either:


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI commented Sep 15, 2025

Copy link
Copy Markdown
Contributor Author

@glynhudson 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

Copilot AI and others added 2 commits September 15, 2025 15:21
Co-authored-by: glynhudson <758844+glynhudson@users.noreply.github.com>
Co-authored-by: glynhudson <758844+glynhudson@users.noreply.github.com>
Copilot AI changed the title [WIP] Special characters in WiFi PSK not being properly escaped Fix WiFi PSK special character escaping in wpa_supplicant.conf Sep 15, 2025
Copilot AI requested a review from glynhudson September 15, 2025 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Special characters in WiFi PSK not being properly escaped

2 participants