@@ -135,7 +135,7 @@ func TestToTOML(t *testing.T) {
135135 got := DefaultConfig .ToTOML ()
136136
137137 c .Assert (got , qt .Equals ,
138- "[security]\n enableInlineShortcodes = false\n \n [security.exec]\n allow = ['^(dart-)?sass(-embedded)?$', '^go$', '^git$', '^node$', '^postcss$', '^tailwindcss$']\n osEnv = ['(?i)^((HTTPS?|NO)_PROXY|PATH(EXT)?|APPDATA|TE?MP|TERM|GO\\ w+|(XDG_CONFIG_)?HOME|USERPROFILE|SSH_AUTH_SOCK|DISPLAY|LANG|SYSTEMDRIVE|PROGRAMDATA)$']\n \n [security.funcs]\n getenv = ['^HUGO_', '^CI$']\n \n [security.http]\n methods = ['(?i)GET|POST']\n urls = ['(?i)^https?://[a-z0-9]', '! ^https?://\\ d+\\ .', '! (?i)localhost', '! (?i)^https?://[^/?#]*@']\n \n [security.node]\n [security.node.permissions]\n allowAddons = ['tailwindcss']\n allowChildProcess = ['tailwindcss']\n allowRead = ['.']\n allowWorker = ['tailwindcss']\n allowWrite = []\n disable = false" ,
138+ "[security]\n allowContent = ['! ^text/html$'] \n enableInlineShortcodes = false\n \n [security.exec]\n allow = ['^(dart-)?sass(-embedded)?$', '^go$', '^git$', '^node$', '^postcss$', '^tailwindcss$']\n osEnv = ['(?i)^((HTTPS?|NO)_PROXY|PATH(EXT)?|APPDATA|TE?MP|TERM|GO\\ w+|(XDG_CONFIG_)?HOME|USERPROFILE|SSH_AUTH_SOCK|DISPLAY|LANG|SYSTEMDRIVE|PROGRAMDATA)$']\n \n [security.funcs]\n getenv = ['^HUGO_', '^CI$']\n \n [security.http]\n methods = ['(?i)GET|POST']\n urls = ['(?i)^https?://[a-z0-9]', '! ^https?://\\ d+\\ .', '! (?i)localhost', '! (?i)^https?://[^/?#]*@']\n \n [security.node]\n [security.node.permissions]\n allowAddons = ['tailwindcss']\n allowChildProcess = ['tailwindcss']\n allowRead = ['.']\n allowWorker = ['tailwindcss']\n allowWrite = []\n disable = false" ,
139139 )
140140}
141141
@@ -298,6 +298,48 @@ func TestCheckAllowedHTTPURLDigitHostnameIssue14837(t *testing.T) {
298298 }
299299}
300300
301+ func TestCheckAllowedContent (t * testing.T ) {
302+ t .Parallel ()
303+ c := qt .New (t )
304+
305+ c .Run ("text/html denied by default" , func (c * qt.C ) {
306+ c .Parallel ()
307+ pc , err := DecodeConfig (config .New ())
308+ c .Assert (err , qt .IsNil )
309+ err = pc .CheckAllowedContent ("text/html" )
310+ c .Assert (err , qt .IsNotNil )
311+ c .Assert (err , qt .ErrorMatches , `(?s).*"text/html" is not whitelisted in policy "security\.allowContent".*` )
312+ })
313+
314+ c .Run ("Other content types allowed by default" , func (c * qt.C ) {
315+ c .Parallel ()
316+ pc , err := DecodeConfig (config .New ())
317+ c .Assert (err , qt .IsNil )
318+ for _ , mt := range []string {
319+ "text/markdown" ,
320+ "text/asciidoc" ,
321+ "text/x-org" ,
322+ "text/rst" ,
323+ "text/pandoc" ,
324+ } {
325+ c .Assert (pc .CheckAllowedContent (mt ), qt .IsNil , qt .Commentf (mt ))
326+ }
327+ })
328+
329+ c .Run ("User can opt in to HTML" , func (c * qt.C ) {
330+ c .Parallel ()
331+ tomlConfig := `
332+ [security]
333+ allowContent = ['.*']
334+ `
335+ cfg , err := config .FromConfigString (tomlConfig , "toml" )
336+ c .Assert (err , qt .IsNil )
337+ pc , err := DecodeConfig (cfg )
338+ c .Assert (err , qt .IsNil )
339+ c .Assert (pc .CheckAllowedContent ("text/html" ), qt .IsNil )
340+ })
341+ }
342+
301343func TestDecodeConfigNodePermissions (t * testing.T ) {
302344 c := qt .New (t )
303345
0 commit comments