fix(github): store oauth tokens per user and secure the callback - #180
Open
kaulith wants to merge 2 commits into
Open
fix(github): store oauth tokens per user and secure the callback#180kaulith wants to merge 2 commits into
kaulith wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes GitHub OAuth authentication by moving credentials to a per-user model, securing the OAuth flow, and ensuring GitHub actions are performed on behalf of the authenticated user instead of the app installation.
Changes
Per-user GitHub tokens
Hive Settingssingleton.GitHub Tokendoctype, with one record per user, which is the intended purpose of the doctype.Fixed OAuth callback flow
Previously, the OAuth callback never completed during the GitHub App installation flow because it required a
stateparameter, while GitHub's post-install redirect does not include one.This PR:
stateparameter in the installation flow.Secured OAuth state validation
The previous implementation decoded an unsigned Base64-encoded JSON payload and compared the embedded user with the current session user.
This was not a secure validation mechanism, as an attacker could craft a callback URL containing their own OAuth code and have another authenticated user associate their Hive account with the attacker's GitHub identity.
The implementation has been replaced with:
This issue was not exploitable previously because the stored access tokens were never used. It becomes exploitable once user tokens are used for GitHub operations, which this PR introduces.
User-authenticated GitHub operations
create_issuenow authenticates using the connected user's GitHub access token instead of the GitHub App installation token.As a result:
Removed unused settings
The following fields have been removed from
Hive Settings:github_access_tokengithub_usernamegithub_authorized_atThese fields are no longer used.
Migration Note
The previous implementation stored
github_access_tokenusingdb_set, which bypasses Frappe's password encryption.If a site has previously connected a GitHub account, the legacy
tabSinglesentry containinggithub_access_tokenshould be removed manually after deploying this change.