How to send credential alerts to Slack
Send credential alerts to Slack when a key lands in your GitHub code. Steps for a webhook, a Gitleaks workflow and a safe test.
·
To send credential alerts to Slack, you need two things: a scanner that finds exposed keys and a Slack webhook, which is a private web address that posts to one channel. This guide uses Gitleaks, a free scanner, and GitHub Actions, which runs jobs when you push code.
The alert names the repository and links to the scan. It never sends the key to Slack.
Pick where your credential alerts come from
| Tool | What it checks | How it reaches Slack |
|---|---|---|
| Gitleaks with GitHub Actions | Code you push and its history | The workflow in this guide |
| GitHub secret scanning | History, issues, pull requests and more | Its secret_scanning_alert webhook, through a small service you run |
| GitGuardian | The sources you connect to it | A built-in Slack setting |
| AgentProof | Your live website, during each test | A built-in Slack setting |
GitHub secret scanning is free for public repositories. Private repositories owned by an organization need paid Secret Protection. GitHub's Slack app does not list secret scanning among the alerts it can send. If you already pay for GitHub's scanner or GitGuardian, use that and skip the workflow.
1. Create a Slack webhook
- Open your Slack apps and create an app.
- Select Incoming Webhooks and turn on Activate Incoming Webhooks.
- Choose Add New Webhook to Workspace, pick a channel and select Authorize. Use a private channel that you are already in.
- Copy the webhook address.
Treat that address like a password. Anyone who has it can post to your channel. Slack revokes webhook addresses that it finds leaked.
2. Send a test message to Slack
Run this in Bash. Paste the address when it waits for input, then press Enter. This keeps the address out of your command history.
read -rs SLACK_WEBHOOK_URL
curl -fsS -H 'Content-Type: application/json' \
--data '{"text":"Test: credential alerts can reach this channel."}' \
"$SLACK_WEBHOOK_URL"Slack replies ok, and the message appears in the channel.
3. Save the webhook as a GitHub secret
In your repository, open Settings, then Secrets and variables, then Actions. Choose New repository secret. Name it SLACK_WEBHOOK_URL, paste the address and save it.
4. Add the credential alert workflow
Save this as .github/workflows/credential-alerts.yml on your default branch.
name: Credential alerts
on:
push:
branches: ["**"]
workflow_dispatch:
permissions:
contents: read
jobs:
scan:
if: ${{ !github.event.deleted }}
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
- name: Install Gitleaks
run: |
cd "$RUNNER_TEMP"
curl -fsSL -o gitleaks.tar.gz https://github.com/gitleaks/gitleaks/releases/download/v8.30.1/gitleaks_8.30.1_linux_x64.tar.gz
echo "551f6fc83ea457d62a0d98237cbad105af8d557003051f41f3e7ca7b3f2470eb gitleaks.tar.gz" | sha256sum -c -
tar -xzf gitleaks.tar.gz gitleaks
- name: Scan for credentials
id: scan
env:
BEFORE: ${{ github.event.before }}
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
run: |
if [ "$GITHUB_EVENT_NAME" = "workflow_dispatch" ]; then
range="--all"
elif git cat-file -e "$BEFORE^{commit}" 2>/dev/null; then
range="$BEFORE..$GITHUB_SHA"
elif [ "$GITHUB_REF_NAME" = "$DEFAULT_BRANCH" ]; then
range="$GITHUB_SHA"
else
range="origin/$DEFAULT_BRANCH..$GITHUB_SHA"
fi
git rev-list --count "$range"
report="$RUNNER_TEMP/report.json"
code=0
"$RUNNER_TEMP/gitleaks" git --redact --no-banner --exit-code 2 \
--log-opts="$range" --report-format json --report-path "$report" . || code=$?
if [ "$code" = 0 ]; then
echo "result=clean" >> "$GITHUB_OUTPUT"
elif [ "$code" = 2 ]; then
echo "result=found" >> "$GITHUB_OUTPUT"
jq -r '.[] | "\(.RuleID): \(.File):\(.StartLine) in \(.Commit)"' "$report"
exit 1
else
exit 1
fi
- name: Send the alert to Slack
if: ${{ !cancelled() && steps.scan.outputs.result != 'clean' }}
env:
RESULT: ${{ steps.scan.outputs.result }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
run: |
if [ "$RESULT" = "found" ]; then
message="Possible exposed credential in $GITHUB_REPOSITORY."
else
message="The credential scan could not finish in $GITHUB_REPOSITORY."
fi
link="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"
jq -n --arg text "$message $link" '{text: $text}' |
curl -fsS -H 'Content-Type: application/json' --data @- "$SLACK_WEBHOOK_URL"On each push, the workflow scans only the new commits, so an old key does not set off an alert every time. If it finds a key, the job fails and Slack gets a link. The log shows the file, line and commit. If the scan fails with an error, Slack hears about that too.
5. Test the credential alert
Push a made-up key on a test branch:
git switch -c test-credential-alert
printf 'api_key = "%s"\n' "$(openssl rand -hex 32)" > alert-test.txt
git add alert-test.txt
git commit -m "Test credential alerts"
git push -u origin test-credential-alertWait for the Slack message, then delete the branch from GitHub and your computer. Never test with a real key.
To check older commits, open Actions, choose Credential alerts and press Run workflow. That scans the full history.
What to do when you get a credential alert
- Replace the key first. Create a new key with the service that issued it, update your app, then revoke the old one. If someone is already using the old key, revoke it at once.
- Check how it was used. Look in that service's logs for activity you do not recognize.
- Move the new key out of your code. Keep it in your host's secret settings.
- Decide whether to clean the history. GitHub says that revoking the key may be enough. Deleting the line alone is not, because old commits still hold it.
For a false alarm, add a gitleaks:allow comment to that line. Review these comments like any code change, because they also hide real keys.
What these credential alerts miss
- They arrive after the push. The key is already on GitHub by then.
- They only know patterns. A short or unusual password can get through.
- They skip edits made while merging. The scan does not read lines that first appear in a merge commit, such as a key typed while fixing a conflict.
- They need the job to finish. A job that is cancelled or runs past its 15-minute limit sends no alert.
- They can be turned off. Anyone who can push can edit the workflow or add a Gitleaks ignore file on their branch.
- Some pushes cannot send alerts. Pushes by Dependabot, GitHub's update bot, cannot read Actions secrets. Pushes to other people's forks do not run in your repository.
- Gitleaks gets security fixes only. Its maintainer says it is feature complete and now works on Betterleaks.
- They do not see your live website. A build can put a server key into the code sent to browsers, even when that key was never committed.
Get alerts for keys exposed on your live website
AgentProof covers that last gap. During a test, the Attack Agent looks for secret keys in the code your website sends to browsers and for private files that anyone can open.
To get the result in Slack, open Settings, then Integrations, add your webhook as a Slack destination and select Findings recorded. The message arrives after the test. It counts all confirmed findings by risk and links to the report, without the key. It is not a credential-only alert, and it does not watch between tests. The notifications guide has the details.
Sources: Slack: incoming webhooks, GitHub: secret scanning, GitHub: webhook events, GitHub: Slack app features, Gitleaks documentation, GitGuardian: Slack.
AgentProof for apps built with AI tools checks for exposed keys and private data in pages and APIs, and reviews database rules in your code.