Skip to content

Fix commit repository authorization (BUG-317102) - #1977

Merged
yongwen merged 3 commits into
masterfrom
fix/BUG-317102
Nov 18, 2026
Merged

yongwen merged 3 commits into
masterfrom
fix/BUG-317102

Conversation

@yongwen

@yongwen yongwen commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Summary

Problem (Why)

Both commit endpoints let baseline readers use Teletraan's broad SCM credential to read arbitrary repositories. GitHub repository input could also alter the outbound API path. Addresses BUG-317102.

Solution (What + How)

  • Keep the existing READ permission and require at least one retained build for the complete repository and selected configured SCM before either endpoint requests SCM data. Repositories without a matching build return HTTP 403, including for administrators.
  • Resolve the default SCM and configured case matching consistently with manager selection. Keep distinct SCM aliases isolated; match GitHub repository names case-insensitively.
  • Check the repository independently of the requested commit, so comparisons, pagination and hotfix views can still read new commits and branches. Deleting the last matching build removes access on the next request.
  • Validate GitHub owner/repository input, encode outbound path segments, and serialize Phabricator parameters as JSON so request fields cannot override the checked repository. Reject missing, malformed or duplicate repository identities before SCM access.

Published build metadata defines a shared repository allowlist: every READ caller can access any repository with a matching build, and publishers can expand it through build metadata. This workaround does not provide per-user repository ownership authorization.

Deployment requires only the service update. No database schema change, migration, new repository grants, GitHub credential change, token issuance change or token cache change is required. Each commit request adds a database existence query; existing indexes do not cover this lookup, so it can scan retained builds.

Test Plan

  • Full clean Maven reactor suite under Temurin 11 with MySQL 8: 872 tests, 0 failures, 0 errors, 0 skipped.
  • Both HTTP routes allow existing READ roles for built repositories, deny repositories without builds even to admins, preserve branch/new-commit access, and reject unauthenticated or ambiguous requests before SCM access.
  • Real database tests cover SCM/repository case rules, distinct aliases, full identity matching, literal wildcard characters, accents, whitespace, injection attempts, overlength inputs and deletion of the last build.
  • GitHub HTTP regression tests cover encoded refs, traversal/query/fragment injection, repository casing and enterprise prefixes. Phabricator tests verify request fields cannot override the checked repository.
  • Scoped Spotless checks on all 11 changed Java files and git diff --check passed.

Require repository-scoped READ grants on both commit endpoints and prevent outbound SCM path or JSON injection. Preserve legitimate references and configured SCM identities.

Provide read-only repository tokens with enforced expiry and revocation, widen grant storage without changing collation semantics, and document the database and caller rollout.
@yongwen
yongwen requested a review from a team as a code owner November 13, 2026 16:55
@github-actions github-actions Bot added the deploy-service Includes changes to deploy-service label Nov 13, 2026
Use the existing MANAGE_SCRIPT_TOKEN permission on SYSTEM for both commit routes, retaining GitHub repository validation and safe URL construction.

Remove repository-specific authorization infrastructure, schema migration, token provisioning and token-cache changes. The resulting patch requires only a service deployment; existing system administrators retain access, while ordinary readers receive 403.
Keep READ access on both commit endpoints and require a retained build for the selected SCM and complete repository identity before SCM access. Preserve new-commit and branch views while blocking repositories without builds, including for admins.

Use safe GitHub URLs and serialized Phabricator parameters. No database schema or GitHub token changes.

Test plan: clean Maven reactor suite passed (872 tests); scoped Spotless and whitespace checks passed.
@yongwen
yongwen requested a review from liyaqin1 November 13, 2026 21:07
// Binary comparison preserves accents, trailing spaces, and complete identities even
// when the table's collation treats those values as equivalent. No prefix or LIKE match.
String query =
HAS_BUILD_FOR_REPOSITORY[caseInsensitiveScm ? 1 : 0][

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this query becomes expensive, we can use caching to help, similar to Entitlements

@yongwen
yongwen merged commit 3ec8ab7 into master Nov 18, 2026
6 checks passed
@yongwen
yongwen deleted the fix/BUG-317102 branch November 18, 2026 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deploy-service Includes changes to deploy-service

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants