🐛 Breadcrumb XSS https://github.com/siyuan-note/siyuan/issues/10753
This commit is contained in:
parent
62cc60c934
commit
42967694ef
2 changed files with 22 additions and 4 deletions
|
@ -366,6 +366,7 @@ func buildBlockBreadcrumb(node *ast.Node, excludeTypes []string) (ret []*BlockPa
|
|||
name = util.EscapeHTML(box.Name) + util.EscapeHTML(hPath)
|
||||
} else if ast.NodeAttributeView == parent.Type {
|
||||
name = treenode.GetAttributeViewName(parent.AttributeViewID)
|
||||
name = util.EscapeHTML(name)
|
||||
} else {
|
||||
if "" == name {
|
||||
if ast.NodeListItem == parent.Type {
|
||||
|
@ -373,6 +374,7 @@ func buildBlockBreadcrumb(node *ast.Node, excludeTypes []string) (ret []*BlockPa
|
|||
} else {
|
||||
name = gulu.Str.SubStr(renderBlockText(parent, excludeTypes), maxNameLen)
|
||||
}
|
||||
name = util.EscapeHTML(name)
|
||||
}
|
||||
if ast.NodeHeading == parent.Type {
|
||||
headingLevel = parent.HeadingLevel
|
||||
|
@ -389,6 +391,7 @@ func buildBlockBreadcrumb(node *ast.Node, excludeTypes []string) (ret []*BlockPa
|
|||
if ast.NodeListItem == parent.Type {
|
||||
if "" == name {
|
||||
name = gulu.Str.SubStr(renderBlockText(fc, excludeTypes), maxNameLen)
|
||||
name = util.EscapeHTML(name)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -42,11 +42,26 @@ func RemoveElem[T any](s []T, index int) []T {
|
|||
return append(s[:index], s[index+1:]...)
|
||||
}
|
||||
|
||||
func EscapeHTML(s string) string {
|
||||
if ContainsSubStr(s, []string{"&", "'", "<", ">", """, " "}) {
|
||||
return s
|
||||
func EscapeHTML(s string) (ret string) {
|
||||
ret = s
|
||||
if "" == strings.TrimSpace(ret) {
|
||||
return
|
||||
}
|
||||
return html.EscapeString(s)
|
||||
|
||||
ret = strings.ReplaceAll(ret, "&", "__@amp__")
|
||||
ret = strings.ReplaceAll(ret, "'", "__@39__")
|
||||
ret = strings.ReplaceAll(ret, "<", "__@lt__")
|
||||
ret = strings.ReplaceAll(ret, ">", "__@gt__")
|
||||
ret = strings.ReplaceAll(ret, """, "__@34__")
|
||||
ret = strings.ReplaceAll(ret, " ", "__@13__")
|
||||
ret = html.EscapeString(ret)
|
||||
ret = strings.ReplaceAll(ret, "__@amp__", "&")
|
||||
ret = strings.ReplaceAll(ret, "__@39__", "'")
|
||||
ret = strings.ReplaceAll(ret, "__@lt__", "<")
|
||||
ret = strings.ReplaceAll(ret, "__@gt__", ">")
|
||||
ret = strings.ReplaceAll(ret, "__@34__", """)
|
||||
ret = strings.ReplaceAll(ret, "__@13__", " ")
|
||||
return
|
||||
}
|
||||
|
||||
func Reverse(s string) string {
|
||||
|
|
Loading…
Add table
Reference in a new issue