-
Notifications
You must be signed in to change notification settings - Fork 61
Add weekly email workflow for Dependabot alerts #2381
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
Open
asier-isayas
wants to merge
1
commit into
master
Choose a base branch
from
users/aisayas/dependabot-weekly-digest-1
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| name: Weekly Dependabot Alerts Email | ||
|
|
||
| on: | ||
| schedule: | ||
| - cron: '0 0 * * 0' # Triggers the workflow every Sunday at midnight UTC. | ||
|
|
||
| jobs: | ||
| send-email: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| # Step 1: Checkout the repository code (optional for this task, but typical in workflows) | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v3 | ||
|
|
||
| # Step 2: Fetch Dependabot Alerts via GitHub API | ||
| - name: Fetch Dependabot Alerts | ||
| id: dependabot-alerts | ||
| run: | | ||
| curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | ||
| -H "Accept: application/vnd.github.v3+json" \ | ||
| "https://api.github.com/repos/${{ github.repository }}/dependabot/alerts?state=open" > dependabot_alerts.json | ||
|
|
||
| # Step 3: Format the Dependabot Alerts | ||
| - name: Format Alerts as Email Body | ||
| id: format-alerts | ||
| run: | | ||
| alerts=$(cat dependabot_alerts.json | jq -r '.[] | "* **\(.securityVulnerability.package.name)**: \(.securityVulnerability.severity) severity, CVE-Id: [\(.securityVulnerability.cve)](https://cve.mitre.org/cve/\(.securityVulnerability.cve))\n \(.description)\n"') | ||
| echo "$alerts" > formatted_alerts.txt | ||
|
|
||
| # Step 4: Send the Email via Outlook SMTP (from DL1 to DL1 or DL2) | ||
| - name: Send Email | ||
| uses: dawidd6/action-send-mail@v3 | ||
| with: | ||
| smtp-server: smtp.office365.com | ||
| smtp-port: 587 | ||
| smtp-user: cdbportal@microsoft.com # Use DL1's email address | ||
| from: cdbportal@microsoft.com # The sender is DL1 | ||
| to: "dl1@yourdomain.com" # This is the recipient DL1; can also use another DL (e.g., dl2@yourdomain.com) | ||
| subject: "Weekly Dependabot Vulnerabilities for ${{ github.repository }}" | ||
| body: | | ||
| **Weekly Dependabot Security Alerts** | ||
|
|
||
| Below are the new security vulnerabilities found in your dependencies: | ||
|
|
||
| ${{ steps.format-alerts.outputs.alerts }} | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check warning
Code scanning / CodeQL
Workflow does not contain permissions Medium
Copilot Autofix
AI 4 months ago
In general, the fix is to explicitly declare a
permissions:block for the workflow (or for thesend-emailjob) that limits theGITHUB_TOKENto the least privileges needed. This workflow only needs to read repository contents and security/dependabot alerts, and it does not modify any GitHub resources.The best minimal fix without changing functionality is to add a root-level
permissions:section (so it applies to all jobs) withcontents: readandsecurity-events: read.contents: readmatches GitHub’s suggested minimal starting point and is sufficient for most repository reads;security-events: readis appropriate for accessing security/dependabot-related data via the API. No changes are needed to steps, commands, or actions. Concretely, edit.github/workflows/dependabot-weekly-email.ymlto insert apermissions:block between theon:section and thejobs:section.