BarkleyGitHub
Incident response
Markdown file

Runbooks

Pick what happened. The steps are in the order to do them.

What happened?

Look at the report

Keep it private until the fix is out, so nobody can use it against your users in the meantime.

  1. Accept the report as a draft advisory. A report sent through private vulnerability reporting is on your repository's Security and quality tab, under Advisories. You can ask the reporter questions there, reject it, or choose Accept and open as draft, which keeps it private (GitHub's docs). If the report came another way, such as an email, start a draft advisory yourself on the same page and copy the details in.

  2. POL-4Level 1When a report comes in, fix it in the advisory's private fork, release the fix, then publish the advisory. You can request a CVE from the advisory. If your code is also published as a package on PyPI or npm, Dependabot then alerts the projects that depend on it.

    Publishing the advisory deletes its private fork, so merge the fix first (GitHub's docs).

Afterwards

If the report didn't come through GitHub, set these up so the next one does.

  1. POL-1Level 1Turn on private vulnerability reporting. Settings → Advanced Security → Private vulnerability reporting → Enable. People then get a "Report a vulnerability" button on your Security and quality tab, and their report reaches you privately. You can ask questions, reject it, or accept it as a draft advisory to work in.

  2. POL-2Level 1Level markerAdd a SECURITY.md that points to it. In an organization, one SECURITY.md in its public .github repository covers every repository that doesn't have its own (see Organizations).

    SECURITY.md
    # Security policy
    
    ## Reporting a problem
    
    Please don't open a public issue. Report it privately through
    GitHub: https://github.com/OWNER/REPO/security/advisories/new
    
    I'll reply within 7 days and keep you posted until it's fixed.
    
    ## Supported versions
    
    Only the latest release gets security fixes.
  3. REPO-2Level 1Turn off blank issues and link the private report.

    .github/ISSUE_TEMPLATE/config.yml
    blank_issues_enabled: false
    contact_links:
      - name: Report a security problem
        url: https://github.com/OWNER/REPO/security/advisories/new
        about: Please report security problems privately, not as an issue.

Lock them out

Do these first, from a device you trust. If you can't sign in, or someone changed your email or two-factor settings, contact GitHub Support (GitHub's docs).

  1. Change your password and check your email addresses. Settings → Password and authentication, then Settings → Emails. Remove any address you didn't add.

  2. ACC-1Level 1Turn on two-factor login with a passkey or a security key.

    Why A common way to take over an account is a page that looks like a real login. A password and an authenticator code work on any site you type them into, and a lookalike can pass them straight on to the real one. A passkey or security key only works on the site it was made for. In 2025, phishing like this was used to publish malware from maintainers' accounts on both PyPI and npm (how it happened).

    Settings → Password and authentication. An authenticator app is fine as a second method. Avoid SMS. Store the recovery codes somewhere offline.

    A lookalike login page can pass on an authenticator app's code as well as your password. Add a passkey or a security key, and generate new recovery codes on the same page.

  3. ACC-3Level 1Review what can act for you.

    Why Every OAuth app, GitHub App, SSH key and signed-in session can act for you without your password, and each is another way into your account. Some were probably added years ago for something you no longer use. After the Shai-Hulud worm, CISA's advice included removing the GitHub Apps and OAuth apps you don't need (how it happened).

    Settings → Applications (OAuth apps and GitHub Apps), SSH keys, and Sessions. Remove anything you don't recognize or no longer use.

    Sign out every session you don't recognize, and remove every SSH key and app you didn't add. A new password doesn't stop any of them.

  4. ACC-2Level 1Replace classic personal access tokens with fine-grained ones.

    Why A token works for anyone who has a copy, with no password or 2FA, and copies end up in CI secrets, .env files and old laptops. A classic token can act on every repository you can reach and never expires. A fine-grained one only reaches the repository and permissions you gave it, until its expiry date. The Shai-Hulud worm collected tokens like these from developers' machines and CI in 2025 (how it happened).

    Settings → Developer settings → Personal access tokens. Give each token one repository, only the permissions it needs, and an expiry date. Delete tokens you no longer use.

    Delete every token you don't recognize and every token that was on the affected machine, then create new ones.

Find out what was done

Check what was changed while they had access.

  1. Read your security log. Settings → Security log lists what was done with your account in the last 90 days. Look for new tokens, keys, apps and email addresses, and for changes to repositories (GitHub's docs). In an organization, an owner can also read its audit log, which goes back 180 days (GitHub's docs).

  2. Check every repository you can write to. Look at recent commits on every branch, and at collaborators, deploy keys, webhooks and workflows. If a release or a tag changed, also pick A bad release went out above.

  3. Replace the repositories' secrets. Anyone who can push a workflow can use a repository's Actions secrets, so treat them as leaked. Get a new credential from wherever each one came from, such as PyPI or npm, update the secret, then revoke the old one.

Afterwards

With signed commits, a commit pushed with a stolen token shows "Unverified". With no stored secrets, CI has nothing to take.

  1. ACC-4Level 2Level markerSign your commits.

    Why Git lets anyone put any name and email on a commit. A signature can't be made without your key, so signed commits let people tell your work from a commit pushed with a stolen token or written to look like yours. In 2021, two malicious commits were pushed to PHP's source code in the names of two of its core developers (PHP's announcement).

    An SSH key is the simplest way. You can use the one you already push with.

    1. If you don't have an SSH key, run ssh-keygen -t ed25519. It saves the public half as ~/.ssh/id_ed25519.pub.
    2. Tell Git to sign every commit and tag with it.
      Terminal
      git config --global gpg.format ssh
      git config --global user.signingkey ~/.ssh/id_ed25519.pub
      git config --global commit.gpgsign true
      git config --global tag.gpgsign true
      Change the path if your key has a different name.
    3. Give GitHub the public key, so it can check your signatures. Until you do, your signed commits show "Unverified". In Settings → SSH and GPG keys, choose New SSH key, set Key type to Signing Key, and paste the line that cat ~/.ssh/id_ed25519.pub prints. Only share the file ending in .pub. The one without .pub is your private key. From a terminal, the GitHub CLI can do it instead:
      Terminal
      gh auth refresh -h github.com -s admin:ssh_signing_key
      gh ssh-key add ~/.ssh/id_ed25519.pub --type signing --title "My laptop"
      A key you already added for pushing has to be added again as a signing key.

    Where the private key is kept decides what someone gets if they copy your files or run code on your machine:

    Where the key isSomeone copies your filesMalware runs as youDay to day
    A file with no passphraseThey have your keyCan signNothing to type
    A file with a passphrase, loaded into the SSH agentUseless without the passphraseCan sign while the key is loadedUnlock once per login. macOS can keep the passphrase in Keychain.
    A password manager's SSH agentThere's no key fileAsks before each app uses the keyApprove each app
    A security key (ssh-keygen -t ed25519-sk)The key never leaves the hardwareNeeds a touch for every signatureA touch for every commit, so a rebase of 20 commits is 20 touches

    With a password manager, its own instructions give the value for user.signingkey. GPG keys work too, with GitHub's GPG instructions.

    In a codespace you don't need a key of your own. Turn on Settings → Codespaces → GPG verification for the repositories you trust, and GitHub signs the commits you make there. Commits you make on GitHub's website are signed by GitHub already.

  2. ACC-5Level 2Then turn on vigilant mode.

    Why Signing only helps if an unsigned commit in your name stands out. Without vigilant mode, GitHub shows an unsigned commit with no label, like most commits. With it on, an unsigned commit in your name shows "Unverified".

    On the same page, tick "Flag unsigned commits as unverified". Any commit with your name that you didn't sign then shows "Unverified", including one pushed with a stolen token. Wait until a commit you push shows "Verified", or your own commits show "Unverified" too.

  3. SEC-4Level 2In CI, prefer no secret at all. Use the built-in GITHUB_TOKEN with the narrowest permissions, and trusted publishing (OpenID Connect) to publish to PyPI or npm instead of a long-lived token.

Revoke it

Revoke it before anything else. Cleaning it out of the code or the history can wait.

  1. SEC-5Level 1If a secret leaks, revoke it first. Removing it from the history doesn't help, because clones, forks and caches already have a copy. Issue a new key, then clean up the history.

  2. Check what it was used for. For a GitHub token, your security log shows what was done with it (GitHub's docs). For a PyPI or npm token, look at the package's release history for versions you didn't publish. For another service's key, check that service's logs. If a release changed, also pick A bad release went out above.

  3. Find out how it got out. It might have been a commit, a workflow log or a lost laptop. Fix that too, or the new key can leak the same way.

Afterwards

These keep the next key out of the repository, and leave fewer keys to leak.

  1. REPO-3Level 1Add a .gitignore before your first commit.

    .gitignore
    # Python
    __pycache__/
    *.py[cod]
    .venv/
    .pytest_cache/
    .ruff_cache/
    .coverage
    
    # Node
    node_modules/
    
    # Secrets and local settings
    .env
    .env.*
    secrets.yaml
    *.pem
    *.key
    
    # Editors and OS
    .idea/
    .DS_Store
  2. CI-3Level 1Turn on secret scanning and push protection. Settings → Advanced Security. Push protection stops a push that contains a known token format before it reaches GitHub.

  3. ACC-2Level 1Replace classic personal access tokens with fine-grained ones.

    Why A token works for anyone who has a copy, with no password or 2FA, and copies end up in CI secrets, .env files and old laptops. A classic token can act on every repository you can reach and never expires. A fine-grained one only reaches the repository and permissions you gave it, until its expiry date. The Shai-Hulud worm collected tokens like these from developers' machines and CI in 2025 (how it happened).

    Settings → Developer settings → Personal access tokens. Give each token one repository, only the permissions it needs, and an expiry date. Delete tokens you no longer use.

  4. SEC-4Level 2In CI, prefer no secret at all. Use the built-in GITHUB_TOKEN with the narrowest permissions, and trusted publishing (OpenID Connect) to publish to PyPI or npm instead of a long-lived token.

Take it down

If someone else published it, lock them out first. Pick Someone got into my GitHub account or A token or key leaked above, then come back.

  1. Work out which versions are bad. Compare each recent release's files and tag with main. A tag on a commit that isn't on main, or a file your workflow didn't build, is suspect. If your releases are attested, gh attestation verify fails for a file your workflow didn't build (Releases).

  2. Delete the bad releases. Delete each one, and its tag, on the repository's Releases page. An immutable release can be deleted too, but its tag name can't be used again (GitHub's docs). For an app, also delete the image version on the package's page (GitHub's docs). If you published to PyPI or npm, remove it there as well.

  3. Release a fixed version with a higher number. A higher version than the bad one moves everyone past it on their next update. Build it from main with your release workflow.

  4. Tell your users. Publish a security advisory that lists the bad versions and the fixed one (Security policy), and pin an issue that says the same. If the bad version could have taken something from users, such as passwords or tokens, say what, so they can change it.

Afterwards

These tie each release to a workflow run on main, so a release made any other way is easy to spot.

  1. REL-1Level 3Level markerBuild and publish releases from a workflow instead of your laptop. This one zips an integration, refuses a tag that isn't on main, adds a provenance attestation, and publishes the release with the zip in one step.

    .github/workflows/release.yaml
    name: Release
    on:
      push:
        tags: ["v*"]
    permissions:
      contents: write
      id-token: write
      attestations: write
    jobs:
      release:
        runs-on: ubuntu-latest
        steps:
          - uses: actions/checkout@v7
            with:
              fetch-depth: 0
          - name: Only release code that's on main
            run: git merge-base --is-ancestor "$GITHUB_SHA" origin/main
          - name: Zip the integration
            run: |
              cd custom_components/your_domain
              zip -r "$GITHUB_WORKSPACE/your_domain.zip" .
          - uses: actions/attest-build-provenance@v4
            with:
              subject-path: your_domain.zip
          - name: Publish the release
            env:
              GH_TOKEN: ${{ github.token }}
            run: gh release create "$GITHUB_REF_NAME" your_domain.zip --verify-tag --generate-notes

    Tell the Marketplace to install the zip with "zip_release": true and "filename": "your_domain.zip" in hacs.json. For a card, build the bundle in the workflow and attach the built file instead.

    The "Only release code that's on main" step catches a tag pushed from the wrong branch by mistake. It can't stop someone with write access. The workflow that runs is the one in the tagged commit, so they could tag a commit whose workflow leaves that step out. A tag ruleset with Restrict creations stops that, because only the people on its bypass list can create release tags (see Branch and tag protection).

  2. BR-4Level 3 (or immutable releases)Level markerAdd a tag ruleset for your release tags. Settings → Rules → Rulesets → New tag ruleset.

    • Enforcement: Active. A disabled ruleset protects nothing.
    • Target: v*, or however you name versions.
    • Turn on Restrict updates and Restrict deletions, so a published version can't be moved to different code later.
    • Turn on Restrict creations if only you should cut releases. Then add the Repository admin role to the bypass list, or you won't be able to push new tags either.
  3. REL-3Level 3 (or a tag ruleset)Level markerTurn on immutable releases (Settings → General → Releases), so a published release's files and tag can't be swapped later. It applies to releases you publish after turning it on. Because assets can't be added after publishing, the workflow above creates the release and its file together.

  4. SEC-4Level 2In CI, prefer no secret at all. Use the built-in GITHUB_TOKEN with the narrowest permissions, and trusted publishing (OpenID Connect) to publish to PyPI or npm instead of a long-lived token.

Open the full page