Skip to content

Only allow -File to accept .ps1 scripts on Windows - #15859

Merged
Travis Plunk (TravisEz13) merged 5 commits into
PowerShell:masterfrom
SteveL-MSFT:file-ps1
Aug 3, 2021
Merged

Travis Plunk (TravisEz13) merged 5 commits into
PowerShell:masterfrom
SteveL-MSFT:file-ps1

Conversation

@SteveL-MSFT

@SteveL-MSFT Steve Lee (SteveL-MSFT) commented Aug 3, 2021 •

Copy link
Copy Markdown
Member

PR Summary

A change was made previously to support shebang on Linux to accept files without requiring .ps1 extension. However, Windows doesn't support shebang, so we should be consistent with Windows PowerShell and only allow for scripts with .ps1 extension.

Fix is to update consolehost -File parsing path to check if the file has a .ps1 extension on Windows and return an error.
A bunch of tests had to be updated with the new behavior.

PR Checklist

@iSazonov Ilya (iSazonov) added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Aug 3, 2021
@SteveL-MSFT

Copy link
Copy Markdown
Member Author

static analysis failures are not related to this PR, still not sure why those URLs fail in CI but work locally from my dev machine unless CI is using a proxy for internet.

@ghost ghost added the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Aug 3, 2021
…eterParser.cs

Co-authored-by: Paul Higinbotham <paulhi@microsoft.com>
@ghost ghost removed the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Aug 3, 2021
@SteveL-MSFT

Steve Lee (SteveL-MSFT) commented Aug 3, 2021 •

Copy link
Copy Markdown
Member Author

Don't know why codeql is failing as it's complaining about --print-diagnostics-summary being an invalid switch, but it's clearly supported via https://codeql.github.com/docs/codeql-cli/manual/database-interpret-results/

@TravisEz13 Travis Plunk (TravisEz13) added the WG-Security security related areas such as JEA label Aug 3, 2021
@TravisEz13 Travis Plunk (TravisEz13) changed the title Only allow -File to accept .ps1 scripts on Windows Only allow -File to accept .ps1 scripts on Windows Aug 3, 2021
@TravisEz13
Travis Plunk (TravisEz13) merged commit 6933c5b into PowerShell:master Aug 3, 2021
@SteveL-MSFT
Steve Lee (SteveL-MSFT) deleted the file-ps1 branch August 6, 2021 20:02
@ghost

Copy link
Copy Markdown

🎉v7.2.0-preview.9 has been released which incorporates this pull request.:tada:

Handy links:

@ghost

Copy link
Copy Markdown

🎉v7.2.0-preview.10 has been released which incorporates this pull request.:tada:

Handy links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log WG-Security security related areas such as JEA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants