Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get-Child Item not working if -Path is a variable? #1372

Closed
ColbyC opened this issue Jul 26, 2024 · 1 comment
Closed

Get-Child Item not working if -Path is a variable? #1372

ColbyC opened this issue Jul 26, 2024 · 1 comment

Comments

@ColbyC
Copy link

ColbyC commented Jul 26, 2024

I am making a Pode Route which refers to this file. Version of PODE is 2.10.1

{
    $query = $WebEvent.Query
    $queryPath = $query['Directory']
    $queryPath ??= ''
    #Basic Directory Traversal Sanitize 
    $queryPath = $queryPath -replace ('..'. '')
    $queryPath = $queryPath -replace ('\\'. '')
    $queryPath = $queryPath -replace ('$'. '')
    $queryPath = $queryPath -replace ('?'. '')
    $queryPath = $queryPath -replace (':'. '')
    $queryPath = $queryPath -replace ('%'. '')
    $queryPath | Out-Default
    #Build Full Path
    $path = (Join-Path -Path (Get-PodeConfig).FileStoreDirectory -ChildPath $queryPath)
    $path | Out-Default
    $res = Get-ChildItem -Path $path -Directory | Select-Object Name, FullName, CreationTime
    Write-PodeJsonResponse -Value $res
}   

However, the $res does not return a value I have verified the config is being loaded correctly and verified the $query variable is correct before entering the Get-ChildItem cmdlet.

When I statically enter path as seen below it returns expected results.

{
    $query = $WebEvent.Query
    $queryPath = $query['Directory']
    $queryPath ??= ''
    #Basic Directory Traversal Sanitize 
    $queryPath = $queryPath -replace ('..'. '')
    $queryPath = $queryPath -replace ('\\'. '')
    $queryPath = $queryPath -replace ('$'. '')
    $queryPath = $queryPath -replace ('?'. '')
    $queryPath = $queryPath -replace (':'. '')
    $queryPath = $queryPath -replace ('%'. '')
    $queryPath | Out-Default
    #Build Full Path
    $path = (Join-Path -Path (Get-PodeConfig).FileStoreDirectory -ChildPath $queryPath)
    $path | Out-Default
    $res = Get-ChildItem -Path 'C:\Windows' -Directory | Select-Object Name, FullName, CreationTime
    Write-PodeJsonResponse -Value $res
}   

PSVersion:

Name                           Value
----                           -----
PSVersion                      5.1.22621.3880
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.22621.3880
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
@ColbyC
Copy link
Author

ColbyC commented Jul 26, 2024

Resolved Issue by upgrading PowerShell to 7

@ColbyC ColbyC closed this as completed Jul 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant