Skip to content

F 739 : fix shell command injection#213

Open
miyazakh wants to merge 2 commits intowolfSSL:mainfrom
miyazakh:f-739_shellcommand
Open

F 739 : fix shell command injection#213
miyazakh wants to merge 2 commits intowolfSSL:mainfrom
miyazakh:f-739_shellcommand

Conversation

@miyazakh
Copy link
Copy Markdown
Contributor

@miyazakh miyazakh commented Mar 27, 2026

F-739 : Shell command injection via popen with unsensitized hostname
Add test coverage

Depend on : #211 (Fixed)
Depend on : #219

Copilot AI review requested due to automatic review settings March 27, 2026 00:06
@miyazakh miyazakh self-assigned this Mar 27, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses a shell command injection risk in the client hostname resolution path (when using popen("host ...")) and expands regression coverage to detect attempted command execution via crafted -connect hostnames.

Changes:

  • Add hostname character validation before constructing a popen() command in the client.
  • Add client regression tests that ensure injected shell metacharacters do not result in file creation.
  • Loosen OCSP interop test error-message matching and adjust hash-type switch guards for newer wolfSSL versions.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/client/client.c Adds hostname validation to prevent shell metacharacters from reaching the popen() command.
tests/client/client-test.sh Adds regression tests intended to detect hostname-based shell injection.
tests/ocsp/ocsp-interop-test.sh Expands grep patterns for expected failure messages in interop testing.
src/x509/clu_x509_sign.c Updates preprocessor version gating for additional WC_HASH_TYPE_* enum cases.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@miyazakh miyazakh force-pushed the f-739_shellcommand branch from 566a39f to b55a628 Compare April 7, 2026 21:11
@miyazakh miyazakh marked this pull request as ready for review April 7, 2026 21:11
Copilot AI review requested due to automatic review settings April 7, 2026 21:11
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +152 to +162
const char* cp;

/* Validate hostname: only allow characters valid in DNS names
* (RFC 1123) to prevent shell injection via popen(). */
for (cp = peer; *cp != '\0'; cp++) {
if (!isalnum((unsigned char)*cp) &&
*cp != '.' && *cp != '-') {
err_sys("invalid character in hostname");
return;
}
}
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isalnum() is locale-dependent, which can allow non-ASCII bytes to be treated as “alnum” under some locales. Since this validation is part of a shell-injection mitigation, it’s safer to enforce an explicit ASCII allowlist (e.g., [A-Za-z0-9.-]) rather than isalnum(), so behavior is deterministic across environments/locales.

Copilot uses AI. Check for mistakes.
Comment on lines +154 to +156
/* Validate hostname: only allow characters valid in DNS names
* (RFC 1123) to prevent shell injection via popen(). */
for (cp = peer; *cp != '\0'; cp++) {
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change enforces “DNS hostname only” semantics on peer for the WOLFSSL_USE_POPEN_HOST path; if peer previously supported IP literals (notably IPv6 forms) in this path, this will now reject them due to : / []. If IP literals are expected to work, consider detecting numeric addresses (or bracketed IPv6) and bypassing the popen("host ...") code path entirely (use getaddrinfo), while keeping the strict hostname allowlist for actual DNS names.

Copilot uses AI. Check for mistakes.
Comment on lines +36 to +37
./wolfssl s_client -connect 'evil.com;touch clu_injection_probe.txt:443' \
2>/dev/null
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These regression tests can become flaky/hang in CI because they rely on external DNS/network behavior (e.g., evil.com) and may block longer than desired depending on resolver settings. To make the tests deterministic, wrap each invocation with a short timeout (and consider redirecting stdout as well) so the test suite can’t stall on slow resolution/connection attempts while still validating that no injected touch executes.

Copilot uses AI. Check for mistakes.
Comment on lines +45 to +46
./wolfssl s_client -connect 'evil$(touch clu_injection_probe.txt).com:443' \
2>/dev/null
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These regression tests can become flaky/hang in CI because they rely on external DNS/network behavior (e.g., evil.com) and may block longer than desired depending on resolver settings. To make the tests deterministic, wrap each invocation with a short timeout (and consider redirecting stdout as well) so the test suite can’t stall on slow resolution/connection attempts while still validating that no injected touch executes.

Copilot uses AI. Check for mistakes.
Comment on lines +54 to +55
./wolfssl s_client -connect 'evil.com|touch clu_injection_probe.txt:443' \
2>/dev/null
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These regression tests can become flaky/hang in CI because they rely on external DNS/network behavior (e.g., evil.com) and may block longer than desired depending on resolver settings. To make the tests deterministic, wrap each invocation with a short timeout (and consider redirecting stdout as well) so the test suite can’t stall on slow resolution/connection attempts while still validating that no injected touch executes.

Copilot uses AI. Check for mistakes.
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.

2 participants