Dev.to Security 🔐 Cybersecurity 👁 0 📖 10 min read

Slack Alerts for the GitHub Events Attackers Leave Behind (Any Plan, One File)

In March 2026, attackers with stolen credentials force-pushed 76 of the 77 version tags in aquasecurity/trivy-action to credential-stealing code. If the payload couldn't send what it stole home, it created a public repos

Slack Alerts for the GitHub Events Attackers Leave Behind (Any Plan, One File)

In March 2026, attackers with stolen credentials force-pushed 76 of the 77 version tags in aquasecurity/trivy-action to credential-stealing code. If the payload couldn't send what it stole home, it created a public repository called tpcp-docs in the victim's account and uploaded the data there. Aqua's advisory tells you what to do: "Look for repositories named tpcp-docs in your GitHub organization."

That's good advice after the fact. This post builds the thing that tells you when it happens.

The other big GitHub attacks of the past year were just as visible. Nx "s1ngularity" used stolen tokens to rename private repositories to s1ngularity-repository-* and make more than 6,700 of them public. GhostAction pushed a workflow called github_actions_security.yml from maintainers' own accounts and took 3,325 secrets from 817 repositories. Every one of those steps is an ordinary GitHub webhook.

Here's what we'll build:

  1. One Node file (no dependencies) that verifies GitHub's signature and posts 17 kinds of risky event to Slack
  2. An organization webhook that feeds it
  3. A short gh script for the settings that have no webhook at all
  4. The test harness I ran it against, and the traps

Three attacks and the GitHub event each left behind: s1ngularity, repository publicized; GhostAction, a push to .github/workflows; Trivy, a repository created

Why webhooks and not the audit log

GitHub's organization audit log keeps 180 days of events, and the web UI is there on every plan. Getting events out of it automatically is the problem:

Webhooks work on every plan, and GitHub's own docs say they "might be a good alternative to the audit log or API polling for certain use cases." This is one of those cases.

What each GitHub plan lets you watch: webhooks on every plan, the audit log API and streaming only on Enterprise

Step 1: the receiver

Save this as github-alerts.mjs. It needs Node 18 or later for the built-in fetch.

// github-alerts.mjs: post a Slack message for the GitHub events attackers leave behind.
// Node 18 or later, no dependencies.
//   WEBHOOK_SECRET=... SLACK_WEBHOOK_URL=https://hooks.slack.com/services/... node github-alerts.mjs
import { createServer } from "node:http";
import { createHmac, timingSafeEqual } from "node:crypto";

const SECRET = process.env.WEBHOOK_SECRET;
const SLACK = process.env.SLACK_WEBHOOK_URL;
const PORT = Number(process.env.PORT ?? 3000);
if (!SECRET || !SLACK) throw new Error("Set WEBHOOK_SECRET and SLACK_WEBHOOK_URL");

// A file whose NAME means credentials. Templates like .env.example are left out on purpose.
const CREDENTIAL_FILE =
  /(^|\/)(\.env(\.(local|production|prod|staging|development|dev))?|id_(rsa|dsa|ecdsa|ed25519)|credentials\.json|\.npmrc|\.pypirc|[^/]+\.tfvars|[^/]+\.(pem|pfx|p12|jks))$/;
const DISMISSED = new Set(["false_positive", "wont_fix", "used_in_tests"]);

function signatureOk(body, header) {
  const expected = Buffer.from("sha256=" + createHmac("sha256", SECRET).update(body).digest("hex"));
  const given = Buffer.from(String(header ?? ""));
  return expected.length === given.length && timingSafeEqual(expected, given);
}

function changedFiles(push) {
  const files = new Set();
  for (const commit of push.commits ?? []) {
    for (const f of [...(commit.added ?? []), ...(commit.modified ?? [])]) files.add(f);
  }
  return [...files];
}

// One function per webhook event. Each returns a message, or undefined for "ignore".
const rules = {
  repository(p) {
    const repo = p.repository.full_name;
    if (p.action === "publicized") return `:rotating_light: ${repo} was made PUBLIC by ${p.sender.login}`;
    if (p.action === "created" && p.repository.visibility === "public")
      return `:warning: New public repository ${repo}, created by ${p.sender.login}`;
    if (p.action === "renamed") return `:warning: ${p.changes.repository.name.from} was renamed to ${repo} by ${p.sender.login}`;
    if (p.action === "deleted" || p.action === "transferred") return `:warning: ${repo} was ${p.action} by ${p.sender.login}`;
  },

  organization(p) {
    const role = p.membership?.role ?? p.invitation?.role;
    if ((p.action === "member_added" || p.action === "member_invited") && role === "admin") {
      const who = p.membership?.user?.login ?? p.invitation?.login ?? p.invitation?.email;
      return `:rotating_light: ${who} was made an OWNER of ${p.organization.login} by ${p.sender.login}`;
    }
  },

  member(p) {
    const role = p.changes?.role_name?.to ?? p.changes?.permission?.to;
    if (p.action === "added" || (p.action === "edited" && (role === "admin" || role === "write")))
      return `:warning: ${p.member.login} has ${role ?? "new"} access to ${p.repository.full_name} (by ${p.sender.login})`;
  },

  branch_protection_rule(p) {
    if (p.action === "deleted")
      return `:rotating_light: Branch protection for "${p.rule.name}" was deleted on ${p.repository.full_name} by ${p.sender.login}`;
  },

  repository_ruleset(p) {
    if (p.action === "deleted")
      return `:rotating_light: Ruleset "${p.repository_ruleset.name}" was deleted by ${p.sender.login}`;
  },

  push(p) {
    const repo = p.repository.full_name;
    if (p.ref.startsWith("refs/tags/") && p.forced) return `:rotating_light: Tag ${p.ref.slice(10)} was moved by a force push on ${repo}`;
    const branch = p.ref.replace("refs/heads/", "");
    const onDefault = branch === p.repository.default_branch;
    const files = changedFiles(p);
    const found = [];
    if (p.forced && onDefault) found.push("force push");
    const workflows = files.filter((f) => f.startsWith(".github/workflows/"));
    if (onDefault && workflows.length) found.push(`workflow changed: ${workflows.join(", ")}`);
    const secrets = files.filter((f) => CREDENTIAL_FILE.test(f));
    if (secrets.length) found.push(`credential file committed: ${secrets.join(", ")}`);
    if (found.length) return `:warning: ${repo} (${branch}), pushed by ${p.pusher.name}: ${found.join("; ")}`;
  },

  deploy_key(p) {
    if (p.action === "created")
      return `:warning: Deploy key "${p.key.title}" (${p.key.read_only ? "read-only" : "READ-WRITE"}) added to ${p.repository.full_name} by ${p.sender.login}`;
  },

  secret_scanning_alert(p) {
    const a = p.alert;
    const what = `${a.secret_type_display_name ?? a.secret_type} in ${p.repository.full_name}`;
    if (["created", "validated", "publicly_leaked"].includes(p.action))
      return `:rotating_light: Secret scanning (${p.action}): ${what}, validity ${a.validity ?? "unknown"}. Rotate it first. ${a.html_url}`;
    if (p.action === "resolved" && DISMISSED.has(a.resolution))
      return `:warning: Secret alert dismissed as ${a.resolution} by ${a.resolved_by?.login}: ${what}. Was it rotated? ${a.html_url}`;
  },

  security_and_analysis(p) {
    const before = p.changes?.from?.security_and_analysis ?? {};
    const now = p.repository.security_and_analysis ?? {};
    const off = Object.keys(before).filter((k) => before[k]?.status === "enabled" && now[k]?.status === "disabled");
    if (off.length) return `:rotating_light: ${off.join(", ")} turned OFF on ${p.repository.full_name} by ${p.sender?.login}`;
  },

  personal_access_token_request(p) {
    if (p.action === "created")
      return `:warning: ${p.personal_access_token_request.owner.login} asked for a fine-grained token into ${p.organization.login}`;
  },
};

async function notify(text) {
  const res = await fetch(SLACK, {
    method: "POST",
    headers: { "content-type": "application/json" },
    body: JSON.stringify({ text }),
  });
  if (!res.ok) console.error(`Slack answered ${res.status}`);
}

createServer(async (req, res) => {
  if (req.method !== "POST") return res.writeHead(405).end();
  const chunks = [];
  for await (const chunk of req) chunks.push(chunk);
  const body = Buffer.concat(chunks);
  if (!signatureOk(body, req.headers["x-hub-signature-256"])) return res.writeHead(401).end();
  res.writeHead(202).end(); // GitHub wants a 2xx within 10 seconds, so answer before doing any work

  const event = req.headers["x-github-event"];
  try {
    const text = rules[event]?.(JSON.parse(body));
    if (text) await notify(text);
  } catch (err) {
    console.error(`${event} ${req.headers["x-github-delivery"]}:`, err);
  }
}).listen(PORT, () => console.log(`Listening on :${PORT}`));

A few choices in there are deliberate:

  • The signature is checked on the raw bytes, before JSON.parse. Re-serializing parsed JSON changes the bytes and breaks the HMAC. timingSafeEqual avoids leaking the signature one byte at a time through response timing.
  • It answers 202 before doing any work. GitHub's docs say your server "should respond with a 2XX response within 10 seconds", or GitHub "terminates the connection and considers the delivery a failure." A slow Slack call shouldn't fail a delivery.
  • Force pushes and workflow changes only count on the default branch. On feature branches they are routine, and an alert that fires on every rebase gets muted by Friday.
  • Credential files count on every branch. A .env on a throwaway branch is still in the repository's history. The regex anchors on the end of the path, so .env.example and .env.sample don't match.
  • A dismissed secret alert is its own alert, but only for false_positive, wont_fix and used_in_tests. Closing a GitHub alert revokes nothing, and those three reasons are how a live key gets closed without being rotated. revoked is the good ending, so it stays quiet.
  • A force-pushed tag is always an alert. That's how tj-actions and Trivy were turned against their users. If you publish an action, you want to know the moment a tag moves.

Step 2: run it and add the webhook

Run it anywhere that can take HTTPS traffic from GitHub. Generate the secret with something like openssl rand -hex 32, and use a Slack incoming webhook URL for a channel people actually read.

export WEBHOOK_SECRET="$(openssl rand -hex 32)"
export SLACK_WEBHOOK_URL="https://hooks.slack.com/services/..."
node github-alerts.mjs

Then, in your organization's settings, open Webhooks and add one:

  • Payload URL: your receiver's HTTPS address
  • Content type: application/json
  • Secret: the same value as WEBHOOK_SECRET
  • Events: choose "Let me select individual events" and tick these: branch protection rules, deploy keys, members, organizations, personal access token requests, pushes, repositories, repository rulesets, secret scanning alerts, and security and analysis

An organization webhook covers every repository in the organization, including ones created after you add it. That matters for the tpcp-docs case.

One caveat on secret scanning: on private repositories it only runs with GitHub Secret Protection, $19 per active committer a month as of November 29, 2026. Without it, secret_scanning_alert only arrives for public repositories, and the file-name rule above is doing the work alone.

Step 3: the settings with no webhook

Some of the most important changes never reach a webhook. Turning off the organization's two-factor requirement shows up in the audit log as org.disable_two_factor_requirement, but the organization webhook only reports members being added, invited or removed, renames and deletion. So read the settings on a schedule and diff them:

#!/usr/bin/env bash
# check-org-settings.sh ORG: the settings no webhook reports. Run it every few hours and diff
# the output against the last run. Needs `gh` signed in as an organization owner (read:org).
set -euo pipefail
org="$1"

echo "== organization settings"
gh api "orgs/$org" --jq '{two_factor_requirement_enabled, default_repository_permission, members_can_create_public_repositories}'

echo "== members without 2FA"
gh api --paginate "orgs/$org/members?filter=2fa_disabled" --jq '.[].login'

echo "== owners"
gh api --paginate "orgs/$org/members?role=admin" --jq '.[].login'

echo "== outside collaborators"
gh api --paginate "orgs/$org/outside_collaborators" --jq '.[].login'

Run it from cron, or from a scheduled GitHub Actions workflow with a token that has read:org, save the output, and alert when it differs from the last run. Only owners can see two_factor_requirement_enabled and the 2fa_disabled filter.

How I tested it

I didn't point this at a production organization. I wrote a small harness that starts a fake Slack endpoint, starts the receiver, and sends it 30 signed payloads shaped from GitHub's published webhook schemas (@octokit/openapi-webhooks-types 12.1.0): one for each alert above, plus near-misses that must stay quiet, like a force push to a feature branch, a .env.example, a secret alert resolved as revoked, and a member added without the admin role. It also sends one payload with a wrong signature and one GET.

PASS  made public                            status=202 alert=true
PASS  new public repo (tpcp-docs)            status=202 alert=true
PASS  renamed (s1ngularity)                  status=202 alert=true
PASS  workflow on main (GhostAction)         status=202 alert=true
PASS  workflow on feature branch             status=202 alert=false
PASS  .env.example only                      status=202 alert=false
PASS  tag moved (Trivy)                      status=202 alert=true
PASS  secret alert resolved revoked          status=202 alert=false
PASS  bad signature rejected                 status=401
...
32/32 passed. Receiver stderr: (empty)

The gh api calls ran read-only against a real organization, so the fields and filters exist. What the harness can't prove is that every real delivery looks exactly like the schema. If a field is missing, the try logs the event name and delivery ID instead of crashing, and GitHub's delivery log lets you redeliver it once you've fixed the rule.

Traps

1. Webhooks are not a history. If your receiver is down, those deliveries fail. GitHub's docs say to redeliver missed webhooks once you're back up, and the redelivery keeps the same X-GitHub-Delivery ID, so you can skip duplicates.

2. A push payload has limits. The commits array holds at most 2,048 commits, and each commit lists at most 3,000 changed files. A huge push can hide the one file you care about. Call the commits API for anything over the limit if that worries you.

3. Mass events flood Slack. s1ngularity made one organization's 700-plus repositories public. This receiver would post 700 messages. Add a per-event rate limit before you rely on it.

4. The organization webhook only sees the organization. Shai-Hulud 2.0 created more than 25,000 repositories in victims' own accounts. Your org webhook won't see a repository in an employee's personal account.

5. Your Slack channel is now sensitive. The messages name repositories, people and secret types. Keep the channel private.

What this doesn't solve

You now get a Slack message seconds after something risky happens. It still doesn't tell you whether the person who made dispatch-web public meant to, or that the same account force-pushed to main a minute earlier. It has no memory, no history to search, and nobody on call.

Disclosure: I work on Jutsu, which runs this kind of detection as a GitHub App (22 rules, plus the settings check every six hours), groups related alerts into incidents, and asks the person who made a change whether it was intended. The longer version of this post, with the full event table and the settings to turn on first, is on the Jutsu blog.

Whatever you use, make sure a person reads the channel. An alert nobody reads is just a log.

Which GitHub event would you add? I left out fork of private repositories and new self-hosted runners, and I'm not sure that was right.

📰 Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.