@patchstack/connect 0.5.20 → 0.5.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENT-INSTALL.md +2 -0
- package/README.md +2 -2
- package/dist/cli.js +71 -1
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +7 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/protect.cjs +12 -2
- package/dist/protect.cjs.map +1 -1
- package/dist/protect.js +1 -1
- package/dist/{refresh-manifest-DZQOEO3Q.js → refresh-manifest-OMRDCNFD.js} +4 -1
- package/dist/refresh-manifest-OMRDCNFD.js.map +1 -0
- package/package.json +1 -1
- package/dist/refresh-manifest-DZQOEO3Q.js.map +0 -1
package/AGENT-INSTALL.md
CHANGED
|
@@ -277,6 +277,8 @@ Handle it in this order:
|
|
|
277
277
|
|
|
278
278
|
- `apiKey` (in `.patchstackrc.local.json`, which is git-ignored; also `PATCHSTACK_API_KEY`, WP format `{secret}-{oauth.id}`) — one credential for both paths. It authenticates **Pulse ingest** (manifest, attack-surface map, package removal, rule detections), where it is exchanged for a short-lived token rather than sent directly, and **block-log reporting** through the connector `POST /api/logs/log`, so "Threats blocked" fills in the dashboard.
|
|
279
279
|
|
|
280
|
+
A production build of a registered site that has **no** credential — a hosted builder's publish, which builds from the committed project and so never sees the git-ignored key file — cannot send its manifest. `scan` and `mark-build` then POST `monitor/pulse/build/<your site uuid>` instead, with no credential and exactly three fields: the manifest checksum, `environment: "production"`, and (`mark-build` only) the marker result. **No package names, no address, no name, no environment variable values.** Patchstack accepts it only when the checksum is the build it last scanned for this site, and shows the build as reported rather than deployed until the live page is seen running it. A publish that changed your packages is refused; set `PATCHSTACK_API_KEY` for that build.
|
|
281
|
+
|
|
280
282
|
It is server-only. Never put it in the widget tag, client bundles, or public env vars (`NEXT_PUBLIC_*`, etc.). Prefer `PATCHSTACK_API_KEY` in production; the git-ignored `.patchstackrc.local.json` is fine for local DX. If it is lost, `npx @patchstack/connect login` recovers it via dashboard approval — do not delete the file and re-provision, which would create a second site. Opt out of reporting with `PATCHSTACK_TELEMETRY=off`. If the project must not carry the widget, persist `"widget": false` in `.patchstackrc.json`; otherwise the next scan re-adds it.
|
|
281
283
|
|
|
282
284
|
A `pulseAuth` field is still honoured if a project has one, and `PATCHSTACK_PULSE_AUTH` still overrides it, for deployments that authenticate Pulse ingest with a different credential from block-logs. Do not add either yourself: they are unnecessary when the two share one credential, which is the default.
|
package/README.md
CHANGED
|
@@ -262,7 +262,7 @@ group, and a verification that can leave a server running is worse than an unans
|
|
|
262
262
|
|
|
263
263
|
No other command runs your application. `protect`, `protect --check`, `setup`, `guide`, `scan`,
|
|
264
264
|
`status` and `mark-build` only read and write files, and — for `scan` and `mark-build` — report the
|
|
265
|
-
dependency manifest they read.
|
|
265
|
+
dependency manifest they read, or only its checksum from a production build that has no API key.
|
|
266
266
|
|
|
267
267
|
## Configuration
|
|
268
268
|
|
|
@@ -310,7 +310,7 @@ The site UUID identifies the site and is **not** a secret — the Patchstack Con
|
|
|
310
310
|
|
|
311
311
|
If it is ever lost, `npx @patchstack/connect login` recovers it — approval happens in the dashboard and rotates the credential.
|
|
312
312
|
|
|
313
|
-
The credential's file is never committed, so CI needs `PATCHSTACK_API_KEY` in the environment (and `PATCHSTACK_SITE_UUID` too where `.patchstackrc.json` is also absent). Precedence is CLI flag → env var → `.patchstackrc.local.json` → `.patchstackrc.json`.
|
|
313
|
+
The credential's file is never committed, so CI needs `PATCHSTACK_API_KEY` in the environment (and `PATCHSTACK_SITE_UUID` too where `.patchstackrc.json` is also absent). A production build that has the site UUID but no key — a hosted builder's publish, typically — reports only that the build ran: it POSTs the manifest checksum to `monitor/pulse/build/<uuid>` without a credential and without the package list, and Patchstack accepts it only for the build it last scanned. Set the key there if the publish can change your packages. Precedence is CLI flag → env var → `.patchstackrc.local.json` → `.patchstackrc.json`.
|
|
314
314
|
|
|
315
315
|
A `pulseAuth` field is still read if present, and `PATCHSTACK_PULSE_AUTH` still overrides, for deployments that authenticate Pulse ingest with a different credential from block-logs. Neither is written by default, and neither is needed when the two share one.
|
|
316
316
|
|
package/dist/cli.js
CHANGED
|
@@ -1876,11 +1876,79 @@ async function postManifestWithEnvironmentFallback(config, payload, marker = nul
|
|
|
1876
1876
|
environmentUsed: config.environment
|
|
1877
1877
|
};
|
|
1878
1878
|
} catch (err) {
|
|
1879
|
+
if (err instanceof PatchstackError && err.code === "UNAUTHORIZED" && reportsBuildWithoutCredential(config)) {
|
|
1880
|
+
return {
|
|
1881
|
+
response: await postBuildReport(config, computeManifestChecksum(payload.packages), marker),
|
|
1882
|
+
environmentUsed: "production"
|
|
1883
|
+
};
|
|
1884
|
+
}
|
|
1879
1885
|
if (config.environment !== "local" || !environmentRejected(err)) throw err;
|
|
1880
1886
|
const fallback = { ...config, environment: "sandbox" };
|
|
1881
1887
|
return { response: await postManifest(fallback, payload, marker), environmentUsed: "sandbox" };
|
|
1882
1888
|
}
|
|
1883
1889
|
}
|
|
1890
|
+
function reportsBuildWithoutCredential(config) {
|
|
1891
|
+
const hasCredential = typeof config.pulseAuth === "string" && config.pulseAuth.length > 0;
|
|
1892
|
+
return !hasCredential && config.environment === "production" && config.siteUuid !== null && config.siteUuid !== "";
|
|
1893
|
+
}
|
|
1894
|
+
function buildReportUrl(manifestEndpoint, siteUuid) {
|
|
1895
|
+
const url = new URL(manifestEndpoint);
|
|
1896
|
+
const path17 = url.pathname.replace(/\/$/, "");
|
|
1897
|
+
const id = encodeURIComponent(siteUuid);
|
|
1898
|
+
url.pathname = path17.endsWith("/manifest") ? `${path17.slice(0, -"/manifest".length)}/build/${id}` : `/monitor/pulse/build/${id}`;
|
|
1899
|
+
url.search = "";
|
|
1900
|
+
url.hash = "";
|
|
1901
|
+
return url.toString();
|
|
1902
|
+
}
|
|
1903
|
+
async function postBuildReport(config, checksum, marker = null) {
|
|
1904
|
+
const siteUuid = config.siteUuid ?? "";
|
|
1905
|
+
const url = buildReportUrl(config.endpoint, siteUuid);
|
|
1906
|
+
assertConnectableEndpoint(config, url);
|
|
1907
|
+
const needsKey = authFailureMessage(401, config) ?? "Set PATCHSTACK_API_KEY where this build runs.";
|
|
1908
|
+
let response;
|
|
1909
|
+
try {
|
|
1910
|
+
response = await fetch(url, {
|
|
1911
|
+
method: "POST",
|
|
1912
|
+
headers: {
|
|
1913
|
+
"Content-Type": "application/json",
|
|
1914
|
+
Accept: "application/json",
|
|
1915
|
+
"User-Agent": "@patchstack/connect"
|
|
1916
|
+
},
|
|
1917
|
+
body: JSON.stringify({ checksum, environment: "production", ...marker !== null ? { marker } : {} }),
|
|
1918
|
+
signal: AbortSignal.timeout(config.timeoutMs)
|
|
1919
|
+
});
|
|
1920
|
+
} catch (cause) {
|
|
1921
|
+
throw new PatchstackError(
|
|
1922
|
+
isTimeoutError(cause) ? `Patchstack request to ${url} timed out after ${config.timeoutMs}ms. Override with PATCHSTACK_TIMEOUT_MS.` : `Could not reach Patchstack at ${url}. Check your network connection.`,
|
|
1923
|
+
isTimeoutError(cause) ? "NETWORK_TIMEOUT" : "NETWORK_ERROR",
|
|
1924
|
+
cause
|
|
1925
|
+
);
|
|
1926
|
+
}
|
|
1927
|
+
let parsed = null;
|
|
1928
|
+
try {
|
|
1929
|
+
const text = await readBoundedText(response);
|
|
1930
|
+
parsed = text.length > 0 ? JSON.parse(text) : null;
|
|
1931
|
+
} catch {
|
|
1932
|
+
parsed = null;
|
|
1933
|
+
}
|
|
1934
|
+
if (response.status === 422) {
|
|
1935
|
+
throw new PatchstackError(
|
|
1936
|
+
safeDisplayString(parsed?.error) ?? `This build is not the one Patchstack last scanned. ${needsKey}`,
|
|
1937
|
+
"UNAUTHORIZED"
|
|
1938
|
+
);
|
|
1939
|
+
}
|
|
1940
|
+
if (response.status < 200 || response.status >= 300) {
|
|
1941
|
+
throw new PatchstackError(needsKey, "UNAUTHORIZED");
|
|
1942
|
+
}
|
|
1943
|
+
const result = parsed?.result;
|
|
1944
|
+
return {
|
|
1945
|
+
uuid: siteUuid,
|
|
1946
|
+
stored: false,
|
|
1947
|
+
checksum,
|
|
1948
|
+
reason: "build-reported",
|
|
1949
|
+
message: result === "already-reported" ? "Patchstack already knew this build was published" : "Told Patchstack this build was published. There is no API key here, so the package list was not sent again"
|
|
1950
|
+
};
|
|
1951
|
+
}
|
|
1884
1952
|
async function postManifest(config, payload, marker = null) {
|
|
1885
1953
|
const url = buildEndpointUrl(config.endpoint, config.siteUuid);
|
|
1886
1954
|
const timeoutMs = config.timeoutMs;
|
|
@@ -10463,6 +10531,8 @@ async function runScan(args, options = {}) {
|
|
|
10463
10531
|
say(`Stored manifest #${response.manifest_id} (checksum ${response.checksum}).`);
|
|
10464
10532
|
} else if (response.reason === "duplicate") {
|
|
10465
10533
|
report.done.unshift(checked, "No changes since the last check");
|
|
10534
|
+
} else if (response.reason === "build-reported") {
|
|
10535
|
+
report.done.unshift(checked, response.message ?? "Reported this production build");
|
|
10466
10536
|
} else {
|
|
10467
10537
|
report.missing.push({
|
|
10468
10538
|
text: "Patchstack did not save this check",
|
|
@@ -10508,7 +10578,7 @@ async function runScan(args, options = {}) {
|
|
|
10508
10578
|
if (config.widget && effectiveUuid !== null && effectiveUuid.length > 0) {
|
|
10509
10579
|
reportSourceWidget(effectiveUuid, shellFramework, report);
|
|
10510
10580
|
}
|
|
10511
|
-
const synced = effectiveUuid !== null && effectiveUuid.length > 0 && (response.stored || response.reason === "duplicate");
|
|
10581
|
+
const synced = effectiveUuid !== null && effectiveUuid.length > 0 && (response.stored || response.reason === "duplicate" || response.reason === "build-reported");
|
|
10512
10582
|
const outcome = {
|
|
10513
10583
|
connected,
|
|
10514
10584
|
synced,
|