Skip to content

[actions] Add detection for workflow_dispatch TOCTOU #19835

Open

Description

@AdnaneKhan

Description of the issue

There is a newer variation of GitHub Actions TOCTOU vulnerabilities known as "Workflow dispatch TOCTOU" - I wrote about a real-world example in a recent bug report writeup:

https://adnanthekhan.com/posts/dependabot-core-toctou-writeup/

I think this is a good candidate for a High detection where a PR has the following characteristics:

  • Runs on workflow dispatch / repository dispatch with the PR number as an input parameter. Does NOT require a commit SHA.
  • Checks out code from that PR without some approval check.
  • Runs code.

High because there is a lot of context required to understand if a maintainer would actually ever run the workflow on a fork, and that is not possible to determine via static analysis alone.

I believe this would require some code changes in the library code - adding a concept of a non externally triggered workflow that is intended to act upon untrusted code. This could then fire the UntrustedCheckoutTOCTOU alert

Activity

  1. rvermeulen commented on Jun 24, 2025

    @rvermeulen
    Contributor

    Hi @AdnaneKhan,

    Thanks for the suggestion.
    Have you tried or looked at https://github.com/github/codeql/tree/main/actions/ql/src/Security/CWE-367?

  2. AdnaneKhan commented on Jun 24, 2025

    @AdnaneKhan
    ContributorAuthor

    Hmm - I look a closer look and while it seems like it would catch this, the workflow_dispatch trigger only leads to results when the workflow is pulling some untrusted context and then using some untrusted context and acting upon it.

    From

    :

    extensions:
      - addsTo:
          pack: codeql/actions-all
          extensible: externallyTriggerableEventsDataModel
        data:
          - ["discussion"]
          - ["discussion_comment"]
          - ["fork"]
          - ["watch"]
          - ["issue_comment"]
          - ["issues"]
          - ["pull_request_comment"]
          - ["pull_request_review"]
          - ["pull_request_review_comment"]
          - ["pull_request"]
          - ["pull_request_target"]
          - ["workflow_run"] # depending on branch filter
          - ["workflow_call"] # depending on caller
          - ["workflow_dispatch"] 
          - ["scheduled"]
    

    However, when we drill down into actions/ql/lib/codeql/actions/security/UntrustedCheckoutQuery.qll, we see:

    string checkoutTriggers() {
      result = ["pull_request_target", "workflow_run", "workflow_call", "issue_comment"]
    }
    

    This means that the unstrusted checkout property (which is required to get a checkout TOCTOU) will never apply unless the trigger is one of the above.

  3. rvermeulen commented on Jun 25, 2025

    @rvermeulen
    Contributor

    I think that workflow_dispatch is deliberatly not including because it requires an explicit user action, wheras the others can be automatically triggered (a dispatch can in also be automatically dispatched, but that requires a workaround.).

    I will inform the team about your suggestion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ActionsAnalysis of GitHub ActionsquestionFurther information is requested

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions