Skip to content

Conversation

@maxammann
Copy link
Contributor

No description provided.

Comment on lines 8 to 31
runs-on: ubuntu-latest

container:
image: aquasec/trivy:0.67.2

steps:
- run: trivy --version
- uses: actions/checkout@v3
with:
fetch-depth: 0
- run: trivy fs --format cyclonedx --output /tmp/trivy-cyclonedx.json .
- run: |
IS_LATEST=false
if [ "${{ github.ref_name }}" = "${{ github.event.repository.default_branch }}" ]; then
IS_LATEST=true
fi
curl -X "POST" "https://dependency-track.hawk-dinosaur.ts.net/api/v1/bom" \
-H 'Content-Type: multipart/form-data' \
-H "X-Api-Key: ${{ secrets.DEPENDENCY_TRACK_AUTOMATION_API_KEY }}" \
-F "autoCreate=true" \
-F "projectName=${{ github.repository }}" \
-F "projectVersion=${{ github.ref_name }}" \
-F "isLatest=$IS_LATEST" \
-F "bom=@/tmp/trivy-cyclonedx.json"

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}

Copilot Autofix

AI about 1 month ago

To fix the problem, we should explicitly add a permissions block to the workflow. Since none of the steps require write access and only need to check out code and run analysis/upload results externally, the minimal starting point is contents: read. This block should be added at the workflow root (before jobs:) to apply to all jobs unless a job-specific override is needed.
Where: In .github/workflows/dependency-track.yml, add a permissions: block after the name: field (i.e. after line 4), before the jobs: field.
What: Add:

permissions:
  contents: read

No imports, methods, or other definitions are necessary.


Suggested changeset 1
.github/workflows/dependency-track.yml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/workflows/dependency-track.yml b/.github/workflows/dependency-track.yml
--- a/.github/workflows/dependency-track.yml
+++ b/.github/workflows/dependency-track.yml
@@ -2,6 +2,8 @@
   pull_request:
 
 name: Dependency Track
+permissions:
+  contents: read
 
 jobs:
   trivy:
EOF
@@ -2,6 +2,8 @@
pull_request:

name: Dependency Track
permissions:
contents: read

jobs:
trivy:
Copilot is powered by AI and may make mistakes. Always verify output.
Comment on lines 20 to 23
- run: |
IS_LATEST=false
if [ "${{ github.ref_name }}" = "${{ github.event.repository.default_branch }}" ]; then
IS_LATEST=true
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The branch detection logic may not function as intended in a pull request context. In pull requests, github.ref_name typically refers to the source branch being merged, not the target branch. To correctly determine if the target branch is the default branch, consider using github.base_ref instead:

if [ "${{ github.base_ref }}" = "${{ github.event.repository.default_branch }}" ]; then
  IS_LATEST=true
fi

This ensures the isLatest flag is properly set when the PR targets the default branch.

Suggested change
- run: |
IS_LATEST=false
if [ "${{ github.ref_name }}" = "${{ github.event.repository.default_branch }}" ]; then
IS_LATEST=true
IS_LATEST=false
if [ "${{ github.base_ref }}" = "${{ github.event.repository.default_branch }}" ]; then
IS_LATEST=true
fi

Spotted by Graphite Agent

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants