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

github-env: refinements #197

Open
2 of 3 tasks
woodruffw opened this issue Nov 24, 2024 · 6 comments
Open
2 of 3 tasks

github-env: refinements #197

woodruffw opened this issue Nov 24, 2024 · 6 comments
Labels
enhancement New feature or request

Comments

@woodruffw
Copy link
Owner

woodruffw commented Nov 24, 2024

The github-env audit merged in #192 is barebones. Some things we should do to improve it:

  • Use a regex to match suspicious >> $GITHUB_ENV shell lines; this won't be perfect, but it'll avoid false positives like echo $GITHUB_ENV.
    • Candidate expression: ^.+\s*>>?\s*"?\$\{?GITHUB_ENV\}?"?.*$
    • We should also support PowerShell run: bodies, which are their own mess.
  • Handle actions/github-script bodies as well, since people are likely to modify GITHUB_ENV there too.
@woodruffw woodruffw added the enhancement New feature or request label Nov 24, 2024
@woodruffw
Copy link
Owner Author

woodruffw commented Nov 25, 2024

For PowerShell, we need to detect patterns like ... | Out-File -FilePath $env:GITHUB_ENV -Append and ... >> $env:GITHUB_ENV.

Edit: As well as cursed things like ${env:GITHUB_ENV} = ...

Edit 2: $env:GITHUB_ENV is also case insensitive, at least on Windows.

@woodruffw
Copy link
Owner Author

woodruffw commented Nov 25, 2024

Another, more serious option here would be to use tree-sitter grammars as necessary:

Edit: see airbus-cert/tree-sitter-powershell#9.

@ubiratansoares
Copy link
Contributor

@woodruffw It seems that Python is also a shell option 🙀

@ubiratansoares
Copy link
Contributor

@woodruffw I gave a try on tree-sitter-bash here. Hope it is in the right direction 🙂

@woodruffw
Copy link
Owner Author

@woodruffw It seems that Python is also a shell option 🙀

Oh yeah, it gets way worse 🙂 -- there's no way we'll end up being fully general here. But I bet we can come up with some good patterns there as well.

I gave a try on tree-sitter-bash here. Hope it is in the right direction

Thanks, that looks amazing! I'll do a more detailed review in a bit, but that approach of popping nodes from the stack is great.

@woodruffw
Copy link
Owner Author

shell: cmd is also a possibility, and in that case the pattern will look something like:

echo NAME=VAR >> %GITHUB_ENV%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants