Resolve Windows shell paths in the user environment - #868
Open
Kirtikumar Anandrao Ramchandani (KirtiRamchandani) wants to merge 2 commits into
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
Pull request overview
This PR hardens Windows-specific execution by resolving %...%-based shell/subsystem paths in the target user’s environment before validation/execution, and by requiring resolved shell paths to be absolute to avoid PATH-based lookups.
Changes:
- Add
resolve_configured_user_path()(Win32) to expand%...%for a given user token and enforce “absolute path” requirements where needed. - Resolve/validate user shell paths (DefaultShell-derived) in the user context and reject non-absolute results on Windows.
- Expand
%...%for configured external subsystem executable paths and add Win32compat unit tests covering expansion and rejection cases.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| session.c | Resolves %...% in external subsystem program paths (Windows) before stat/exec. |
| auth.c | Resolves shell path in the target user context and enforces absolute shell paths on Windows. |
| contrib/win32/win32compat/misc.c | Adds the user-context environment expansion helper resolve_configured_user_path(). |
| contrib/win32/win32compat/misc_internal.h | Exposes resolve_configured_user_path() in the internal Win32compat header. |
| regress/unittests/win32compat/miscellaneous_tests.c | Adds unit tests for user-path resolution behavior and error cases. |
Suppressed comments (1)
session.c:2035
- The failure log at the end of this function always reports "subsystem not found", but the loop can also exit with a matching subsystem name where the configured path expansion failed (e.g., resolve_configured_user_path() returned NULL). This can mislead debugging and operations on Windows.
if (!success)
logit("subsystem request for %.100s by user %s failed, "
"subsystem not found", s->subsys, s->pw->pw_name);
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+1481
to
+1484
| if (wcschr(expanded_path, L'%') != NULL) { | ||
| errno = EINVAL; | ||
| goto cleanup; | ||
| } |
Comment on lines
+427
to
+436
| char *out; | ||
|
|
||
| TEST_START("configured path expansion"); | ||
| SetEnvironmentVariableA("OPENSSH_TEST_ROOT", "C:\\OpenSSHTest"); | ||
| out = resolve_configured_user_path("%OPENSSH_TEST_ROOT%\\pwsh.exe", | ||
| NULL, 1); | ||
| ASSERT_STRING_EQ(out, "C:\\OpenSSHTest\\pwsh.exe"); | ||
| free(out); | ||
| SetEnvironmentVariableA("OPENSSH_TEST_ROOT", NULL); | ||
| TEST_DONE(); |
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.
Summary
pwsh.exeare not looked up through PATH%...%resolution to external subsystem executable paths while preserving existing relative built-in subsystem behaviorValidation
git diff --cached --checkMSBuild.exe contrib/win32/openssh/config.vcxproj /p:Configuration=Debug /p:Platform=x64 /p:WindowsTargetPlatformVersion=10.0.26100.0 /p:SpectreMitigation=falseMSBuild.exe contrib/win32/openssh/win32iocompat.vcxproj /p:Configuration=Debug /p:Platform=x64 /p:WindowsTargetPlatformVersion=10.0.26100.0 /p:SpectreMitigation=falseunittest-win32compat.vcxprojandsshd.vcxprojcould not be completed locally because this checkout does not have the repo vcpkg/libressl outputs installed. The focused Win32 compatibility library target that contains the new resolver compiles successfully.Fixes PowerShell/Win32-OpenSSH#2449