mirror of
				https://codeberg.org/forgejo/forgejo.git
				synced 2025-11-04 08:21:11 +00:00 
			
		
		
		
	[GITEA] Use restricted sanitizer for repository description
- Currently the repository description uses the same sanitizer as a normal markdown document. This means that element such as heading and images are allowed and can be abused. - Create a minimal restricted sanitizer for the repository description, which only allows what the postprocessor currently allows, which are links and emojis. - Added unit testing. - Resolves https://codeberg.org/forgejo/forgejo/issues/1202 - Resolves https://codeberg.org/Codeberg/Community/issues/1122 (cherry picked from commita8afa4cd18) (cherry picked from commit0238587c51) (cherry picked from commita8c7bbf728) (cherry picked from commit80e05a8245) (cherry picked from commitf5af5050b3) (cherry picked from commit608f981e55) (cherry picked from commit6591867502) (cherry picked from commitb7e6dedafd)
This commit is contained in:
		
					parent
					
						
							
								2d561205d2
							
						
					
				
			
			
				commit
				
					
						1cd196da49
					
				
			
		
					 3 changed files with 56 additions and 5 deletions
				
			
		| 
						 | 
				
			
			@ -73,6 +73,28 @@ func Test_Sanitizer(t *testing.T) {
 | 
			
		|||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func TestDescriptionSanitizer(t *testing.T) {
 | 
			
		||||
	NewSanitizer()
 | 
			
		||||
 | 
			
		||||
	testCases := []string{
 | 
			
		||||
		`<h1>Title</h1>`, `Title`,
 | 
			
		||||
		`<img src='img.png' alt='image'>`, ``,
 | 
			
		||||
		`<span class="emoji" aria-label="thumbs up">THUMBS UP</span>`, `<span class="emoji" aria-label="thumbs up">THUMBS UP</span>`,
 | 
			
		||||
		`<span style="color: red">Hello World</span>`, `<span>Hello World</span>`,
 | 
			
		||||
		`<br>`, ``,
 | 
			
		||||
		`<a href="https://example.com" target="_blank" rel="noopener noreferrer">https://example.com</a>`, `<a href="https://example.com" target="_blank" rel="noopener noreferrer">https://example.com</a>`,
 | 
			
		||||
		`<mark>Important!</mark>`, `Important!`,
 | 
			
		||||
		`<details>Click me! <summary>Nothing to see here.</summary></details>`, `Click me! Nothing to see here.`,
 | 
			
		||||
		`<input type="hidden">`, ``,
 | 
			
		||||
		`<b>I</b> have a <i>strong</i> <strong>opinion</strong> about <em>this</em>.`, `<b>I</b> have a <i>strong</i> <strong>opinion</strong> about <em>this</em>.`,
 | 
			
		||||
		`Provides alternative <code>wg(8)</code> tool`, `Provides alternative <code>wg(8)</code> tool`,
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	for i := 0; i < len(testCases); i += 2 {
 | 
			
		||||
		assert.Equal(t, testCases[i+1], SanitizeDescription(testCases[i]))
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func TestSanitizeNonEscape(t *testing.T) {
 | 
			
		||||
	descStr := "<scrİpt><script>alert(document.domain)</script></scrİpt>"
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue