fix(qa): 第五轮系统性质量保障缺陷修复 + 单元/集成测试
安全/鉴权:登出清服务端 httpOnly 令牌、登录 IP 限流前置 bcrypt、停用账号 令牌在 6 个内联 role handler 失效、admin/items 存在性 oracle 认证前置、 同意偏好 sanitize fail-closed、api-crypto 按 HTTP 方法判体。 CMS:workflow 状态更新+审计收进交互式 $transaction(失败即回滚)、编辑器 richtext 走 textarea 防换行损毁、array/object 子字段按作用域读写防污染、 about/contact/erp-upgrade 补 ISR revalidate 与路由映射。 UI/a11y:AnimatedCounter 入视口前显起点、CLS 累计上报、MetricCard 动画入 effect 并卸载取消 rAF、后台状态四态映射/搜索防抖+序号守卫/媒体单 input/ 吞错改横幅/表单 label-aria 关联。 新增对应判别性单测与 pagination/rate-limit/client-ip/sanitize/validate-content-data 等模块及 tests-integration 真库集成层。
This commit is contained in:
1 parent
040951c0a3
commit
a366bd1400
224 files changed
+8938
-5579
No files matched your search
@@ -230,6 +230,24 @@ describe('StructuredData', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('JSON-LD 序列化的 </script> 闭合防护', () => {
|
||||
const PAYLOAD = '</script><img src=x onerror=alert(1)>';
|
||||
|
||||
it('序列化结果里不出现字面 </script>,改为 \\u003c 转义', () => {
|
||||
const { container } = render(<FAQSchema items={[{ question: PAYLOAD, answer: 'a' }]} />);
|
||||
const text = container.querySelector('script[type="application/ld+json"]')?.textContent ?? '';
|
||||
expect(text).not.toContain('</script>');
|
||||
expect(text).toContain('\\u003c/script\\u003e');
|
||||
});
|
||||
|
||||
it('转义不改变 JSON 语义,解析后仍是原字符串', () => {
|
||||
const { container } = render(<FAQSchema items={[{ question: PAYLOAD, answer: 'b' }]} />);
|
||||
const script = container.querySelector('script[type="application/ld+json"]');
|
||||
const schema = JSON.parse(script?.textContent || '{}');
|
||||
expect(schema.mainEntity[0].name).toBe(PAYLOAD);
|
||||
});
|
||||
});
|
||||
|
||||
describe('LocalBusinessSchema', () => {
|
||||
it('should render local business schema', () => {
|
||||
const { container } = render(<LocalBusinessSchema />);
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
import { COMPANY_INFO } from '@/lib/constants';
|
||||
|
||||
/**
|
||||
* JSON-LD 内联脚本的序列化。JSON.stringify 不转义尖括号,因此字符串值里出现的 `</script>`
|
||||
* 会提前闭合 <script>,把后续内容放回 HTML 标记流(与 A-3 同一类缺陷,只是换了 sink)。
|
||||
* `\u003c` / `\u003e` 在 JSON 解析后逐字等值,对搜索引擎解析器无影响。
|
||||
*/
|
||||
function jsonLd(schema: unknown): string {
|
||||
return JSON.stringify(schema).replace(/</g, '\\u003c').replace(/>/g, '\\u003e');
|
||||
}
|
||||
|
||||
export function OrganizationSchema() {
|
||||
const schema = {
|
||||
"@context": "https://schema.org",
|
||||
@@ -50,7 +59,7 @@ export function OrganizationSchema() {
|
||||
return (
|
||||
<script
|
||||
type="application/ld+json"
|
||||
dangerouslySetInnerHTML={{ __html: JSON.stringify(schema) }}
|
||||
dangerouslySetInnerHTML={{ __html: jsonLd(schema) }}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -76,7 +85,7 @@ export function WebsiteSchema() {
|
||||
return (
|
||||
<script
|
||||
type="application/ld+json"
|
||||
dangerouslySetInnerHTML={{ __html: JSON.stringify(schema) }}
|
||||
dangerouslySetInnerHTML={{ __html: jsonLd(schema) }}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -120,7 +129,7 @@ export function ServiceSchema({ name, description, areaServed }: ServiceSchemaPr
|
||||
return (
|
||||
<script
|
||||
type="application/ld+json"
|
||||
dangerouslySetInnerHTML={{ __html: JSON.stringify(schema) }}
|
||||
dangerouslySetInnerHTML={{ __html: jsonLd(schema) }}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -159,7 +168,7 @@ export function ProductSchema({ name, description, image, category }: ProductSch
|
||||
return (
|
||||
<script
|
||||
type="application/ld+json"
|
||||
dangerouslySetInnerHTML={{ __html: JSON.stringify(schema) }}
|
||||
dangerouslySetInnerHTML={{ __html: jsonLd(schema) }}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -186,7 +195,7 @@ export function FAQSchema({ items }: { items: FAQItem[] }) {
|
||||
return (
|
||||
<script
|
||||
type="application/ld+json"
|
||||
dangerouslySetInnerHTML={{ __html: JSON.stringify(schema) }}
|
||||
dangerouslySetInnerHTML={{ __html: jsonLd(schema) }}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -211,7 +220,7 @@ export function BreadcrumbSchema({ items }: { items: BreadcrumbItem[] }) {
|
||||
return (
|
||||
<script
|
||||
type="application/ld+json"
|
||||
dangerouslySetInnerHTML={{ __html: JSON.stringify(schema) }}
|
||||
dangerouslySetInnerHTML={{ __html: jsonLd(schema) }}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -263,7 +272,7 @@ export function LocalBusinessSchema() {
|
||||
return (
|
||||
<script
|
||||
type="application/ld+json"
|
||||
dangerouslySetInnerHTML={{ __html: JSON.stringify(schema) }}
|
||||
dangerouslySetInnerHTML={{ __html: jsonLd(schema) }}
|
||||
/>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user