GitHub Pull Request Approved by Bot


Description

A GitHub App or bot submitted an approving review on a pull request. Automation is expected to comment on pull requests, never to approve them: a bot approval can satisfy a required review and let code reach a protected branch without a human reviewer. It may mean a workflow's token was used by the code under review.

Query · python

from panther_github_helpers import github_webhook_alert_context


def is_bot_reviewer(event):
    return event.deep_get("review", "user", "type", default="") == "Bot" or str(
        event.deep_get("review", "user", "login", default="")
    ).endswith("[bot]")


def rule(event):
    return (
        event.get("action") == "submitted"
        and event.deep_get("review", "state", default="") == "approved"
        and is_bot_reviewer(event)
    )


def title(event):
    reviewer = event.deep_get("review", "user", "login", default="<UNKNOWN_REVIEWER>")
    number = event.deep_get("pull_request", "number", default="<UNKNOWN>")
    repo = event.deep_get("repository", "full_name", default="<UNKNOWN_REPO>")
    return f"Bot [{reviewer}] approved pull request #{number} in [{repo}]"


def alert_context(event):
    context = github_webhook_alert_context(event)
    context["reviewer"] = event.deep_get("review", "user", "login")
    context["reviewer_type"] = event.deep_get("review", "user", "type")
    context["review_url"] = event.deep_get("review", "html_url")
    context["pull_request_number"] = event.deep_get("pull_request", "number")
    context["repository_full_name"] = event.deep_get("repository", "full_name")
    return context

Analyst notes

  1. Confirm whether the write or approval came from an approved automation workflow run (the workflow run that minted the token is in the token broker's log).
  2. If it did not: suspend the GitHub App installation for the organisation, or rotate the App's private key, so no further token is minted.
  3. Disable the workflow that performed it.
  4. Revert the commit or dismiss the review, and review every change the token made (same token_id).
  5. Notify Security.
Raw source GitHub Pull Request Approved by Bot · Panther Python
Esc
Published by panther-labs/panther-analysis ↗, licensed under Apache 2.0 ↗. Reproduced here unmodified.
AnalysisType: rule
Filename: github_bot_pull_request_approval.py
RuleID: "GitHub.Webhook.BotPullRequestApproval"
DisplayName: "GitHub Pull Request Approved by Bot"
Enabled: true
LogTypes:
  - GitHub.Webhook
Tags:
  - GitHub
  - No Pack
  - CI/CD
Reports:
  MITRE ATT&CK:
    - TA0001:T1195.002 # Supply Chain Compromise: Compromise Software Supply Chain
Severity: High
Description: >
  A GitHub App or bot submitted an approving review on a pull request. Automation is expected
  to comment on pull requests, never to approve them: a bot approval can satisfy a required
  review and let code reach a protected branch without a human reviewer. It may mean a
  workflow's token was used by the code under review.
Runbook: |
  1. Confirm whether the write or approval came from an approved automation workflow run
     (the workflow run that minted the token is in the token broker's log).
  2. If it did not: suspend the GitHub App installation for the organisation, or rotate the
     App's private key, so no further token is minted.
  3. Disable the workflow that performed it.
  4. Revert the commit or dismiss the review, and review every change the token made
     (same token_id).
  5. Notify Security.
Reference: https://docs.github.com/en/webhooks/webhook-events-and-payloads#pull_request_review
Tests:
  - Name: Bot Approved a Pull Request
    ExpectedResult: true
    Log:
      {
        "action": "submitted",
        "review": {
          "id": 345678,
          "body": "Approved.",
          "state": "approved",
          "user": {
            "login": "my-automation[bot]",
            "type": "Bot"
          },
          "html_url": "https://github.com/org/repo/pull/10#pullrequestreview-345678",
          "submitted_at": "2024-01-15T11:00:00Z"
        },
        "pull_request": {
          "number": 10,
          "title": "Bug fix"
        },
        "repository": {
          "full_name": "org/repo"
        },
        "p_log_type": "GitHub.Webhook"
      }
  - Name: Bot Commented on a Pull Request
    ExpectedResult: false
    Log:
      {
        "action": "submitted",
        "review": {
          "id": 345679,
          "body": "Review comments follow.",
          "state": "commented",
          "user": {
            "login": "my-automation[bot]",
            "type": "Bot"
          },
          "html_url": "https://github.com/org/repo/pull/10#pullrequestreview-345679",
          "submitted_at": "2024-01-15T11:00:00Z"
        },
        "pull_request": {
          "number": 10,
          "title": "Bug fix"
        },
        "repository": {
          "full_name": "org/repo"
        },
        "p_log_type": "GitHub.Webhook"
      }
  - Name: Human Approved a Pull Request
    ExpectedResult: false
    Log:
      {
        "action": "submitted",
        "review": {
          "id": 345680,
          "body": "Looks good!",
          "state": "approved",
          "user": {
            "login": "fake-reviewer",
            "type": "User"
          },
          "html_url": "https://github.com/org/repo/pull/10#pullrequestreview-345680",
          "submitted_at": "2024-01-15T11:00:00Z"
        },
        "pull_request": {
          "number": 10,
          "title": "Bug fix"
        },
        "repository": {
          "full_name": "org/repo"
        },
        "p_log_type": "GitHub.Webhook"
      }
  - Name: Bot Review Dismissed
    ExpectedResult: false
    Log:
      {
        "action": "dismissed",
        "review": {
          "id": 345678,
          "body": "Approved.",
          "state": "dismissed",
          "user": {
            "login": "my-automation[bot]",
            "type": "Bot"
          },
          "html_url": "https://github.com/org/repo/pull/10#pullrequestreview-345678",
          "submitted_at": "2024-01-15T11:00:00Z"
        },
        "pull_request": {
          "number": 10,
          "title": "Bug fix"
        },
        "repository": {
          "full_name": "org/repo"
        },
        "p_log_type": "GitHub.Webhook"
      }


# ------ paired body: github_bot_pull_request_approval.py ------

from panther_github_helpers import github_webhook_alert_context


def is_bot_reviewer(event):
    return event.deep_get("review", "user", "type", default="") == "Bot" or str(
        event.deep_get("review", "user", "login", default="")
    ).endswith("[bot]")


def rule(event):
    return (
        event.get("action") == "submitted"
        and event.deep_get("review", "state", default="") == "approved"
        and is_bot_reviewer(event)
    )


def title(event):
    reviewer = event.deep_get("review", "user", "login", default="<UNKNOWN_REVIEWER>")
    number = event.deep_get("pull_request", "number", default="<UNKNOWN>")
    repo = event.deep_get("repository", "full_name", default="<UNKNOWN_REPO>")
    return f"Bot [{reviewer}] approved pull request #{number} in [{repo}]"


def alert_context(event):
    context = github_webhook_alert_context(event)
    context["reviewer"] = event.deep_get("review", "user", "login")
    context["reviewer_type"] = event.deep_get("review", "user", "type")
    context["review_url"] = event.deep_get("review", "html_url")
    context["pull_request_number"] = event.deep_get("pull_request", "number")
    context["repository_full_name"] = event.deep_get("repository", "full_name")
    return context

Detection rules belong to the projects that publish them and remain under their own licenses. This site indexes and links to them; it claims no rights in them.