Yuku Kotani 3d56fc960a feat: add allow_bot_users option to control bot user access
- Add allow_bot_users input parameter (default: false)
- Modify checkHumanActor to optionally allow bot users
- Add comprehensive tests for bot user handling
- Improve security by blocking bot users by default

This change prevents potential prompt injection attacks from bot users
while providing flexibility for trusted bot integrations.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-21 11:06:31 +09:00

57 lines
1.5 KiB
TypeScript

#!/usr/bin/env bun
/**
* Check if the action trigger is from a human actor
* Prevents automated tools or bots from triggering Claude
*/
import type { Octokit } from "@octokit/rest";
import type { ParsedGitHubContext } from "../context";
export async function checkHumanActor(
octokit: Octokit,
githubContext: ParsedGitHubContext,
allowedBots: string,
) {
// Fetch user information from GitHub API
const { data: userData } = await octokit.users.getByUsername({
username: githubContext.actor,
});
const actorType = userData.type;
console.log(`Actor type: ${actorType}`);
// Check bot permissions if actor is not a User
if (actorType !== "User") {
// Parse allowed bots list
const allowedBotsList = allowedBots
.split(",")
.map((bot) => bot.trim().toLowerCase())
.filter((bot) => bot.length > 0);
// Check if all bots are allowed
if (allowedBots.trim() === "*") {
console.log(
`All bots are allowed, skipping human actor check for: ${githubContext.actor}`,
);
return;
}
// Check if specific bot is allowed
if (allowedBotsList.includes(githubContext.actor.toLowerCase())) {
console.log(
`Bot ${githubContext.actor} is in allowed list, skipping human actor check`,
);
return;
}
// Bot not allowed
throw new Error(
`Workflow initiated by non-human actor: ${githubContext.actor} (type: ${actorType}). Add bot to allowed_bots list or use '*' to allow all bots.`,
);
}
console.log(`Verified human actor: ${githubContext.actor}`);
}