Skip to content

Commit

Permalink
fix: 禁止访客发表 HTML 内容
Browse files Browse the repository at this point in the history
https://blog.twofei.com/902/#comment-1528

再不写完整的集成/端到端测试,感觉我要经常改挂逻辑
  • Loading branch information
movsb committed Jun 21, 2024
1 parent c23efe8 commit 98f6c05
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions service/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package service
import (
"context"
"fmt"
"html"
"log"
"net/url"
"os"
Expand Down Expand Up @@ -234,7 +235,7 @@ func (s *Service) renderMarkdown(secure bool, postId, commentId int64, sourceTyp
tr = &renderers.HTML{}
return tr.Render(source)
case `plain`:
return source, nil
return html.EscapeString(source), nil
}

if sourceType != `markdown` {
Expand Down Expand Up @@ -265,16 +266,10 @@ func (s *Service) renderMarkdown(secure bool, postId, commentId int64, sourceTyp
media_size.New(s.OpenAsset(postId), media_size.WithLocalOnly(), media_size.WithDimensionLimiter(350)),
)
}
if commentId > 0 {
if !secure {
options = append(options,
renderers.WithDisableHeadings(true),
renderers.WithDisableHTML(true),
)
}
if !secure {
options = append(options,
renderers.WithRemoveTitleHeading(),
renderers.WithOpenLinksInNewTab(renderers.OpenLinksInNewTabKind(co.OpenLinksInNewTab)),
renderers.WithDisableHeadings(true),
renderers.WithDisableHTML(true),
)
}
if co.RenderCodeBlocks {
Expand Down

0 comments on commit 98f6c05

Please sign in to comment.