fix: 修复系统一致性与安全问题
This commit is contained in:
1 parent
aaeec14733
commit
f158f906d5
19 files changed
+194
-34
No files matched your search
@@ -11,7 +11,6 @@ export class UpdateMiniAppSettingsDto {
|
||||
@MaxLength(200)
|
||||
apiBaseUrl?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsOptional()
|
||||
@IsObject()
|
||||
build?: Record<string, unknown>;
|
||||
|
||||
@@ -136,7 +136,7 @@ export class AdminUploadController {
|
||||
const target = path.join(this.localMediaRoot, key);
|
||||
await mkdir(path.dirname(target), { recursive: true });
|
||||
return {
|
||||
uploadUrl: `/api/admin/uploads/local?key=${encodeURIComponent(key)}`,
|
||||
uploadUrl: `/admin/uploads/local?key=${encodeURIComponent(key)}`,
|
||||
key,
|
||||
publicUrl: `${this.localMediaBaseUrl}/${key}`,
|
||||
mode: "local",
|
||||
|
||||
@@ -132,7 +132,8 @@ export class CustomerInquirySubmissionController {
|
||||
if (field.type === "number" && !Number.isFinite(Number(value)))
|
||||
throw new BadRequestException(`${label}必须是数字`);
|
||||
}
|
||||
const allowedKeys = new Set(fields.map((field) => String(field.key)));
|
||||
const visibleFields = fields.filter((field) => this.isVisibleField(field, body.values));
|
||||
const allowedKeys = new Set(visibleFields.map((field) => String(field.key)));
|
||||
const values = Object.fromEntries(
|
||||
Object.entries(body.values).filter(([key]) => allowedKeys.has(key)),
|
||||
);
|
||||
@@ -150,4 +151,29 @@ export class CustomerInquirySubmissionController {
|
||||
});
|
||||
return this.present(submission);
|
||||
}
|
||||
|
||||
private visibilityRuleMatches(rule: unknown, values: Record<string, unknown>): boolean {
|
||||
if (!rule || typeof rule !== "object") return true;
|
||||
const item = rule as Record<string, unknown>;
|
||||
if (typeof item.field !== "string") return true;
|
||||
const value = values[item.field];
|
||||
switch (item.operator) {
|
||||
case "exists":
|
||||
return Array.isArray(value) ? value.length > 0 : Boolean(value);
|
||||
case "equals":
|
||||
return value === item.value;
|
||||
case "not-equals":
|
||||
return value !== item.value;
|
||||
case "in":
|
||||
return Array.isArray(item.value) && typeof value === "string" && item.value.includes(value);
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private isVisibleField(field: Record<string, unknown>, values: Record<string, unknown>): boolean {
|
||||
return (Array.isArray(field.visibleWhen) ? field.visibleWhen : []).every((rule) =>
|
||||
this.visibilityRuleMatches(rule, values),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,11 @@
|
||||
import { BadRequestException, Controller, Get, Param, Query } from "@nestjs/common";
|
||||
import {
|
||||
BadRequestException,
|
||||
Controller,
|
||||
Get,
|
||||
NotFoundException,
|
||||
Param,
|
||||
Query,
|
||||
} from "@nestjs/common";
|
||||
import { PublicBrandContextService } from "./public-brand-context.service.js";
|
||||
import { BrandReleaseService } from "../../brand-release.service.js";
|
||||
|
||||
@@ -34,7 +41,7 @@ export class PublicOfferingController {
|
||||
const item = (snapshot?.offerings ?? [])
|
||||
.map((raw) => this.object(raw))
|
||||
.find((offering) => offering.id === id && offering.isEnabled === true);
|
||||
if (!item) throw new BadRequestException("业务提供项不存在");
|
||||
if (!item) throw new NotFoundException("业务提供项不存在");
|
||||
const forms = (snapshot?.forms ?? []).filter((raw) => {
|
||||
const form = this.object(raw);
|
||||
return form.offeringId === id && form.isEnabled === true;
|
||||
|
||||
@@ -149,6 +149,35 @@ export function toRuntimeInquiryFields(snapshot: Prisma.JsonValue): RuntimeInqui
|
||||
? [{ label: item.label, value: item.value }]
|
||||
: [];
|
||||
});
|
||||
const visibleWhen = asArray(value.visibleWhen).flatMap((rule) => {
|
||||
if (!rule || typeof rule !== "object") return [];
|
||||
const item = rule as Record<string, unknown>;
|
||||
if (typeof item.field !== "string") return [];
|
||||
const operator: "equals" | "not-equals" | "exists" | "in" = item.operator as
|
||||
"equals" | "not-equals" | "exists" | "in";
|
||||
if (
|
||||
operator !== "equals" &&
|
||||
operator !== "not-equals" &&
|
||||
operator !== "exists" &&
|
||||
operator !== "in"
|
||||
)
|
||||
return [];
|
||||
const ruleValue = item.value;
|
||||
const normalizedValue =
|
||||
typeof ruleValue === "string" ||
|
||||
typeof ruleValue === "number" ||
|
||||
typeof ruleValue === "boolean" ||
|
||||
(Array.isArray(ruleValue) && ruleValue.every((entry) => typeof entry === "string"))
|
||||
? ruleValue
|
||||
: undefined;
|
||||
return [
|
||||
{
|
||||
field: item.field,
|
||||
operator,
|
||||
...(normalizedValue === undefined ? {} : { value: normalizedValue }),
|
||||
},
|
||||
];
|
||||
});
|
||||
return [
|
||||
{
|
||||
key: value.key,
|
||||
@@ -156,6 +185,7 @@ export function toRuntimeInquiryFields(snapshot: Prisma.JsonValue): RuntimeInqui
|
||||
type,
|
||||
required: value.required === true,
|
||||
...(options.length ? { options } : {}),
|
||||
...(visibleWhen.length ? { visibleWhen } : {}),
|
||||
},
|
||||
];
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user