fix(posts-cr): Copilot CR fixes — XSS narrowing, bundle split, satoken guard#352
Merged
Conversation
- PostContent: narrow rehype-sanitize style attribute from * to span/svg only
(KaTeX only needs style on these two elements; global style is an XSS vector)
- Extract buildFrontmatter to lib/frontmatter.ts to avoid pulling editor
bundle into detail page / card bundles
- PostDetailOwnerActions: add .catch(()=>({})) on DELETE res.json() for
resilient error body parsing
- EditorPageClient: align titleToSlug comment with actual Unicode behavior,
add tags trim+filter before POST, guard satoken header to avoid empty token
- PromoteToDocsButton: update import path, guard satoken header
Co-authored-by: copilot-pull-request-reviewer[bot] <198982749+copilot-pull-request-reviewer[bot]@users.noreply.github.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR applies follow-up fixes to the lightweight posts feature: tightening UGC sanitization to reduce XSS/CSS-injection surface area, splitting buildFrontmatter into a standalone module to avoid pulling editor code into other bundles, and improving client request robustness (token handling + non-JSON error bodies).
Changes:
- Narrow
rehype-sanitize’sstyleallowance from global to KaTeX-required elements only (span/svg). - Extract
buildFrontmatterintolib/frontmatter.tsand update imports to reduce bundle coupling. - Harden client fetch flows: guard empty
satoken, trim/filter tags prior to POST, and tolerate non-JSON DELETE error bodies.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
lib/frontmatter.ts |
New shared buildFrontmatter helper to decouple editor bundle from promote/detail UI. |
app/components/PromoteToDocsButton.tsx |
Switch to shared buildFrontmatter; adjust satoken header handling for promote POST. |
app/components/PostContent.tsx |
Tighten sanitize schema: restrict style attribute to KaTeX-needed elements. |
app/[locale]/u/[username]/posts/[slug]/PostDetailOwnerActions.tsx |
Make DELETE response parsing resilient to non-JSON bodies; adjust auth header emission. |
app/[locale]/editor/EditorPageClient.tsx |
Update slug comment, normalize tags, and add clearer token guard for publish requests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+4
to
+5
| * 抽到独立模块的原因:EditorPageClient 和 PromoteToDocsButton 都需要它, | ||
| * 把它留在 EditorPageClient.tsx 会让详情页/卡片 bundle 拖进整个编辑器栈。 |
Comment on lines
+59
to
63
| headers: { ...(token ? { satoken: token } : {}) }, | ||
| }); | ||
| const body = (await res.json()) as ApiResponse<void>; | ||
| const body = (await res.json().catch(() => ({}))) as ApiResponse<void>; | ||
| if (res.ok && body.success) { | ||
| router.replace(`/u/${authorUsername}/posts`); |
Comment on lines
114
to
+118
| method: "POST", | ||
| headers: { | ||
| "Content-Type": "application/json", | ||
| // rewrite 透传:后端读 satoken,不是 x-satoken | ||
| satoken: token, | ||
| // rewrite 透传:后端读 satoken,不是 x-satoken;空 token 不发 header | ||
| ...(token ? { satoken: token } : {}), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
styleattribute in rehype-sanitize from*(all elements) tospan/svgonly — KaTeX only needs style on these two; allowing globalstyleis a CSS injection vector in UGC contentlib/frontmatter.ts(new): extractbuildFrontmatterout ofEditorPageClient.tsxso detail page and card bundles no longer pull in the entire editor stack.catch(()=>({}))on DELETEres.json()for resilient error body parsing (mirrors existingdeleteEventpattern in admin/events/lib.ts)titleToSlugcomment with actual Unicode behavior; addtags.map(t=>t.trim()).filter(Boolean)before POST; guardsatokenheader so empty token throws a clear error instead of sending empty headerbuildFrontmatterimport path; guardsatokenheader on promote POSTTest plan
pnpm buildpasses (TypeScript + 51 vitest tests + prebuild checks)Fixes Copilot CR feedback on PR #350.
🤖 Generated with Claude Code