T05 · Unauthorized Access and Privilege Escalation
Error
- Location
- scripts/setup_oidc.py:108
- Finding
- Overly Broad GitHub OIDC Subject Pattern Permits Unintended Repositories<![CDATA[ ## Vulnerability Details **File Location**: `scripts/setup_oidc.py`, lines 108-109 **Vulnerability Type**: Overly broad federated identity trust policy **Risk Level**: High ### Vulnerable Code ```python 'StringLike': {'oidc:sub': 'repo:%s*/%s*:ref:refs/heads/%s' % (owner, repo, branch)}, ``` ### Technical Analysis The generated Alibaba Cloud RAM trust policy places wildcards immediately after both the expected GitHub owner and repository names. This creates prefix matching rather than restricting role assumption to one exact repository. For example, a configuration intended for owner `acme` and repository `certs` produces a pattern equivalent to: ```text repo:acme*/certs*:ref:refs/heads/main ``` This may also match subjects associated with similarly prefixed identities, such as: ```text repo:acme-attacker/certs-copy:ref:refs/heads/main ``` The audience and issuer checks do not independently establish that the token belongs to the exact intended repository. GitHub workflows can request a custom audience, so accepting the configured audience does not compensate for an overly broad `sub` condition. ### Attack Path 1. The victim runs `setup_oidc.py` and creates a RAM role using the wildcard subject condition. 2. An attacker creates or controls a GitHub owner and repository whose names share the configured prefixes. 3. The attacker creates a workflow on the configured branch. 4. The workflow requests a GitHub OIDC token using the audience accepted by the Alibaba Cloud OIDC provider. 5. The token contains the legitimate GitHub issuer and requested audience, while its subject matches the prefix-wildcard condition. 6. The attacker submits the token to Alibaba Cloud `AssumeRoleWithOIDC`. 7. If Alibaba Cloud evaluates the subject as matching, it returns temporary STS credentials for the victim's role. ### Impact Assessment Successful exploitation grants the attacker all permissions attached to the OIDC role. With the defa ...[truncated 441 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions Use an exact repository subject whenever possible: ```python 'StringEquals': { 'oidc:iss': ISSUER, 'oidc:aud': audience, 'oidc:sub': 'repo:%s/%s:ref:refs/heads/%s' % (owner, repo, branch), } ``` Additional hardening measures: 1. Avoid prefix wildcards for owner, repository, branch, environment, and workflow identity fields. 2. If multiple subject formats must be supported, enumerate separately verified exact subject values. 3. Consider restricting tokens through a protected GitHub environment and matching its exact environment-based subject. 4. Protect the authorized branch and workflow files with branch protection and mandatory review. 5. Test the resulting trust policy with both accepted and intentionally similar rejected subjects before deployment. 6. Rotate or revoke the role and review cloud audit logs if the broad policy has already been deployed. ]]>
