fix: render repository images in project READMEs - #958
Open
TyreeZhao wants to merge 3 commits into
Open
Conversation
Resolve relative README image paths through an authenticated media endpoint with content validation and caching. Support sanitized HTML images and cover unsafe paths and media types.\n\nRefs chaitin#957
Support GitHub repository images larger than 1 MiB without unbounded buffering, revalidate mutable branch images with ETags, and cover content sniffing and download limits.\n\nRefs chaitin#957
Preserve the existing GitHub blob behavior unless an explicit media limit is supplied, document all supported image response types, and add the generated binary API contract and integration wiring test. Refs chaitin#957
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.
问题
项目「信息」页中的 README 无法展示仓库内相对路径图片:Markdown 图片显示为破图,原生 HTML 图片语法显示为文本。
Closes #957
修改范围
后端
GET /api/v1/users/projects/{id}/tree/media接口。path和ref获取 README 图片。Content-Type。ETag、private, no-cache、inline disposition 与nosniff响应头。前端
resolveImageUrl扩展点,不改变其他调用方的默认行为。data:、javascript:、反斜杠和越出仓库根目录的路径。rehype-sanitize净化后的原生 HTML,以支持<details>/<img>。format: "blob")。测试证据
go test ./pkg/git/github ./biz/project/handler/v1✅go test -race ./pkg/git/... ./biz/project/...✅npx --yes tsx --test test/readme-media.test.ts✅(6/6)npm run lint✅npm run build✅jq empty backend/docs/swagger.json✅1440 × 1000390 × 3390.png、实际内容为 JPEG,服务端正确返回image/jpeg截图
修复后:Markdown 相对图片正常展示:

修复后:经安全净化的原生 HTML
<img>正常展示: