mirror of
				https://codeberg.org/forgejo/forgejo.git
				synced 2025-11-04 00:11:04 +00:00 
			
		
		
		
	fix: strict matching of allowed content for sanitizer
- _Simply_ add `^$` to regexp that didn't had it yet, this avoids any
content being allowed that simply had the allowed content as a
substring.
- Fix file-preview regex to have `$` instead of `*`.
(cherry picked from commit 7067cc7da4)
v7: added fix for ref-issue, this is already fixed in forgejo branch but
not backported as it was part of a feature.
	
	
This commit is contained in:
		
					parent
					
						
							
								c2284d871f
							
						
					
				
			
			
				commit
				
					
						3a197f7de2
					
				
			
		
					 1 changed files with 5 additions and 5 deletions
				
			
		| 
						 | 
					@ -94,10 +94,10 @@ func createDefaultPolicy() *bluemonday.Policy {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Allow classes for anchors
 | 
						// Allow classes for anchors
 | 
				
			||||||
	policy.AllowAttrs("class").Matching(regexp.MustCompile(`ref-issue( ref-external-issue)?`)).OnElements("a")
 | 
						policy.AllowAttrs("class").Matching(regexp.MustCompile(`^ref-issue( ref-external-issue)?$`)).OnElements("a")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Allow classes for task lists
 | 
						// Allow classes for task lists
 | 
				
			||||||
	policy.AllowAttrs("class").Matching(regexp.MustCompile(`task-list-item`)).OnElements("li")
 | 
						policy.AllowAttrs("class").Matching(regexp.MustCompile(`^task-list-item$`)).OnElements("li")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Allow classes for org mode list item status.
 | 
						// Allow classes for org mode list item status.
 | 
				
			||||||
	policy.AllowAttrs("class").Matching(regexp.MustCompile(`^(unchecked|checked|indeterminate)$`)).OnElements("li")
 | 
						policy.AllowAttrs("class").Matching(regexp.MustCompile(`^(unchecked|checked|indeterminate)$`)).OnElements("li")
 | 
				
			||||||
| 
						 | 
					@ -106,7 +106,7 @@ func createDefaultPolicy() *bluemonday.Policy {
 | 
				
			||||||
	policy.AllowAttrs("class").Matching(regexp.MustCompile(`^icon(\s+[\p{L}\p{N}_-]+)+$`)).OnElements("i")
 | 
						policy.AllowAttrs("class").Matching(regexp.MustCompile(`^icon(\s+[\p{L}\p{N}_-]+)+$`)).OnElements("i")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Allow classes for emojis
 | 
						// Allow classes for emojis
 | 
				
			||||||
	policy.AllowAttrs("class").Matching(regexp.MustCompile(`emoji`)).OnElements("img")
 | 
						policy.AllowAttrs("class").Matching(regexp.MustCompile(`^emoji$`)).OnElements("img")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Allow icons, emojis, chroma syntax and keyword markup on span
 | 
						// Allow icons, emojis, chroma syntax and keyword markup on span
 | 
				
			||||||
	policy.AllowAttrs("class").Matching(regexp.MustCompile(`^((icon(\s+[\p{L}\p{N}_-]+)+)|(emoji)|(language-math display)|(language-math inline))$|^([a-z][a-z0-9]{0,2})$|^` + keywordClass + `$`)).OnElements("span")
 | 
						policy.AllowAttrs("class").Matching(regexp.MustCompile(`^((icon(\s+[\p{L}\p{N}_-]+)+)|(emoji)|(language-math display)|(language-math inline))$|^([a-z][a-z0-9]{0,2})$|^` + keywordClass + `$`)).OnElements("span")
 | 
				
			||||||
| 
						 | 
					@ -122,13 +122,13 @@ func createDefaultPolicy() *bluemonday.Policy {
 | 
				
			||||||
	policy.AllowAttrs("class").Matching(regexp.MustCompile("^header$")).OnElements("div")
 | 
						policy.AllowAttrs("class").Matching(regexp.MustCompile("^header$")).OnElements("div")
 | 
				
			||||||
	policy.AllowAttrs("data-line-number").Matching(regexp.MustCompile("^[0-9]+$")).OnElements("span")
 | 
						policy.AllowAttrs("data-line-number").Matching(regexp.MustCompile("^[0-9]+$")).OnElements("span")
 | 
				
			||||||
	policy.AllowAttrs("class").Matching(regexp.MustCompile("^text small grey$")).OnElements("span")
 | 
						policy.AllowAttrs("class").Matching(regexp.MustCompile("^text small grey$")).OnElements("span")
 | 
				
			||||||
	policy.AllowAttrs("class").Matching(regexp.MustCompile("^file-preview*")).OnElements("table")
 | 
						policy.AllowAttrs("class").Matching(regexp.MustCompile("^file-preview$")).OnElements("table")
 | 
				
			||||||
	policy.AllowAttrs("class").Matching(regexp.MustCompile("^lines-escape$")).OnElements("td")
 | 
						policy.AllowAttrs("class").Matching(regexp.MustCompile("^lines-escape$")).OnElements("td")
 | 
				
			||||||
	policy.AllowAttrs("class").Matching(regexp.MustCompile("^toggle-escape-button btn interact-bg$")).OnElements("button")
 | 
						policy.AllowAttrs("class").Matching(regexp.MustCompile("^toggle-escape-button btn interact-bg$")).OnElements("button")
 | 
				
			||||||
	policy.AllowAttrs("title").OnElements("button")
 | 
						policy.AllowAttrs("title").OnElements("button")
 | 
				
			||||||
	policy.AllowAttrs("class").Matching(regexp.MustCompile("^ambiguous-code-point$")).OnElements("span")
 | 
						policy.AllowAttrs("class").Matching(regexp.MustCompile("^ambiguous-code-point$")).OnElements("span")
 | 
				
			||||||
	policy.AllowAttrs("data-tooltip-content").OnElements("span")
 | 
						policy.AllowAttrs("data-tooltip-content").OnElements("span")
 | 
				
			||||||
	policy.AllowAttrs("class").Matching(regexp.MustCompile("muted|(text black)")).OnElements("a")
 | 
						policy.AllowAttrs("class").Matching(regexp.MustCompile("^muted|(text black)$")).OnElements("a")
 | 
				
			||||||
	policy.AllowAttrs("class").Matching(regexp.MustCompile("^ui warning message tw-text-left$")).OnElements("div")
 | 
						policy.AllowAttrs("class").Matching(regexp.MustCompile("^ui warning message tw-text-left$")).OnElements("div")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Allow generally safe attributes
 | 
						// Allow generally safe attributes
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue