v0.39.2
This commit is contained in:
1 parent
d455028de3
commit
5b2eaaff61
36 files changed
+2544
-102
No files matched your search
@@ -18,11 +18,11 @@ window.rustProxyCacheRules = (() => {
|
||||
response_header: { ops: ["exists", "equals", "contains", "regex"], name: true, stages: ["response", "deliver"] },
|
||||
};
|
||||
const ACTIONS = {
|
||||
request: ["pass", "lookup", "strip_cookies", "remove_named_cookies", "strip_query", "hash_header", "hash_cookie", "set_request_header", "remove_request_header"],
|
||||
request: ["pass", "cookie_pass", "lookup", "strip_cookies", "remove_named_cookies", "strip_query", "hash_header", "hash_cookie", "set_request_header", "remove_request_header"],
|
||||
response: ["ttl", "grace", "no_store", "allow_store", "ignore_cache_control", "strip_set_cookie", "set_backend_header", "remove_backend_header"],
|
||||
deliver: ["set_header", "default_header", "remove_header"],
|
||||
};
|
||||
const ASPECTS = { pass: "request_routing", lookup: "request_routing", strip_cookies: "request_cookies", remove_named_cookies: "request_cookies", strip_query: "request_query", ttl: "ttl", grace: "grace", no_store: "store", allow_store: "store" };
|
||||
const ASPECTS = { pass: "request_routing", cookie_pass: "request_routing", lookup: "request_routing", strip_cookies: "request_cookies", remove_named_cookies: "request_cookies", strip_query: "request_query", ttl: "ttl", grace: "grace", no_store: "store", allow_store: "store" };
|
||||
const tk = (prefix, value) => t(`${prefix}${String(value).split("_").map(part => part[0].toUpperCase() + part.slice(1)).join("")}`);
|
||||
const fieldLabel = field => tk("cacheRuleField", field);
|
||||
const opLabel = op => tk("cacheRuleOp", op);
|
||||
@@ -82,6 +82,7 @@ window.rustProxyCacheRules = (() => {
|
||||
return rule.actions.map(a => {
|
||||
switch (a.type) {
|
||||
case "pass": return "return (pass);";
|
||||
case "cookie_pass": return "return (cookie_pass);";
|
||||
case "lookup": return rule.hash_stage ? "return (lookup);" : "return (hash);";
|
||||
case "strip_cookies": return a.keep?.length ? `# keep only cookies: ${a.keep.join(", ")}\nset req.http.Cookie = regsuball(req.http.Cookie, "(^|;\\s*)(?!(${a.keep.map(reEsc).join("|")})=)[^;=]+=[^;]*", "");` : "unset req.http.Cookie;";
|
||||
case "remove_named_cookies": return `remove_req_cookies(${(a.names || []).map(name => `"${esc(name)}"`).join(", ")});`;
|
||||
@@ -124,6 +125,8 @@ window.rustProxyCacheRules = (() => {
|
||||
limits.push("One or more graphical actions are only approximated in this VCL display.");
|
||||
if (rule.actions.some(a => a.type === "remove_named_cookies"))
|
||||
limits.push("remove_req_cookies() is a RustProxy extension, not standard Varnish VCL.");
|
||||
if (rule.actions.some(a => a.type === "cookie_pass"))
|
||||
limits.push("return(cookie_pass) is a RustProxy extension (Cookie guard); stock Varnish only knows return(pass).");
|
||||
const notes = limits.map(limit => `# PREVIEW LIMITATION: ${limit}`).join("\n");
|
||||
const description = notes ? `${head}\n${notes}` : head;
|
||||
return conditions.length ? `${description}\nif (${joined}) {\n${body}\n}` : `${description}\n${body.replace(/^ {4}/gm, "")}`;
|
||||
@@ -170,6 +173,12 @@ window.rustProxyCacheRules = (() => {
|
||||
name: t(label), stage: "request", match, conditions,
|
||||
actions: [{ type: "pass" }], stop: true,
|
||||
});
|
||||
// Cookie/session guards use cookie_pass: the same BYPASS for pages, but
|
||||
// RustProxy may still cache a *public static asset* when the global static
|
||||
// cookie policy is on and no explicit pass rule matches the request.
|
||||
const templateCookieGuard = (label, conditions, match = "all") => ({
|
||||
...templatePass(label, conditions, match), actions: [{ type: "cookie_pass" }],
|
||||
});
|
||||
const templatePath = (value) => ({ field: "path", operator: "regex", values: [value] });
|
||||
const templateResponse = (label, conditions, actions, enabled = false) => ({
|
||||
name: t(label), stage: "response", match: "all", conditions, actions, enabled,
|
||||
@@ -179,7 +188,12 @@ window.rustProxyCacheRules = (() => {
|
||||
});
|
||||
const protectedPaths = "^/(?:admin|auth|login|logout|user|users|account|profile|settings|dashboard|cart|checkout|orders|billing|payment)(?:/|[?]|$)";
|
||||
const TEMPLATES = {
|
||||
wordpress: () => [{ name: t("cacheRuleTplWordpress"), stage: "request", match: "any", conditions: [{ field: "path", operator: "regex", values: ["^/(wp-admin|wp-login\\.php|xmlrpc\\.php|wp-json)"] }, { field: "header", name: "cookie", operator: "regex", values: ["wordpress_logged_in_|comment_author_|woocommerce_items_in_cart|wp-postpass_"] }], actions: [{ type: "pass" }] }],
|
||||
// Path guard and Cookie guard are separate rules: the explicit path pass
|
||||
// is never relaxed, the Cookie guard may yield to the static policy.
|
||||
wordpress: () => [
|
||||
{ name: t("cacheRuleTplWordpress"), stage: "request", match: "all", conditions: [{ field: "path", operator: "regex", values: ["^/(wp-admin|wp-login\\.php|xmlrpc\\.php|wp-json)"] }], actions: [{ type: "pass" }] },
|
||||
{ name: t("cacheRuleTplWordpressCookies"), stage: "request", match: "all", conditions: [{ field: "header", name: "cookie", operator: "regex", values: ["wordpress_logged_in_|comment_author_|woocommerce_items_in_cart|wp-postpass_"] }], actions: [{ type: "cookie_pass" }] },
|
||||
],
|
||||
static: () => [
|
||||
{ name: t("cacheRuleTplStaticCookies"), stage: "request", match: "all", conditions: [{ field: "extension", operator: "equals", values: ["css", "js", "mjs", "png", "jpg", "jpeg", "gif", "webp", "avif", "svg", "ico", "woff", "woff2"] }], actions: [{ type: "strip_cookies", keep: [] }] },
|
||||
{ name: t("cacheRuleTplStaticTtl"), stage: "response", match: "all", conditions: [{ field: "extension", operator: "equals", values: ["css", "js", "mjs", "png", "jpg", "jpeg", "gif", "webp", "avif", "svg", "ico", "woff", "woff2"] }, { field: "status", operator: "equals", values: ["200"] }], actions: [{ type: "ttl", seconds: 2592000 }, { type: "strip_set_cookie" }] },
|
||||
@@ -193,7 +207,7 @@ window.rustProxyCacheRules = (() => {
|
||||
{ name: t("cacheRuleTplCdnPrivate"), stage: "request", match: "all", conditions: [{ field: "path", operator: "regex", values: ["^/(admin|api|auth|login|logout|panel|konto|dashboard)(/|$)"] }], actions: [{ type: "pass" }], stop: true },
|
||||
{ name: t("cacheRuleTplCdnAuth"), stage: "request", match: "all", conditions: [{ field: "header", name: "Authorization", operator: "exists" }], actions: [{ type: "pass" }], stop: true },
|
||||
{ name: t("cacheRuleTplCdnStrip"), stage: "request", match: "all", conditions: [{ field: "header", name: "Cookie", operator: "regex", values: [`^${technical}=[^;]*(?:;[ \\t]*${technical}=[^;]*)*$`] }], actions: [{ type: "strip_cookies", keep: [] }] },
|
||||
{ name: t("cacheRuleTplCdnRemaining"), stage: "request", match: "all", conditions: [{ field: "header", name: "Cookie", operator: "exists" }], actions: [{ type: "pass" }], stop: true },
|
||||
{ name: t("cacheRuleTplCdnRemaining"), stage: "request", match: "all", conditions: [{ field: "header", name: "Cookie", operator: "exists" }], actions: [{ type: "cookie_pass" }], stop: true },
|
||||
];
|
||||
},
|
||||
// Separate from the CDN template: remove only explicitly named cookies
|
||||
@@ -221,8 +235,8 @@ window.rustProxyCacheRules = (() => {
|
||||
// Safety and authenticated traffic. No rule below removes unknown cookies.
|
||||
safemethods: () => [templatePass("cacheRuleTplSafemethods", [{ field: "method", operator: "equals", values: ["GET", "HEAD"], negate: true }])],
|
||||
authbypass: () => [templatePass("cacheRuleTplAuthbypass", [{ field: "header", name: "Authorization", operator: "exists" }])],
|
||||
cookiepass: () => [templatePass("cacheRuleTplCookiepass", [{ field: "header", name: "Cookie", operator: "exists" }])],
|
||||
sessioncookies: () => [templatePass("cacheRuleTplSessioncookies", [{ field: "header", name: "Cookie", operator: "regex", values: ["(?:^|;[ \\t]*)(?:session|sessionid|PHPSESSID|laravel_session|connect[.]sid|sid)="] }])],
|
||||
cookiepass: () => [templateCookieGuard("cacheRuleTplCookiepass", [{ field: "header", name: "Cookie", operator: "exists" }])],
|
||||
sessioncookies: () => [templateCookieGuard("cacheRuleTplSessioncookies", [{ field: "header", name: "Cookie", operator: "regex", values: ["(?:^|;[ \\t]*)(?:session|sessionid|PHPSESSID|laravel_session|connect[.]sid|sid)="] }])],
|
||||
privateroutes: () => [
|
||||
templatePass("cacheRuleTplPrivateroutesPass", [templatePath(protectedPaths)]),
|
||||
templateResponse("cacheRuleTplPrivateroutesStore", [templatePath(protectedPaths)], [{ type: "no_store" }], true),
|
||||
@@ -245,15 +259,17 @@ window.rustProxyCacheRules = (() => {
|
||||
...["token", "access_token", "signature", "sig", "auth_token"].map(name => ({ field: "query", name, operator: "exists" })),
|
||||
], "any")],
|
||||
// Framework-specific guards are independent from the CDN allowlist.
|
||||
woocommerce: () => [templatePass("cacheRuleTplWoocommerce", [
|
||||
templatePath("^/(?:cart|checkout|my-account)(?:/|[?]|$)"),
|
||||
{ field: "header", name: "Cookie", operator: "regex", values: ["(?:^|;[ \\t]*)(?:wordpress_logged_in_[^=;]*|woocommerce_items_in_cart|wp_woocommerce_session_[^=;]*|woocommerce_cart_hash)="] },
|
||||
], "any")],
|
||||
django: () => [templatePass("cacheRuleTplDjango", [{ field: "cookie", name: "sessionid", operator: "exists" }])],
|
||||
laravel: () => [templatePass("cacheRuleTplLaravel", [{ field: "header", name: "Cookie", operator: "regex", values: ["(?:^|;[ \\t]*)(?:laravel_session|PHPSESSID)="] }])],
|
||||
authjs: () => [templatePass("cacheRuleTplAuthjs", [{ field: "header", name: "Cookie", operator: "regex", values: ["(?:^|;[ \\t]*)(?:__Secure-)?(?:next-auth[.]session-token|authjs[.]session-token)="] }])],
|
||||
aspnet: () => [templatePass("cacheRuleTplAspnet", [{ field: "header", name: "Cookie", operator: "regex", values: ["(?:^|;[ \\t]*)(?:[.]AspNetCore[.]Cookies|ASP[.]NET_SessionId)="] }])],
|
||||
drupal: () => [templatePass("cacheRuleTplDrupal", [{ field: "header", name: "Cookie", operator: "regex", values: ["(?:^|;[ \\t]*)(?:S?SESS[a-fA-F0-9]+)="] }])],
|
||||
woocommerce: () => [
|
||||
templatePass("cacheRuleTplWoocommerce", [templatePath("^/(?:cart|checkout|my-account)(?:/|[?]|$)")]),
|
||||
templateCookieGuard("cacheRuleTplWoocommerceCookies", [
|
||||
{ field: "header", name: "Cookie", operator: "regex", values: ["(?:^|;[ \\t]*)(?:wordpress_logged_in_[^=;]*|woocommerce_items_in_cart|wp_woocommerce_session_[^=;]*|woocommerce_cart_hash)="] },
|
||||
]),
|
||||
],
|
||||
django: () => [templateCookieGuard("cacheRuleTplDjango", [{ field: "cookie", name: "sessionid", operator: "exists" }])],
|
||||
laravel: () => [templateCookieGuard("cacheRuleTplLaravel", [{ field: "header", name: "Cookie", operator: "regex", values: ["(?:^|;[ \\t]*)(?:laravel_session|PHPSESSID)="] }])],
|
||||
authjs: () => [templateCookieGuard("cacheRuleTplAuthjs", [{ field: "header", name: "Cookie", operator: "regex", values: ["(?:^|;[ \\t]*)(?:__Secure-)?(?:next-auth[.]session-token|authjs[.]session-token)="] }])],
|
||||
aspnet: () => [templateCookieGuard("cacheRuleTplAspnet", [{ field: "header", name: "Cookie", operator: "regex", values: ["(?:^|;[ \\t]*)(?:[.]AspNetCore[.]Cookies|ASP[.]NET_SessionId)="] }])],
|
||||
drupal: () => [templateCookieGuard("cacheRuleTplDrupal", [{ field: "header", name: "Cookie", operator: "regex", values: ["(?:^|;[ \\t]*)(?:S?SESS[a-fA-F0-9]+)="] }])],
|
||||
// Cache acceleration must be opt-in: names, routes, representation privacy,
|
||||
// Vary, and origin Cache-Control must be checked before activation.
|
||||
publicjson: () => [templateResponse("cacheRuleTplPublicjson", [
|
||||
@@ -325,6 +341,17 @@ window.rustProxyCacheRules = (() => {
|
||||
function applicableGlobals(vhostId) {
|
||||
return (envelope?.config?.cache?.rules || []).filter(rule => rule.enabled !== false && (!rule.vhosts?.length || rule.vhosts.includes(vhostId)));
|
||||
}
|
||||
// A request `pass` rule whose only conditions describe cookies (all match)
|
||||
// or that has a Cookie condition alongside others (any match) is a likely
|
||||
// Cookie/session guard created before cookie_pass existed.
|
||||
function cookieOnlyPass(rule) {
|
||||
if (rule.stage !== "request" || !rule.actions.some(a => a.type === "pass")) return false;
|
||||
const isCookie = c => !c.negate && (c.field === "cookie" || (c.field === "header" && String(c.name || "").trim().toLowerCase() === "cookie"));
|
||||
const cookies = rule.conditions.filter(isCookie);
|
||||
if (!cookies.length) return false;
|
||||
if (rule.match === "any") return rule.conditions.every(isCookie);
|
||||
return rule.conditions.every(c => isCookie(c) || (c.field === "method" && !c.negate));
|
||||
}
|
||||
function aspects(rule) { return new Set(rule.actions.map(a => ASPECTS[a.type]).filter(Boolean)); }
|
||||
function conflictsFor(vhostRules, globals) {
|
||||
const notes = [];
|
||||
@@ -527,6 +554,15 @@ window.rustProxyCacheRules = (() => {
|
||||
head.append(grip, toggle, title, hitCount, actions);
|
||||
card.append(head);
|
||||
if (scope === "global") for (const note of globalOverrideNotes(rule)) card.append(el("p", note, "fine cache-rules-notice cache-rule-note"));
|
||||
if (cookieOnlyPass(rule)) {
|
||||
// Controlled migration: an explicit pass is never relaxed automatically.
|
||||
// The operator may convert a Cookie-session guard after review.
|
||||
const note = el("p", t("cacheRuleCookieGuardHint"), "fine cache-rules-notice cache-rule-note");
|
||||
const convert = el("button", t("cacheRuleCookieGuardConvert"), "outline"); convert.type = "button";
|
||||
convert.addEventListener("click", () => { rule.actions = rule.actions.map(a => a.type === "pass" ? { type: "cookie_pass" } : a); render(); changed(); toast(t("cacheRuleCookieGuardConverted")); });
|
||||
note.append(" ", convert);
|
||||
card.append(note);
|
||||
}
|
||||
if (open.has(rule.id)) card.append(ruleEditor(rule));
|
||||
return card;
|
||||
}
|
||||
@@ -690,6 +726,9 @@ window.rustProxyCacheRules = (() => {
|
||||
const request = data.request || {};
|
||||
line(t("cacheRulesResultDecision"), request.cacheable ? (data.response?.stored ? t("cacheRulesResultHit").replace("{ttl}", fmtDuration(data.response.ttl)).replace("{grace}", fmtDuration(data.response.grace)) : t("cacheRulesResultNotStored").replace("{reason}", data.response?.reason || "-")) : t("cacheRulesResultPass").replace("{reason}", request.reason || "-"), request.cacheable && data.response?.stored ? "is-ok" : "is-warn");
|
||||
line(t("cacheRulesResultRequest"), names(request.matched));
|
||||
if (request.reason_class) line(t("cacheRulesResultReasonClass"), t(`cacheReasonClass_${request.reason_class}`));
|
||||
if (request.static_cookie_relaxed) line(t("cacheRulesResultStaticCookie"), t("cacheRulesResultStaticCookieRelaxed"), "is-ok");
|
||||
else if (request.shared_static_check) line(t("cacheRulesResultStaticCookie"), t("cacheRulesResultStaticCookieChecked"));
|
||||
if (request.header_edits?.length) line(t("cacheRulesResultRequestHeaders"), request.header_edits.map(edit => edit.type === "set" ? `${edit.name}: ${edit.value}` : `−${edit.name}`).join(", "));
|
||||
line(t("cacheRulesResultKey"), `${data.host || "-"}${request.target || ""}${request.variant?.length ? ` + ${request.variant.join(", ")}` : ""}`);
|
||||
if (request.cookie != null) line(t("cacheRulesResultCookie"), request.cookie || "—");
|
||||
@@ -716,7 +755,7 @@ window.rustProxyCacheRules = (() => {
|
||||
// strip / remaining-cookie pass checks; never move or merge CDN rules.
|
||||
const cdnIndex = templateKey === "publiccookies" ? rules.findIndex(rule =>
|
||||
/^CDN:/.test(rule.name || "") && rule.conditions.some(c => c.field === "header" && String(c.name || "").toLowerCase() === "cookie") &&
|
||||
rule.actions.some(a => a.type === "strip_cookies" || a.type === "pass")) : -1;
|
||||
rule.actions.some(a => a.type === "strip_cookies" || a.type === "pass" || a.type === "cookie_pass")) : -1;
|
||||
if (cdnIndex >= 0) rules.splice(cdnIndex, 0, ...addedRules);
|
||||
else rules.push(...addedRules);
|
||||
if (addedRules.length) open.add(addedRules[0].id);
|
||||
|
||||
Reference in new issue
Block a user