Skip to content

Commit 6c84303

Browse files
authored
oidc/github: make repo comparison insensitive (#15501)
This fixes the immediate bug in #15498. Closes #15498. Signed-off-by: William Woodruff <[email protected]>
1 parent 5f621eb commit 6c84303

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

tests/unit/oidc/models/test_github.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,27 @@ def test_github_publisher_verifies(self, monkeypatch, environment, missing_claim
244244
optional_verifiable_claims
245245
)
246246

247+
@pytest.mark.parametrize(
248+
("truth", "claim", "valid"),
249+
[
250+
# invalid: claim should never be empty or missing
251+
("", None, False),
252+
("foo", None, False),
253+
("", "", False),
254+
("foo", "", False),
255+
# valid: exact and case-insensitive matches
256+
("foo", "foo", True),
257+
("Foo", "foo", True),
258+
("Foo", "Foo", True),
259+
("foo", "Foo", True),
260+
("FOO", "foo", True),
261+
("foo", "FOO", True),
262+
],
263+
)
264+
def test_check_repository(self, truth, claim, valid):
265+
check = github.GitHubPublisher.__required_verifiable_claims__["repository"]
266+
assert check(truth, claim, pretend.stub()) == valid
267+
247268
@pytest.mark.parametrize(
248269
("claim", "ref", "sha", "valid", "expected"),
249270
[

warehouse/oidc/models/github.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@
2727
)
2828

2929

30+
def _check_repository(ground_truth, signed_claim, all_signed_claims):
31+
# Defensive: GitHub should never give us an empty repository claim.
32+
if not signed_claim:
33+
return False
34+
35+
# GitHub repository names are case-insensitive.
36+
return signed_claim.lower() == ground_truth.lower()
37+
38+
3039
def _check_job_workflow_ref(ground_truth, signed_claim, all_signed_claims):
3140
# We expect a string formatted as follows:
3241
# OWNER/REPO/.github/workflows/WORKFLOW.yml@REF
@@ -112,7 +121,7 @@ class GitHubPublisherMixin:
112121

113122
__required_verifiable_claims__: dict[str, CheckClaimCallable[Any]] = {
114123
"sub": _check_sub,
115-
"repository": check_claim_binary(str.__eq__),
124+
"repository": _check_repository,
116125
"repository_owner": check_claim_binary(str.__eq__),
117126
"repository_owner_id": check_claim_binary(str.__eq__),
118127
"job_workflow_ref": _check_job_workflow_ref,

0 commit comments

Comments
 (0)