@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.
@@ -811,6 +811,26 @@ function warnUnsupportedMatchType(type) {
811
811
  `[patchstack] Unsupported rule_v2 match type "${type}" \u2014 condition treated as no-match. Rules relying on it are not enforced by this engine.`
812
812
  );
813
813
  }
814
+ function hostFromValue(value) {
815
+ const raw = String(value ?? "").trim();
816
+ if (raw === "") return "";
817
+ if (/^[a-z][a-z0-9+.-]*:\/\//i.test(raw) || raw.startsWith("//")) {
818
+ try {
819
+ return new URL(raw.startsWith("//") ? `http:${raw}` : raw).hostname;
820
+ } catch {
821
+ return raw;
822
+ }
823
+ }
824
+ if (raw.startsWith("[")) {
825
+ const end = raw.indexOf("]");
826
+ if (end > 0) return raw.slice(1, end);
827
+ }
828
+ const colon = raw.indexOf(":");
829
+ if (colon > 0 && raw.indexOf(":", colon + 1) === -1 && /^\d+$/.test(raw.slice(colon + 1))) {
830
+ return raw.slice(0, colon);
831
+ }
832
+ return raw;
833
+ }
814
834
  function isInternalHost(hostname) {
815
835
  if (!hostname) return false;
816
836
  let host = String(hostname).toLowerCase().replace(/^\[|\]$/g, "");
@@ -900,8 +920,20 @@ function expandIPv6(host) {
900
920
  }
901
921
  return out;
902
922
  }
923
+ var warnedScopes = /* @__PURE__ */ new Set();
924
+ function warnUnrecognisedScope(when) {
925
+ const key = Object.keys(when).sort().join(",");
926
+ if (warnedScopes.has(key)) return;
927
+ warnedScopes.add(key);
928
+ console.warn(
929
+ `[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.`
930
+ );
931
+ }
903
932
  function ruleAppliesTo(when, resolver) {
904
933
  try {
934
+ if (when.method === void 0 && when.path === void 0 && Object.keys(when).length > 0) {
935
+ warnUnrecognisedScope(when);
936
+ }
905
937
  if (when.method) {
906
938
  const methods = (Array.isArray(when.method) ? when.method : [when.method]).map((m) => String(m).toUpperCase());
907
939
  const actual = String(resolver.resolve("server.REQUEST_METHOD")[0] ?? "GET").toUpperCase();
@@ -1067,7 +1099,7 @@ function matchValue(type, value, matchVal, matchObj) {
1067
1099
  }
1068
1100
  }
1069
1101
  case "internal_host":
1070
- return isInternalHost(strValue);
1102
+ return isInternalHost(hostFromValue(strValue));
1071
1103
  case "quotes":
1072
1104
  // engine-php exposes `inline_js_xss` as an alias of `quotes`.
1073
1105
  case "inline_js_xss":