githubauthorizationgithub-apigithub-app

How to securely associate a Github App Install ID with the account of a website integrating with the GitHub App?


I'm in the process of building a website integrated around a GitHub App of mine.

This website has its own users (from Google oAuth), who can connect their account to their GitHub account by installing my GitHub application.

There's something in the GitHub App install process I cannot wrap my head around:

After a user installs my App on GitHub:

The install ID is a sensible info, as if a malicious user of my website (the attacker) can trick my website into associating their account with the GitHub Install ID of somebody else (the victim), my website would operate on the GitHub API of the victim on behalf of the attacker (which is bad!).

Now, my goal is to securely bind this install ID to the user of my website. By secure, I mean that it is impossible for my website to grant an attacker permissions on a victim GitHub install of my app.

Using the GitHub install ID provided in the "Post install Setup URL" to bind this install to an account of my website is insecure, as I have no way to validate that this install ID "belongs" to the user of my website, as the URL can be forged by an attacker knowing a valid install ID of a victim.

Imperfect mitigations:

Am I missing something, or is this a flaw of the App authorization model ?


Solution

  • Found the answer:

    I needed to activate "Request user authorization (OAuth) during installation". This way, GitHub answers with a secure token that I can use to validate the installation instead of just the installation ID.

    Documentation: https://docs.github.com/en/free-pro-team@latest/developers/apps/identifying-and-authorizing-users-for-github-apps#web-application-flow