@patchstack/connect 0.3.25 → 0.3.27
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 +62 -5
- package/README.md +6 -5
- package/dist/cli.js +203 -83
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +1 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -4
- package/dist/index.d.ts +12 -4
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/dist/protect.cjs +33 -1
- package/dist/protect.cjs.map +1 -1
- package/dist/protect.edge.js +33 -1
- package/dist/protect.edge.js.map +2 -2
- package/dist/protect.js +34 -2
- package/dist/protect.js.map +1 -1
- package/dist/{refresh-manifest-MUWVIPFR.js → refresh-manifest-KZSQD2X3.js} +1 -1
- package/dist/refresh-manifest-KZSQD2X3.js.map +1 -0
- package/package.json +1 -1
- package/dist/refresh-manifest-MUWVIPFR.js.map +0 -1
package/dist/protect.js
CHANGED
|
@@ -782,6 +782,26 @@ function warnUnsupportedMatchType(type) {
|
|
|
782
782
|
`[patchstack] Unsupported rule_v2 match type "${type}" \u2014 condition treated as no-match. Rules relying on it are not enforced by this engine.`
|
|
783
783
|
);
|
|
784
784
|
}
|
|
785
|
+
function hostFromValue(value) {
|
|
786
|
+
const raw = String(value ?? "").trim();
|
|
787
|
+
if (raw === "") return "";
|
|
788
|
+
if (/^[a-z][a-z0-9+.-]*:\/\//i.test(raw) || raw.startsWith("//")) {
|
|
789
|
+
try {
|
|
790
|
+
return new URL(raw.startsWith("//") ? `http:${raw}` : raw).hostname;
|
|
791
|
+
} catch {
|
|
792
|
+
return raw;
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
if (raw.startsWith("[")) {
|
|
796
|
+
const end = raw.indexOf("]");
|
|
797
|
+
if (end > 0) return raw.slice(1, end);
|
|
798
|
+
}
|
|
799
|
+
const colon = raw.indexOf(":");
|
|
800
|
+
if (colon > 0 && raw.indexOf(":", colon + 1) === -1 && /^\d+$/.test(raw.slice(colon + 1))) {
|
|
801
|
+
return raw.slice(0, colon);
|
|
802
|
+
}
|
|
803
|
+
return raw;
|
|
804
|
+
}
|
|
785
805
|
function isInternalHost(hostname) {
|
|
786
806
|
if (!hostname) return false;
|
|
787
807
|
let host = String(hostname).toLowerCase().replace(/^\[|\]$/g, "");
|
|
@@ -871,8 +891,20 @@ function expandIPv6(host) {
|
|
|
871
891
|
}
|
|
872
892
|
return out;
|
|
873
893
|
}
|
|
894
|
+
var warnedScopes = /* @__PURE__ */ new Set();
|
|
895
|
+
function warnUnrecognisedScope(when) {
|
|
896
|
+
const key = Object.keys(when).sort().join(",");
|
|
897
|
+
if (warnedScopes.has(key)) return;
|
|
898
|
+
warnedScopes.add(key);
|
|
899
|
+
console.warn(
|
|
900
|
+
`[patchstack] Rule scope \`when: { ${key} }\` names no supported key \u2014 the engine understands \`method\` and \`path\`. The scope is IGNORED and the rule applies to every request.`
|
|
901
|
+
);
|
|
902
|
+
}
|
|
874
903
|
function ruleAppliesTo(when, resolver) {
|
|
875
904
|
try {
|
|
905
|
+
if (when.method === void 0 && when.path === void 0 && Object.keys(when).length > 0) {
|
|
906
|
+
warnUnrecognisedScope(when);
|
|
907
|
+
}
|
|
876
908
|
if (when.method) {
|
|
877
909
|
const methods = (Array.isArray(when.method) ? when.method : [when.method]).map((m) => String(m).toUpperCase());
|
|
878
910
|
const actual = String(resolver.resolve("server.REQUEST_METHOD")[0] ?? "GET").toUpperCase();
|
|
@@ -1038,7 +1070,7 @@ function matchValue(type, value, matchVal, matchObj) {
|
|
|
1038
1070
|
}
|
|
1039
1071
|
}
|
|
1040
1072
|
case "internal_host":
|
|
1041
|
-
return isInternalHost(strValue);
|
|
1073
|
+
return isInternalHost(hostFromValue(strValue));
|
|
1042
1074
|
case "quotes":
|
|
1043
1075
|
// engine-php exposes `inline_js_xss` as an alias of `quotes`.
|
|
1044
1076
|
case "inline_js_xss":
|
|
@@ -2978,7 +3010,7 @@ async function createProtection(options = {}) {
|
|
|
2978
3010
|
let reporter = null;
|
|
2979
3011
|
if (refreshable && options.siteUuid && options.reportManifest !== false && cwd) {
|
|
2980
3012
|
try {
|
|
2981
|
-
({ reportManifest: reporter } = await import("./refresh-manifest-
|
|
3013
|
+
({ reportManifest: reporter } = await import("./refresh-manifest-KZSQD2X3.js"));
|
|
2982
3014
|
} catch (err) {
|
|
2983
3015
|
onError?.(err);
|
|
2984
3016
|
}
|