Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
7073906
feat(commitperclip): add get-bot-token.mjs — generate installation token
brandonburr May 20, 2026
4accce2
feat(commitperclip): add PR template compliance gate
brandonburr May 20, 2026
7594fa1
feat(commitperclip): add linked issue gate
brandonburr May 20, 2026
09a75ec
feat(commitperclip): add test coverage gate
brandonburr May 20, 2026
34250da
feat(commitperclip): add lockfile guard gate
brandonburr May 20, 2026
96835c3
fix: exempt .github/scripts/check-*.mjs from gitignore
brandonburr May 20, 2026
3cae559
fix(commitperclip): tighten #NNN pattern — require non-word boundary …
brandonburr May 20, 2026
7ba72c5
feat(commitperclip): add new dependency notice gate
brandonburr May 20, 2026
77db6c7
feat(commitperclip): add quality gate orchestrator with comment upsert
brandonburr May 20, 2026
6ea25e7
fix(commitperclip): deduplicate findExistingComment API call in orche…
brandonburr May 20, 2026
77b5a14
feat(commitperclip): add security gate with 6 checks and draft adviso…
brandonburr May 20, 2026
c488368
feat(commitperclip): add PR review workflow, CodeQL analysis, and Dep…
brandonburr May 20, 2026
5900144
feat(commitperclip): add security-review check run — pending blocks m…
brandonburr May 20, 2026
547aa3f
feat(commitperclip): add Dependency Review gate — fails on CVE-vulner…
brandonburr May 20, 2026
8d9d967
fix: remove duplicate codeql.yml — CodeQL already runs via repo defau…
brandonburr May 20, 2026
7b80285
fix: sanitize PR_NUMBER and GH_REPO before URL construction (SSRF)
brandonburr May 20, 2026
4e33ee0
feat(commitperclip): make gates conventional-commit-aware — skip docs…
brandonburr May 20, 2026
2a7d74a
fix: re-derive sensitive paths against current master + reframe lockf…
brandonburr May 30, 2026
16e65f7
feat(commitperclip): self-validate SENSITIVE_PATHS — fail workflow lo…
brandonburr May 30, 2026
10f04b4
fix(commitperclip): paginate PR file fetches
devinfoley May 30, 2026
128d8fd
fix(commitperclip): scope token installs and base refs
devinfoley May 30, 2026
8745685
fix(commitperclip): tighten linked issue URL matching
devinfoley May 30, 2026
321581b
fix(commitperclip): address remaining Greptile security feedback
devinfoley May 30, 2026
a2cff69
fix(commitperclip): close remaining Greptile gaps
devinfoley May 30, 2026
d914753
fix(commitperclip): harden security gate parsing
devinfoley May 30, 2026
87f155c
fix(commitperclip): count bullets and paragraphs as sentences
devinfoley Jun 1, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: 2
updates:
- package-ecosystem: npm
directory: "/"
schedule:
interval: weekly
day: monday
time: "06:00"
open-pull-requests-limit: 10
labels:
- "dependencies"
ignore:
# Ignore major version bumps — review those manually
- dependency-name: "*"
update-types: ["version-update:semver-major"]

- package-ecosystem: github-actions
directory: "/"
schedule:
interval: weekly
day: monday
time: "06:00"
open-pull-requests-limit: 5
66 changes: 66 additions & 0 deletions .github/scripts/check-pr-dependencies.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env node
/**
* check-pr-dependencies.mjs
* Detects new npm packages added in this PR vs. the base branch.
* Never fails (informational only) — outputs { passed: true, informational: string[] }
*/
import { fileURLToPath } from 'node:url';
import { ghFetch } from './get-bot-token.mjs';

export async function checkDependencies(files, token, repo, prNumber) {
Comment thread
devinfoley marked this conversation as resolved.
Resolved
const pkgFiles = files.filter(
f => f.filename.endsWith('package.json') &&
!f.filename.includes('node_modules') &&
f.status !== 'removed'
);

if (pkgFiles.length === 0) return { passed: true, informational: [] };

const newPackages = new Set();

for (const file of pkgFiles) {
try {
const [baseRes, prRes] = await Promise.all([
ghFetch(`/repos/${repo}/contents/${file.filename}?ref=master`, token),
Comment thread
devinfoley marked this conversation as resolved.
Resolved
ghFetch(`/repos/${repo}/contents/${file.filename}?ref=refs/pull/${prNumber}/head`, token),
]);

const basePkg = JSON.parse(Buffer.from(baseRes.content, 'base64').toString());
const prPkg = JSON.parse(Buffer.from(prRes.content, 'base64').toString());

const baseDeps = new Set([
...Object.keys(basePkg.dependencies ?? {}),
...Object.keys(basePkg.devDependencies ?? {}),
...Object.keys(basePkg.peerDependencies ?? {}),
]);

for (const dep of [
...Object.keys(prPkg.dependencies ?? {}),
...Object.keys(prPkg.devDependencies ?? {}),
...Object.keys(prPkg.peerDependencies ?? {}),
]) {
if (!baseDeps.has(dep)) newPackages.add(dep);
}
} catch {
// File may not exist on base — skip
}
}

if (newPackages.size === 0) return { passed: true, informational: [] };

const pkgList = [...newPackages].map(p => `\`${p}\``).join(', ');
return {
passed: true,
informational: [
`📦 New dependencies added: ${pkgList}. Review may take longer and new dependencies ` +
`are less likely to be accepted — please check if existing deps cover this need.`,
],
};
}

if (process.argv[1] === fileURLToPath(import.meta.url)) {
const { GH_TOKEN, GH_REPO, PR_NUMBER, PR_FILES } = process.env;
const files = JSON.parse(PR_FILES ?? '[]');
const result = await checkDependencies(files, GH_TOKEN, GH_REPO, PR_NUMBER);
console.log(JSON.stringify(result));
}
36 changes: 36 additions & 0 deletions .github/scripts/check-pr-linked-issue.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env node
/**
* check-pr-linked-issue.mjs
* Checks that a PR body references a GitHub issue.
* Export: checkLinkedIssue(prBody: string) → { passed: boolean, failures: string[] }
*/
import { fileURLToPath } from 'node:url';

const ISSUE_PATTERNS = [
/(?:fixes|closes|resolves)\s+#\d+/i,
/\bhttps:\/\/github\.com\/paperclipai\/paperclip\/issues\/\d+/i,
Comment thread
devinfoley marked this conversation as resolved.
Resolved
/(?<!\w)#\d+/,
];

export function checkLinkedIssue(body) {
if (!body || !body.trim()) {
return { passed: false, failures: ['PR body is empty — please fill out the PR template'] };
}

const found = ISSUE_PATTERNS.some(p => p.test(body));
return {
passed: found,
failures: found ? [] : [
'No linked issue found — please add `Fixes #NNN` to your PR description. ' +
'If no issue exists yet, please file one first: ' +
'https://github.com/paperclipai/paperclip/issues/new',
],
};
}

if (process.argv[1] === fileURLToPath(import.meta.url)) {
const body = process.env.PR_BODY ?? '';
const result = checkLinkedIssue(body);
console.log(JSON.stringify(result));
process.exit(result.passed ? 0 : 1);
}
31 changes: 31 additions & 0 deletions .github/scripts/check-pr-lockfile.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env node
/**
* check-pr-lockfile.mjs
* Checks that pnpm-lock.yaml was not manually edited.
* Export: checkLockfile(files, prAuthor, prBranch) → { passed, failures }
*/
import { fileURLToPath } from 'node:url';

export function checkLockfile(files, prAuthor, prBranch) {
const lockfileChanged = files.some(f => f.filename === 'pnpm-lock.yaml');
if (!lockfileChanged) return { passed: true, failures: [] };

const isRefreshBot =
prAuthor === 'github-actions[bot]' && prBranch === 'chore/refresh-lockfile';

return {
passed: isRefreshBot,
failures: isRefreshBot ? [] : [
'Please remove the `pnpm-lock.yaml` changes — this file is managed automatically. ' +
'Run `pnpm install` locally and exclude the lockfile from your commit. ' +
'The lockfile will be refreshed automatically by the refresh bot.',
],
};
}

if (process.argv[1] === fileURLToPath(import.meta.url)) {
const files = JSON.parse(process.env.PR_FILES ?? '[]');
const result = checkLockfile(files, process.env.PR_AUTHOR ?? '', process.env.PR_BRANCH ?? '');
console.log(JSON.stringify(result));
process.exit(result.passed ? 0 : 1);
}
238 changes: 238 additions & 0 deletions .github/scripts/check-pr-security.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
#!/usr/bin/env node
/**
* check-pr-security.mjs
* Runs 6 security checks against a PR diff. Never posts public comments.
* Creates a draft security advisory in the repo if any check fires.
*
* Env: GH_TOKEN, GH_REPO, PR_NUMBER, PR_AUTHOR
* Exit: always 0 — security flags are silent, never block the PR visibly.
*/
import { fileURLToPath } from 'node:url';
import { ghFetch } from './get-bot-token.mjs';

// ── Pure check functions (exported for testing) ───────────────────────────────

const SECRET_PATTERNS = [
{ name: 'OpenAI API key', re: /sk-[a-zA-Z0-9]{32,}/ },
{ name: 'Google API key', re: /AIza[0-9A-Za-z\-_]{35}/ },
{ name: 'AWS access key', re: /AKIA[0-9A-Z]{16}/ },
{ name: 'Private key', re: /-----BEGIN (RSA|EC|OPENSSH) PRIVATE KEY-----/ },
{ name: 'High-entropy secret', re: /[a-zA-Z_]*(key|token|secret|password|credential)[a-zA-Z_]*\s*[=:]\s*["'][^"']{20,}["']/i },
];

export function scanSecrets(files) {
const flags = [];
for (const file of files) {
if (!file.patch) continue;
const added = file.patch.split('\n').filter(l => l.startsWith('+') && !l.startsWith('+++'));
for (const line of added) {
for (const { name, re } of SECRET_PATTERNS) {
if (re.test(line)) {
flags.push({ check: 'secret-scan', file: file.filename, pattern: name, line: line.slice(0, 120) });
}
}
}
}
return flags;
}

const CI_BUILD_SCRIPTS = [
'scripts/release.sh',
'scripts/check-docker-deps-stage.mjs',
'scripts/check-release-package-bootstrap.mjs',
'scripts/release-package-map.mjs',
'scripts/docker-onboard-smoke.sh',
];

export function scanCITampering(files) {
return files
.filter(f => f.filename.startsWith('.github/workflows/') && f.status !== 'removed')
.map(f => ({ check: 'ci-tampering', file: f.filename }));
}

export function scanBuildScripts(files) {
return files
.filter(f => CI_BUILD_SCRIPTS.includes(f.filename) && f.status !== 'removed')
.map(f => ({ check: 'build-script-change', file: f.filename }));
}

export function scanSupplyChain(files) {
const lockfile = files.find(f => f.filename === 'pnpm-lock.yaml');
if (!lockfile?.patch) return [];

const added = new Set();
const removed = new Set();
const PKG_RE = /^([+-])\s{2}'(@?[a-z][a-z0-9\-_./@]*)@[^']+'/;

for (const line of lockfile.patch.split('\n')) {
const m = line.match(PKG_RE);
if (!m) continue;
if (m[1] === '+') added.add(m[2]);
if (m[1] === '-') removed.add(m[2]);
}

const netNew = [...added].filter(p => !removed.has(p));
return netNew.length ? [{ check: 'supply-chain', packages: netNew }] : [];
}

const TEST_FILE_RE = /\.(test|spec)\.(ts|js|tsx|jsx)$|\/tests?\//;
const SUSPICIOUS_PATTERNS = [
{ name: 'outbound-network', re: /\+.*(fetch\(|axios\.|http\.request|https\.request)/ },
{ name: 'env-var-read', re: /\+.*process\.env\.(?!(?:NODE_ENV|CI|TEST|VITEST|npm_))([A-Z_]{4,})/ },
{ name: 'shell-exec', re: /\+.*(execSync\(|spawnSync\(|exec\(|spawn\()/ },
{ name: 'absolute-file-read', re: /\+.*(readFile|readFileSync)\s*\(\s*["'`]?\// },
];

export function scanTestPatterns(files) {
const flags = [];
for (const file of files) {
if (!TEST_FILE_RE.test(file.filename) || !file.patch) continue;
for (const { name, re } of SUSPICIOUS_PATTERNS) {
if (re.test(file.patch)) {
flags.push({ check: 'suspicious-test', file: file.filename, pattern: name });
}
}
}
return flags;
}

const SENSITIVE_PATHS = [
'server/src/routes/agents/',
'server/src/lib/assertCompanyAccess',
'server/src/execution/',
'server/src/adapters/',
'packages/markdown/',
'server/src/routes/imports/',
'server/src/routes/api/',
'server/src/skills/',
'server/src/approval/',
];

export function scanSensitivePaths(files) {
return files
.filter(f => f.status !== 'removed' && SENSITIVE_PATHS.some(p => f.filename.startsWith(p)))
.map(f => ({
check: 'sensitive-path',
file: f.filename,
advisoryPath: SENSITIVE_PATHS.find(p => f.filename.startsWith(p)),
}));
}

// ── Advisory creation ─────────────────────────────────────────────────────────

const SEVERITY_MAP = {
'supply-chain': 'critical',
'sensitive-path': 'critical',
'secret-scan': 'high',
'ci-tampering': 'high',
'suspicious-test': 'high',
'build-script-change': 'medium',
};

const SEVERITY_ORDER = ['low', 'medium', 'high', 'critical'];

function worstSeverity(flags) {
return flags.reduce((worst, f) => {
const s = SEVERITY_MAP[f.check] ?? 'medium';
return SEVERITY_ORDER.indexOf(s) > SEVERITY_ORDER.indexOf(worst) ? s : worst;
}, 'low');
}

async function createAdvisory(token, repo, prNumber, prTitle, flags) {
const checkNames = [...new Set(flags.map(f => f.check))].join(', ');
const severity = worstSeverity(flags);

const description = [
`**PR:** #${prNumber} — ${prTitle}`,
`**Checks triggered:** ${checkNames}`,
'',
'**Details:**',
...flags.map(f => [
`- \`${f.check}\`: ${f.file ?? ''}`,
f.pattern ? ` (pattern: ${f.pattern})` : '',
f.packages ? ` (packages: ${f.packages.join(', ')})` : '',
f.line ? `\n \`${f.line}\`` : '',
].join('')),
'',
'> This advisory was created automatically by commitperclip. Review and dismiss if not a real concern.',
].join('\n');

await ghFetch(`/repos/${repo}/security-advisories`, token, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
summary: `🚨 Security flag — PR #${prNumber}: ${checkNames}`,
description,
severity,
vulnerabilities: [],
}),
});
}

async function postSecurityCheckRun(token, repo, headSha, hasFlags) {
await ghFetch(`/repos/${repo}/check-runs`, token, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(hasFlags ? {
name: 'security-review',
head_sha: headSha,
status: 'in_progress',
output: {
title: 'Security Review Pending',
summary: 'This PR has been flagged for manual security review by a maintainer. No action needed from you.',
},
} : {
name: 'security-review',
head_sha: headSha,
status: 'completed',
conclusion: 'success',
output: {
title: 'Security Review Passed',
summary: 'No security concerns detected.',
},
}),
});
}

// ── Main ──────────────────────────────────────────────────────────────────────

async function main() {
const { GH_TOKEN, GH_REPO, PR_NUMBER } = process.env;

if (!GH_TOKEN || !GH_REPO || !PR_NUMBER) {
console.error('ERROR: GH_TOKEN, GH_REPO, PR_NUMBER required');
process.exit(1);
}

const [pr, files] = await Promise.all([
ghFetch(`/repos/${GH_REPO}/pulls/${PR_NUMBER}`, GH_TOKEN),
ghFetch(`/repos/${GH_REPO}/pulls/${PR_NUMBER}/files?per_page=100`, GH_TOKEN),
]);
Comment thread
devinfoley marked this conversation as resolved.
Resolved

const allFlags = [
...scanSecrets(files),
...scanCITampering(files),
...scanBuildScripts(files),
...scanSupplyChain(files),
...scanTestPatterns(files),
...scanSensitivePaths(files),
];

if (allFlags.length > 0) {
console.error(`[security] ${allFlags.length} flag(s) detected — creating draft advisory and pending check run`);
await Promise.all([
createAdvisory(GH_TOKEN, GH_REPO, PR_NUMBER, pr.title, allFlags),
postSecurityCheckRun(GH_TOKEN, GH_REPO, pr.head.sha, true),
]);
} else {
console.log('[security] all clear');
await postSecurityCheckRun(GH_TOKEN, GH_REPO, pr.head.sha, false);
}

// Always exit 0 — security flags are silent, never block the PR publicly
process.exit(0);
}

if (process.argv[1] === fileURLToPath(import.meta.url)) {
main().catch(e => { console.error(e.message); process.exit(1); });
}
Loading
Loading