Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
+17
-22
@@ -25,6 +25,7 @@ import { verifyUserHasPermission } from "~/utils/helpers/.server/PermissionsServ
|
||||
import { getUserInfo, validateCSRFToken } from "~/utils/session.server";
|
||||
import { getUser } from "~/utils/db/users.db.server";
|
||||
import { getSharedStore } from "~/shared-store.server";
|
||||
import { getTrustedClientIpOrNull } from "~/utils/server/IpUtils";
|
||||
import {
|
||||
parsePluginCapabilityGrantArray,
|
||||
parsePluginCapabilityNameArray,
|
||||
@@ -45,6 +46,7 @@ import {
|
||||
} from "~/modules/plugins/services/.server/PluginLifecycleService";
|
||||
import { getPluginConsentRequirements } from "~/modules/plugins/utils/pluginConsentRequirements";
|
||||
import { getTranslations } from "~/locale/i18next.server";
|
||||
import { getPseudonymousAuthBucketKey } from "~/services/auth/auth-rate-limit-key.server";
|
||||
|
||||
const USE_PERMISSION = "app.plugins.use";
|
||||
const MANAGE_PERMISSION = "app.plugins.manage";
|
||||
@@ -69,17 +71,12 @@ async function createCapabilityReviewDigest(item: Pick<PluginListItem, "pluginId
|
||||
* rows + signature-verify CPU. The key is tenant-scoped so adversarial
|
||||
* activity on one tenant cannot starve another.
|
||||
*
|
||||
* Fail-open on infra error outside production (matches existing pattern in
|
||||
* api.leads.capture and api.embed.forms.$formKey.submit) — a flaky Redis
|
||||
* must not block legitimate staging/dev operator installs. Production always
|
||||
* fails closed for plugin writes.
|
||||
* Rate-limit infrastructure failures are fail-closed in every environment.
|
||||
* Staging may contain real credentials and integrations, so weakening this
|
||||
* boundary based on NODE_ENV would create an avoidable security gap.
|
||||
*/
|
||||
const INSTALL_RATE_LIMIT_PREFIX = "plugin-install-route:rl";
|
||||
|
||||
function shouldFailClosedOnRateLimitInfraFailure(): boolean {
|
||||
return process.env.NODE_ENV === "production";
|
||||
}
|
||||
|
||||
function resolveInstallRateLimitPerMin(): number {
|
||||
const raw = process.env.PLUGIN_INSTALL_RATE_LIMIT_PER_MIN;
|
||||
if (typeof raw !== "string" || raw.length === 0) return 5;
|
||||
@@ -277,7 +274,9 @@ export async function action({ request, params }: ActionFunctionArgs) {
|
||||
windowSeconds: 60,
|
||||
prefix: INSTALL_RATE_LIMIT_PREFIX,
|
||||
});
|
||||
const tenantDecision = await limiter.consume(`tenant:${tenantId}`);
|
||||
const tenantDecision = await limiter.consume(
|
||||
getPseudonymousAuthBucketKey({ request, action: "plugin-install", identifier: tenantId, scope: "identifier" })
|
||||
);
|
||||
if (!tenantDecision.allowed) {
|
||||
return Response.json(
|
||||
{ error: "rate_limit_exceeded", message: t("api.plugins.errors.installRateLimitExceeded", { perMin }) },
|
||||
@@ -286,7 +285,9 @@ export async function action({ request, params }: ActionFunctionArgs) {
|
||||
}
|
||||
const ip = getRequestIp(request);
|
||||
if (ip) {
|
||||
const ipDecision = await limiter.consume(`ip:${ip}`);
|
||||
const ipDecision = await limiter.consume(
|
||||
getPseudonymousAuthBucketKey({ request, action: "plugin-install", scope: "client" })
|
||||
);
|
||||
if (!ipDecision.allowed) {
|
||||
return Response.json(
|
||||
{ error: "rate_limit_exceeded", message: t("api.plugins.errors.installRateLimitExceeded", { perMin }) },
|
||||
@@ -294,17 +295,11 @@ export async function action({ request, params }: ActionFunctionArgs) {
|
||||
);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
if (shouldFailClosedOnRateLimitInfraFailure()) {
|
||||
return Response.json(
|
||||
{ error: "rate_limit_unavailable", message: t("api.plugins.errors.rateLimitUnavailable") },
|
||||
{ status: 503, headers: { "Retry-After": "60" } }
|
||||
);
|
||||
}
|
||||
// Fail-open on infra error outside production — better than dropping
|
||||
// legitimate staging/dev installs while Redis is being restarted.
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn("[plugin-install] rate-limit infra failure; allowing install:", err instanceof Error ? err.message : String(err));
|
||||
} catch {
|
||||
return Response.json(
|
||||
{ error: "rate_limit_unavailable", message: t("api.plugins.errors.rateLimitUnavailable") },
|
||||
{ status: 503, headers: { "Retry-After": "60" } }
|
||||
);
|
||||
}
|
||||
|
||||
const actor = await resolveActor(request);
|
||||
@@ -338,5 +333,5 @@ async function resolveActor(request: Request): Promise<PluginLifecycleActor> {
|
||||
}
|
||||
|
||||
function getRequestIp(request: Request): string | null {
|
||||
return request.headers.get("x-forwarded-for")?.split(",")[0]?.trim() || request.headers.get("x-real-ip")?.trim() || null;
|
||||
return getTrustedClientIpOrNull(request);
|
||||
}
|
||||
Reference in new issue
Block a user