Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

skip fork PRs

Matheus Nogueira7671024b2edd
diff --git a/backend/AGENTS.md b/backend/AGENTS.md
index a195fc23d5..a02d61a2cf 100644
--- a/backend/AGENTS.md
+++ b/backend/AGENTS.md
@@ -1233,7 +1233,7 @@ EE routes register before community routes so they can override/extend endpoints
**Secret Scanning** is single-project (see the root `AGENTS.md`): `secret-scanning-v2-project-bootstrap.ts` creates the project with the org when it has a creator to make admin (like PAM and Agent Vault), `secret-scanning-v2-project-resolver.ts` picks the active project and lazily creates it, with every org admin as project admin, for older orgs and for orgs created from the admin console, whose admins are only invited after the org exists, and routes that take `projectId` read `req.internalSecretScanningProjectId`. A data source covers the resources it has rows for (added by a user or discovered from a push); its `config` only says where to look (Bitbucket workspace, GitLab group), never which resources, so scans, "included" state and GitLab account-scope webhooks all key off rows. Stored configs may still carry the old `includeRepos` / `includeProjects` keys, which nothing reads.
-**Secret scanning scans record what started them in `trigger`** (`SecretScanningScanTrigger`: `manual`, `resources-added`, `push`, `pull-request`), separate from `type`, which says how much was scanned (`historical` / `realtime`). Rows from before the column are null. `metadata` (jsonb) holds trigger-specific data and is parsed by trigger; it is omitted from API responses. **GitHub pull request checks** are realtime scans with `trigger: pull-request`, gated on the data source's `isScanNewCommitsEnabled`. A PR on a repository that isn't a resource yet goes through `discoverResource`, the same discovery a push gets (skipped when discovery is off, history scanned when historical scan is on), so both webhooks add repositories the same way. `secret-scanning-v2-queue.ts` stays provider-agnostic: provider behavior goes behind hooks on the data source factory, never behind a provider check in the queue. A scan reported back to where it was requested implements `TSecretScanningScanReport` (`start`, `getCompletedScanMetadata`, `complete`, `fail`, `cancel`), which the factory builds from the diff job payload (`getDiffScanReport`, so a scan whose data source was deleted can still close it) or from the saved scan (`getScanReport`, for the stuck-scan reaper). `getDiffScanFindingsPayload` returns `{ findings, details? }`, where `details` is what the report needs beyond the findings (GitHub: commit counts). Webhook events other than pushes go through `queueDataSourceEvent` as a `TQueueSecretScanningDataSourceEvent` and are handled by the provider factory's optional `processEvent`, which gets `discoverResource` and `queueReportedDiffScan` per call (as `initialize` gets the DAL) (inserts the scan under the ID its report already carries, and closes the report if queueing fails). The `pull_request`, `check_run.rerequested`, `check_suite.rerequested` and `check_run.requested_action` webhook handlers in `github-secret-scanning-service.ts` only enqueue a reduced `TQueueGitHubPullRequestEvent` that way (job ID from the GitHub delivery ID, 3 attempts); `processGitHubPullRequestEvent` in `github-secret-scanning-fns.ts` processes it in the worker. Everything before the check run is created is safe to repeat and nothing after it throws, which is what makes the retries safe. The processor creates the check run *before* the scan row: the scan's uuid is generated in the app and sent as the check run's `external_id`, so a `check_run.rerequested` event (whose `pull_requests` is empty for forks) loads the scan by primary key and reads the PR from `metadata` (`GitHubPullRequestScanMetadataSchema`). `check_suite.rerequested` ("Re-run all checks") names only the suite, so it lists the suite's latest check run with our name and takes the same path from its `external_id`. If the check run can't be created (typically an installation that hasn't accepted the Checks permission), nothing is scanned. The scan lists commits with the compare API pinned to the event's base and head SHAs (not `pulls.listCommits`, which caps at 250 and drifts as commits land) and reuses the push path's per-commit scan, so fingerprints match and findings dedupe with push scans. The check fails on every finding in the PR's commits, not only the rows its own scan inserted: a finding a push scan saved first keeps that scan's `scanId`. Findings triaged `false-positive` or `ignore` don't fail the check: the result is judged on the rows the upsert returns, which carry their stored status, and the scan stores every finding ID in `metadata.findingIds` when it completes. A failing check offers **Skip: False positive** and **Skip: Ignore** (`PULL_REQUEST_CHECK_SKIP_ACTIONS`); the `check_run.requested_action` event verifies the scan belongs to the event's installation and repository, sets that status on the PR's findings like Infisical's own triage (audited per finding, GitHub login in `triageComment`), and starts a new check run. GitHub shows those buttons to anyone with write access to the repository. Every exit of `handleDiffScan` (including a failure before the scan starts) and the stuck-scan reaper closes the check run, since a check left `queued` blocks merging when it is required. The reaper fails realtime scans left `queued` past the stuck-scan timeout as well as stuck `scanning` ones, because a realtime job's payload isn't stored and can't be redelivered; check reporting is best effort after the scan's outcome is committed (diff scans run with one attempt).
+**Secret scanning scans record what started them in `trigger`** (`SecretScanningScanTrigger`: `manual`, `resources-added`, `push`, `pull-request`), separate from `type`, which says how much was scanned (`historical` / `realtime`). Rows from before the column are null. `metadata` (jsonb) holds trigger-specific data and is parsed by trigger; it is omitted from API responses. **GitHub pull request checks** are realtime scans with `trigger: pull-request`, gated on the data source's `isScanNewCommitsEnabled`. A PR on a repository that isn't a resource yet goes through `discoverResource`, the same discovery a push gets (skipped when discovery is off, history scanned when historical scan is on), so both webhooks add repositories the same way. `secret-scanning-v2-queue.ts` stays provider-agnostic: provider behavior goes behind hooks on the data source factory, never behind a provider check in the queue. A scan reported back to where it was requested implements `TSecretScanningScanReport` (`start`, `getCompletedScanMetadata`, `complete`, `fail`, `cancel`), which the factory builds from the diff job payload (`getDiffScanReport`, so a scan whose data source was deleted can still close it) or from the saved scan (`getScanReport`, for the stuck-scan reaper). `getDiffScanFindingsPayload` returns `{ findings, details? }`, where `details` is what the report needs beyond the findings (GitHub: commit counts). Webhook events other than pushes go through `queueDataSourceEvent` as a `TQueueSecretScanningDataSourceEvent` and are handled by the provider factory's optional `processEvent`, which gets `discoverResource` and `queueReportedDiffScan` per call (as `initialize` gets the DAL) (inserts the scan under the ID its report already carries, and closes the report if queueing fails). The `pull_request`, `check_run.rerequested`, `check_suite.rerequested` and `check_run.requested_action` webhook handlers in `github-secret-scanning-service.ts` only enqueue a reduced `TQueueGitHubPullRequestEvent` that way (job ID from the GitHub delivery ID, 3 attempts); `processGitHubPullRequestEvent` in `github-secret-scanning-fns.ts` processes it in the worker. Everything before the check run is created is safe to repeat and nothing after it throws, which is what makes the retries safe. The processor creates the check run *before* the scan row: the scan's uuid is generated in the app and sent as the check run's `external_id`, so a `check_run.rerequested` event (whose `pull_requests` is empty for forks) loads the scan by primary key and reads the PR from `metadata` (`GitHubPullRequestScanMetadataSchema`). `check_suite.rerequested` ("Re-run all checks") names only the suite, so it lists the suite's latest check run with our name and takes the same path from its `external_id`. Pull requests from forks (`head.repo` differs from the base repository, or was deleted) aren't scanned and don't discover the repository: anyone can open one on a public repository, so scanning them would let any GitHub account spend the shared scan workers and the installation's API quota and plant findings. They get a check run created already completed with conclusion `skipped`, which passes branch protection, and their commits are scanned by the push scan once merged. If the check run can't be created (typically an installation that hasn't accepted the Checks permission), nothing is scanned. The scan lists commits with the compare API pinned to the event's base and head SHAs (not `pulls.listCommits`, which caps at 250 and drifts as commits land) and reuses the push path's per-commit scan, so fingerprints match and findings dedupe with push scans. The check fails on every finding in the PR's commits, not only the rows its own scan inserted: a finding a push scan saved first keeps that scan's `scanId`. Findings triaged `false-positive` or `ignore` don't fail the check: the result is judged on the rows the upsert returns, which carry their stored status, and the scan stores every finding ID in `metadata.findingIds` when it completes. A failing check offers **Skip: False positive** and **Skip: Ignore** (`PULL_REQUEST_CHECK_SKIP_ACTIONS`); the `check_run.requested_action` event verifies the scan belongs to the event's installation and repository, sets that status on the PR's findings like Infisical's own triage (audited per finding, GitHub login in `triageComment`), and starts a new check run. GitHub shows those buttons to anyone with write access to the repository. Every exit of `handleDiffScan` (including a failure before the scan starts) and the stuck-scan reaper closes the check run, since a check left `queued` blocks merging when it is required. The reaper fails realtime scans left `queued` past the stuck-scan timeout as well as stuck `scanning` ones, because a realtime job's payload isn't stored and can't be redelivered; check reporting is best effort after the scan's outcome is committed (diff scans run with one attempt).
**Dynamic secret lease secrets needed at revoke time go in `dynamic_secret_leases.encryptedLeaseData`**, never in `externalEntityId` or `config` (both plaintext, and `externalEntityId` is returned by every lease route and logged in audit events). A provider opts in by listing the `create()` `data` keys in `persistedLeaseFields`; the lease service encrypts them with the project's SecretManager key and every revoke path passes them back as `metadata.leaseData`. Lease routes return `SanitizedDynamicSecretLeaseSchema` so the column never reaches a response. Secret *config* fields are listed separately in `DYNAMIC_SECRET_SECRET_FIELDS` (`providers/redact.ts`), as dotted paths so nested secrets work (`clientAuth.clientSecret`): reads strip them via `redactStoredInputs`, and an update that omits one keeps the stored value via `restoreOmittedSecretFields`, because the update merge is shallow.
diff --git a/backend/src/ee/services/secret-scanning-v2/github/github-secret-scanning-fns.test.ts b/backend/src/ee/services/secret-scanning-v2/github/github-secret-scanning-fns.test.ts
index 429f00959e..35ede0a4f7 100644
--- a/backend/src/ee/services/secret-scanning-v2/github/github-secret-scanning-fns.test.ts
+++ b/backend/src/ee/services/secret-scanning-v2/github/github-secret-scanning-fns.test.ts
@@ -8,15 +8,17 @@ import { TFindingsPayload } from "@app/ee/services/secret-scanning-v2/secret-sca
import {
completePullRequestCheckRun,
+ createSkippedPullRequestCheckRun,
getPullRequestScanCheckRunResult,
isGitHubPullRequestScanPayload,
scanGitHubCommitsAndGetFindings
} from "./github-secret-scanning-fns";
const checksUpdate = vi.fn();
+const checksCreate = vi.fn();
vi.mock("probot", () => ({
- ProbotOctokit: vi.fn(() => ({ checks: { update: checksUpdate } }))
+ ProbotOctokit: vi.fn(() => ({ checks: { update: checksUpdate, create: checksCreate } }))
}));
vi.mock("@app/lib/config/env", async (importOriginal) => ({
@@ -235,3 +237,28 @@ describe("scanGitHubCommitsAndGetFindings", () => {
expect(scanned).toEqual(["added", "modified", "renamed", "copied", "changed"]);
});
});
+
+describe("createSkippedPullRequestCheckRun", () => {
+ test("creates a check that is already completed as skipped, with no scan behind it", async () => {
+ checksCreate.mockReset();
+
+ await createSkippedPullRequestCheckRun({
+ installationId: "1",
+ repositoryFullName: "acme/api",
+ headSha: "b".repeat(40),
+ title: "Fork not scanned",
+ summary: "summary"
+ });
+
+ expect(checksCreate).toHaveBeenCalledWith(
+ expect.objectContaining({
+ owner: "acme",
+ repo: "api",
+ head_sha: "b".repeat(40),
+ status: "completed",
+ conclusion: "skipped"
+ })
+ );
+ expect(checksCreate.mock.calls[0][0]).not.toHaveProperty("external_id");
+ });
+});
diff --git a/backend/src/ee/services/secret-scanning-v2/github/github-secret-scanning-fns.ts b/backend/src/ee/services/secret-scanning-v2/github/github-secret-scanning-fns.ts
index f96ba6c0d5..9942aa33d5 100644
--- a/backend/src/ee/services/secret-scanning-v2/github/github-secret-scanning-fns.ts
+++ b/backend/src/ee/services/secret-scanning-v2/github/github-secret-scanning-fns.ts
@@ -290,6 +290,35 @@ export const createPullRequestCheckRun = async ({
return data.id;
};
+// Completed on creation, so a required check doesn't block the pull request. `skipped` passes branch protection.
+export const createSkippedPullRequestCheckRun = async ({
+ installationId,
+ repositoryFullName,
+ headSha,
+ title,
+ summary
+}: {
+ installationId: string;
+ repositoryFullName: string;
+ headSha: string;
+ title: string;
+ summary: string;
+}) => {
+ const octokit = getGitHubRadarInstallationOctokit(installationId);
+ const { owner, repo } = splitRepositoryFullName(repositoryFullName);
+
+ await octokit.checks.create({
+ owner,
+ repo,
+ name: GITHUB_PULL_REQUEST_CHECK_NAME,
+ head_sha: headSha,
+ status: "completed",
+ conclusion: "skipped",
+ completed_at: new Date().toISOString(),
+ output: { title, summary }
+ });
+};
+
// A suite holds one App's check runs for one commit; `latest` returns only the newest run with our check's name.
export const getLatestPullRequestCheckRunExternalId = async ({
installationId,
@@ -575,11 +604,13 @@ export const processGitHubPullRequestEvent: TSecretScanningFactoryProcessEvent<T
installationId,
repository,
pullRequest,
+ isFromFork,
expectedResourceId
}: {
installationId: number;
repository: Pick<Repository, "id" | "full_name">;
pullRequest: TGitHubPullRequestScanPayload["pullRequest"];
+ isFromFork?: boolean;
expectedResourceId?: string;
}) => {
const logDetails = `[installationId=${installationId}] [repository=${repository.full_name}] [pullRequest=${pullRequest.number}] [headSha=${pullRequest.headSha}]`;
@@ -613,6 +644,28 @@ export const processGitHubPullRequestEvent: TSecretScanningFactoryProcessEvent<T
return;
}
+ // Anyone can open a pull request from a fork of a public repository, so scanning one would let any GitHub account
+ // spend the instance's scan workers and the installation's API quota, and plant findings in the org. The commits are
+ // scanned once merged, by the push scan. Nothing is discovered either.
+ if (isFromFork) {
+ try {
+ await createSkippedPullRequestCheckRun({
+ installationId: String(installationId),
+ repositoryFullName: repository.full_name,
+ headSha: pullRequest.headSha,
+ title: "Fork not scanned",
+ summary:
+ "Infisical doesn't scan pull requests from forks. Their commits are scanned after they are merged into this repository."
+ });
+ } catch (error) {
+ logger.warn(
+ error,
+ `secretScanningV2PullRequestEvent: GitHub - could not create skipped check run for fork ${logDetails}`
+ );
+ }
+ return;
+ }
+
const resource =
existingResource ??
(await discoverResource({
@@ -864,7 +917,12 @@ export const processGitHubPullRequestEvent: TSecretScanningFactoryProcessEvent<T
switch (event.event) {
case GitHubPullRequestEvent.PullRequest:
- return startPullRequestScan({ installationId, repository, pullRequest: event.pullRequest });
+ return startPullRequestScan({
+ installationId,
+ repository,
+ pullRequest: event.pullRequest,
+ isFromFork: event.isFromFork
+ });
case GitHubPullRequestEvent.CheckRunRerequested:
return rerunPullRequestScan({
installationId,
diff --git a/backend/src/ee/services/secret-scanning-v2/github/github-secret-scanning-service.ts b/backend/src/ee/services/secret-scanning-v2/github/github-secret-scanning-service.ts
index c77b51cc1b..03f1784473 100644
--- a/backend/src/ee/services/secret-scanning-v2/github/github-secret-scanning-service.ts
+++ b/backend/src/ee/services/secret-scanning-v2/github/github-secret-scanning-service.ts
@@ -99,7 +99,9 @@ export const githubSecretScanningService = (
number: pullRequest.number,
baseSha: pullRequest.base.sha,
headSha: pullRequest.head.sha
- }
+ },
+ // A fork whose repository was deleted has no head repository.
+ isFromFork: pullRequest.head.repo?.id !== repository.id
},
deliveryId
);
diff --git a/backend/src/ee/services/secret-scanning-v2/github/github-secret-scanning-types.ts b/backend/src/ee/services/secret-scanning-v2/github/github-secret-scanning-types.ts
index 2dc905e016..2d85e7a2ed 100644
--- a/backend/src/ee/services/secret-scanning-v2/github/github-secret-scanning-types.ts
+++ b/backend/src/ee/services/secret-scanning-v2/github/github-secret-scanning-types.ts
@@ -57,7 +57,11 @@ export type TQueueGitHubPullRequestEvent = {
installationId: number;
repository: Pick<Repository, "id" | "full_name">;
} & (
- | { event: GitHubPullRequestEvent.PullRequest; pullRequest: TGitHubPullRequestScanPayload["pullRequest"] }
+ | {
+ event: GitHubPullRequestEvent.PullRequest;
+ pullRequest: TGitHubPullRequestScanPayload["pullRequest"];
+ isFromFork: boolean;
+ }
| { event: GitHubPullRequestEvent.CheckRunRerequested; checkRunId: number; externalId: string | null }
| { event: GitHubPullRequestEvent.CheckSuiteRerequested; checkSuiteId: number }
| {
diff --git a/docs/documentation/platform/secret-scanning/github.mdx b/docs/documentation/platform/secret-scanning/github.mdx
index 4c30288204..7813f45ee8 100644
--- a/docs/documentation/platform/secret-scanning/github.mdx
+++ b/docs/documentation/platform/secret-scanning/github.mdx
@@ -64,6 +64,7 @@ If **Scan New Commits** is on for a GitHub data source, Infisical scans the comm
- If Infisical finds a secret in any commit of the pull request, the check fails and marks the file and line of each secret, unless the secret's finding is marked as a false positive or ignored
- If Infisical can't finish the scan, the check fails, and you can re-run the check from the pull request
- If Infisical finds no secrets, the check passes
+- If the pull request comes from a fork, Infisical doesn't scan it and marks the check as skipped, which doesn't block merging. Infisical scans its commits after they're merged into the repository.
To stop a pull request that contains a secret from being merged, [require the check in a branch protection rule](https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-protected-branches/about-protected-branches#require-status-checks-before-merging).