Conversation
| run: | | ||
| echo "${{ inputs.version-path }}" | ||
| if [ -r "${{ inputs.version-path }}" ]; then | ||
| echo "${{ inputs.version-path }}" | ||
| # Extract version from setup.py or similar file | ||
| VERSION=$(cat "${{ inputs.version-path }}" | grep -i 'version[ ]*=[ ]*["\'\''][0-9]\+\.[0-9]\+\.[0-9]\+' | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+') | ||
| echo "$VERSION" | ||
| if [ -z "$VERSION" ]; then | ||
| # Try getting it with setuptools if direct grep fails | ||
| python -c "import setuptools; exec(open('${{ inputs.version-path }}').read()); print(__version__ if 'version' not in locals() else version)" > version.txt 2>/dev/null || true | ||
| if [ -s version.txt ]; then | ||
| VERSION=$(cat version.txt | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+') | ||
| fi | ||
| fi | ||
| echo "VERSION=$VERSION" >> $GITHUB_OUTPUT | ||
| else | ||
| echo "Version file not found at ${{ inputs.version-path }}" | ||
| echo "VERSION=unknown" >> $GITHUB_OUTPUT | ||
| fi | ||
|
|
There was a problem hiding this comment.
Using variable interpolation ${{...}} with github context data in a run: step could allow an attacker to inject their own code into the runner. This would allow them to steal secrets and code. github context data can have arbitrary user input and should be treated as untrusted. Instead, use an intermediate environment variable with env: to store the data and use the environment variable in the run: script. Be sure to use double-quotes the environment variable, like this: "$ENVVAR".
🧁 Fixed in commit 6d459d2 🧁
| run: | | ||
| echo "${{ inputs.version-path }}" | ||
| if [ -r "${{ inputs.version-path }}" ]; then | ||
| echo "${{ inputs.version-path }}" | ||
| # Extract version from setup.py or similar file | ||
| VERSION=$(cat "${{ inputs.version-path }}" | grep -i 'version[ _]*=[ ]*["\'\''][0-9]\+\.[0-9]\+\.[0-9]\+' | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+') | ||
| echo "$VERSION" | ||
| if [ -z "$VERSION" ]; then | ||
| # Try getting it with setuptools if direct grep fails | ||
| python -c "import setuptools; exec(open('${{ inputs.version-path }}').read()); print(__version__ if 'version' not in locals() else version)" > version.txt 2>/dev/null || true | ||
| if [ -s version.txt ]; then | ||
| VERSION=$(cat version.txt | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+') | ||
| fi | ||
| fi | ||
| echo "VERSION=$VERSION" >> $GITHUB_OUTPUT | ||
| else | ||
| echo "Version file not found at ${{ inputs.version-path }}" | ||
| echo "VERSION=unknown" >> $GITHUB_OUTPUT | ||
| fi | ||
|
|
There was a problem hiding this comment.
Semgrep identified an issue in your code:
Using variable interpolation ${{...}} with github context data in a run: step could allow an attacker to inject their own code into the runner. This would allow them to steal secrets and code. github context data can have arbitrary user input and should be treated as untrusted. Instead, use an intermediate environment variable with env: to store the data and use the environment variable in the run: script. Be sure to use double-quotes the environment variable, like this: "$ENVVAR".
To resolve this comment:
✨ Commit Assistant fix suggestion
| run: | | |
| echo "${{ inputs.version-path }}" | |
| if [ -r "${{ inputs.version-path }}" ]; then | |
| echo "${{ inputs.version-path }}" | |
| # Extract version from setup.py or similar file | |
| VERSION=$(cat "${{ inputs.version-path }}" | grep -i 'version[ _]*=[ ]*["\'\''][0-9]\+\.[0-9]\+\.[0-9]\+' | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+') | |
| echo "$VERSION" | |
| if [ -z "$VERSION" ]; then | |
| # Try getting it with setuptools if direct grep fails | |
| python -c "import setuptools; exec(open('${{ inputs.version-path }}').read()); print(__version__ if 'version' not in locals() else version)" > version.txt 2>/dev/null || true | |
| if [ -s version.txt ]; then | |
| VERSION=$(cat version.txt | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+') | |
| fi | |
| fi | |
| echo "VERSION=$VERSION" >> $GITHUB_OUTPUT | |
| else | |
| echo "Version file not found at ${{ inputs.version-path }}" | |
| echo "VERSION=unknown" >> $GITHUB_OUTPUT | |
| fi | |
| env: | |
| VERSION_PATH: ${{ inputs.version-path }} | |
| run: | | |
| echo "$VERSION_PATH" | |
| if [ -r "$VERSION_PATH" ]; then | |
| echo "$VERSION_PATH" | |
| # Extract version from setup.py or similar file | |
| VERSION=$(cat "$VERSION_PATH" | grep -i 'version[ _]*=[ ]*["\'\''][0-9]\+\.[0-9]\+\.[0-9]\+' | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+') | |
| echo "$VERSION" | |
| if [ -z "$VERSION" ]; then | |
| # Try getting it with setuptools if direct grep fails | |
| python -c "import setuptools; exec(open('$VERSION_PATH').read()); print(__version__ if 'version' not in locals() else version)" > version.txt 2>/dev/null || true | |
| if [ -s version.txt ]; then | |
| VERSION=$(cat version.txt | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+') | |
| fi | |
| fi | |
| echo "VERSION=$VERSION" >> $GITHUB_OUTPUT | |
| else | |
| echo "Version file not found at $VERSION_PATH" | |
| echo "VERSION=unknown" >> $GITHUB_OUTPUT | |
| fi |
View step-by-step instructions
-
Add environment variables to the step to store untrusted input values:
- name: Extract Version id: extract_version env: VERSION_PATH: ${{ inputs.version-path }} run: | echo "$VERSION_PATH" if [ -r "$VERSION_PATH" ]; then echo "$VERSION_PATH" # Extract version from setup.py or similar file VERSION=$(cat "$VERSION_PATH" | grep -i 'version[ _]*=[ ]*["\'\''][0-9]\+\.[0-9]\+\.[0-9]\+' | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+') echo "$VERSION" if [ -z "$VERSION" ]; then # Try getting it with setuptools if direct grep fails python -c "import setuptools; exec(open('$VERSION_PATH').read()); print(__version__ if 'version' not in locals() else version)" > version.txt 2>/dev/null || true if [ -s version.txt ]; then VERSION=$(cat version.txt | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+') fi fi echo "VERSION=$VERSION" >> $GITHUB_OUTPUT else echo "Version file not found at $VERSION_PATH" echo "VERSION=unknown" >> $GITHUB_OUTPUT fi
-
Also update the Build and publish step to use environment variables:
- name: Build and publish env: TWINE_USERNAME: ${{ secrets.UV_INDEX_JFROG_USERNAME }} TWINE_PASSWORD: ${{ secrets.UV_INDEX_JFROG_PASSWORD }} REPOSITORY_URL: ${{ inputs.repository-url }} run: | python3 setup.py sdist bdist_wheel twine upload --non-interactive -u $TWINE_USERNAME -p $TWINE_PASSWORD --repository-url "$REPOSITORY_URL" dist/*
Using environment variables prevents direct interpolation of potentially dangerous input values in shell commands, reducing the risk of command injection attacks.
💬 Ignore this finding
Reply with Semgrep commands to ignore this finding.
/fp <comment>for false positive/ar <comment>for acceptable risk/other <comment>for all other reasons
Alternatively, triage in Semgrep AppSec Platform to ignore the finding created by run-shell-injection.
You can view more details about this finding in the Semgrep AppSec Platform.
No description provided.