Skip to content

Commit d9e329e

Browse files
committed
Authorize same-repository caller token
1 parent ca1cc53 commit d9e329e

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

.github/scripts/run-agent-task/build-codebox-task-request.mjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ const request = {
8787
requires_pr: booleanEnv("SUCCESS_REQUIRES_PR"),
8888
},
8989
access: {
90+
caller_repo: requiredString("CALLER_REPO").toLowerCase(),
9091
access_token_repos: repositoryList("ACCESS_TOKEN_REPOS"),
91-
require_access_token: booleanEnv("REQUIRE_ACCESS_TOKEN"),
9292
allowed_repos: parseJson("ALLOWED_REPOS", [], "array"),
9393
},
9494
limits: {
@@ -115,6 +115,9 @@ if (request.access.allowed_repos.some((repository) => typeof repository !== "str
115115
request.access.allowed_repos = [...new Set(request.access.allowed_repos.map((repository) => repository.toLowerCase()))]
116116
request.access.access_token_repos = [...new Set(request.access.access_token_repos.map((repository) => repository.toLowerCase()))]
117117
request.target_repo = request.target_repo.toLowerCase()
118+
if (!/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/.test(request.access.caller_repo)) {
119+
throw new Error("CALLER_REPO must be an OWNER/REPO value.")
120+
}
118121
if (!request.access.allowed_repos.includes(request.target_repo)) {
119122
throw new Error("ALLOWED_REPOS must explicitly include TARGET_REPO.")
120123
}

.github/scripts/run-agent-task/execute-native-agent-task.mjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,11 @@ function accessFailure(request) {
118118
const allowed = Array.isArray(access.allowed_repos) ? access.allowed_repos : []
119119
const tokenRepos = Array.isArray(access.access_token_repos) ? access.access_token_repos : []
120120
const target = string(request.target_repo)
121+
const caller = string(access.caller_repo)
121122
if (!allowed.includes(target) || !tokenRepos.includes(target)) return "Target repository is not explicitly authorized by allowed_repos and access_token_repos."
122-
if (access.require_access_token === true && process.env.ACCESS_TOKEN_CONFIGURED !== "true") return "A configured ACCESS_TOKEN is required but unavailable."
123+
if (!caller) return "Caller repository is required for publication authorization."
124+
if (target !== caller && process.env.EXPLICIT_ACCESS_TOKEN_CONFIGURED !== "true") return "An explicit ACCESS_TOKEN is required for cross-repository publication."
125+
if (!string(process.env.GITHUB_TOKEN)) return "No effective GitHub token is available for runner workspace tools."
123126
return ""
124127
}
125128

0 commit comments

Comments
 (0)