// Copyright (c) 2014, David Kitchen // // All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // // * Redistributions of source code must retain the above copyright notice, this // list of conditions and the following disclaimer. // // * Redistributions in binary form must reproduce the above copyright notice, // this list of conditions and the following disclaimer in the documentation // and/or other materials provided with the distribution. // // * Neither the name of the organisation (Microcosm) nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package bluemonday import ( "encoding/base64" "net/url" "regexp" "strings" "sync" "testing" ) // test is a simple input vs output struct used to construct a slice of many // tests to run within a single test method. type test struct { in string expected string } func TestEmpty(t *testing.T) { p := StrictPolicy() if "" != p.Sanitize(``) { t.Error("Empty string is not empty") } } func TestSignatureBehaviour(t *testing.T) { // https://github.com/microcosm-cc/bluemonday/issues/8 p := UGCPolicy() input := "Hi.\n" if output := p.Sanitize(input); output != input { t.Errorf(`Sanitize() input = %s, output = %s`, input, output) } if output := string(p.SanitizeBytes([]byte(input))); output != input { t.Errorf(`SanitizeBytes() input = %s, output = %s`, input, output) } if output := p.SanitizeReader( strings.NewReader(input), ).String(); output != input { t.Errorf(`SanitizeReader() input = %s, output = %s`, input, output) } input = "\t\n \n\t" if output := p.Sanitize(input); output != input { t.Errorf(`Sanitize() input = %s, output = %s`, input, output) } if output := string(p.SanitizeBytes([]byte(input))); output != input { t.Errorf(`SanitizeBytes() input = %s, output = %s`, input, output) } if output := p.SanitizeReader( strings.NewReader(input), ).String(); output != input { t.Errorf(`SanitizeReader() input = %s, output = %s`, input, output) } } func TestAllowDocType(t *testing.T) { p := NewPolicy() p.AllowElements("b") in := "Hello, World!" expected := "Hello, World!" out := p.Sanitize(in) if out != expected { t.Errorf( "test 1 failed;\ninput : %s\noutput : %s\nexpected: %s", in, out, expected, ) } // Allow the doctype and run the test again p.AllowDocType(true) expected = "Hello, World!" out = p.Sanitize(in) if out != expected { t.Errorf( "test 1 failed;\ninput : %s\noutput : %s\nexpected: %s", in, out, expected, ) } } func TestLinks(t *testing.T) { tests := []test{ { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: `Red dot`, expected: `Red dot`, }, { in: ``, expected: ``, }, } p := UGCPolicy() p.RequireParseableURLs(true) // These tests are run concurrently to enable the race detector to pick up // potential issues wg := sync.WaitGroup{} wg.Add(len(tests)) for ii, tt := range tests { go func(ii int, tt test) { out := p.Sanitize(tt.in) if out != tt.expected { t.Errorf( "test %d failed;\ninput : %s\noutput : %s\nexpected: %s", ii, tt.in, out, tt.expected, ) } wg.Done() }(ii, tt) } wg.Wait() } func TestLinkTargets(t *testing.T) { tests := []test{ { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: `Red dot`, expected: `Red dot`, }, { in: ``, expected: ``, }, } p := UGCPolicy() p.RequireParseableURLs(true) p.RequireNoFollowOnLinks(false) p.RequireNoFollowOnFullyQualifiedLinks(true) p.AddTargetBlankToFullyQualifiedLinks(true) // These tests are run concurrently to enable the race detector to pick up // potential issues wg := sync.WaitGroup{} wg.Add(len(tests)) for ii, tt := range tests { go func(ii int, tt test) { out := p.Sanitize(tt.in) if out != tt.expected { t.Errorf( "test %d failed;\ninput : %s\noutput : %s\nexpected: %s", ii, tt.in, out, tt.expected, ) } wg.Done() }(ii, tt) } wg.Wait() } func TestStyling(t *testing.T) { tests := []test{ { in: `Hello World`, expected: `Hello World`, }, { in: `Hello World`, expected: `Hello World`, }, } p := UGCPolicy() p.AllowStyling() // These tests are run concurrently to enable the race detector to pick up // potential issues wg := sync.WaitGroup{} wg.Add(len(tests)) for ii, tt := range tests { go func(ii int, tt test) { out := p.Sanitize(tt.in) if out != tt.expected { t.Errorf( "test %d failed;\ninput : %s\noutput : %s\nexpected: %s", ii, tt.in, out, tt.expected, ) } wg.Done() }(ii, tt) } wg.Wait() } func TestEmptyAttributes(t *testing.T) { p := UGCPolicy() // Do not do this, especially without a Matching() clause, this is a test p.AllowAttrs("disabled").OnElements("textarea") tests := []test{ // Empty elements { in: `` + `
Styled by span
`, expected: `` + `
Styled by span
`, }, { in: `foo
bar`, expected: `foo
bar`, }, { in: `foo
bar`, expected: `foo
bar`, }, { in: `foo
bar`, expected: `foo
bar`, }, { in: `foo
bar`, expected: `foo
bar`, }, } for ii, test := range tests { out := p.Sanitize(test.in) if out != test.expected { t.Errorf( "test %d failed;\ninput : %s\noutput : %s\nexpected: %s", ii, test.in, out, test.expected, ) } } } func TestDataUri(t *testing.T) { p := UGCPolicy() p.AllowURLSchemeWithCustomPolicy( "data", func(url *url.URL) (allowUrl bool) { // Allows PNG images only const prefix = "image/png;base64," if !strings.HasPrefix(url.Opaque, prefix) { return false } if _, err := base64.StdEncoding.DecodeString(url.Opaque[len(prefix):]); err != nil { return false } if url.RawQuery != "" || url.Fragment != "" { return false } return true }, ) tests := []test{ { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, } for ii, test := range tests { out := p.Sanitize(test.in) if out != test.expected { t.Errorf( "test %d failed;\ninput : %s\noutput : %s\nexpected: %s", ii, test.in, out, test.expected, ) } } } func TestAntiSamy(t *testing.T) { standardUrls := regexp.MustCompile(`(?i)^https?|mailto`) p := NewPolicy() p.AllowElements( "a", "b", "br", "div", "font", "i", "img", "input", "li", "ol", "p", "span", "td", "ul", ) p.AllowAttrs("checked", "type").OnElements("input") p.AllowAttrs("color").OnElements("font") p.AllowAttrs("href").Matching(standardUrls).OnElements("a") p.AllowAttrs("src").Matching(standardUrls).OnElements("img") p.AllowAttrs("class", "id", "title").Globally() p.AllowAttrs("char").Matching( regexp.MustCompile(`p{L}`), // Single character or HTML entity only ).OnElements("td") tests := []test{ // Base64 strings // // first string is //
click here { in: `PGEgLSBocmVmPSJodHRwOi8vd3d3Lm93YXNwLm9yZyI+Y2xpY2sgaGVyZTwvYT4=`, expected: `PGEgLSBocmVmPSJodHRwOi8vd3d3Lm93YXNwLm9yZyI+Y2xpY2sgaGVyZTwvYT4=`, }, // the rest are randomly generated 300 byte sequences which generate // parser errors, turned into Strings { in: `uz0sEy5aDiok6oufQRaYPyYOxbtlACRnfrOnUVIbOstiaoB95iw+dJYuO5sI9nudhRtSYLANlcdgO0pRb+65qKDwZ5o6GJRMWv4YajZk+7Q3W/GN295XmyWUpxuyPGVi7d5fhmtYaYNW6vxyKK1Wjn9IEhIrfvNNjtEF90vlERnz3wde4WMaKMeciqgDXuZHEApYmUcu6Wbx4Q6WcNDqohAN/qCli74tvC+Umy0ZsQGU7E+BvJJ1tLfMcSzYiz7Q15ByZOYrA2aa0wDu0no3gSatjGt6aB4h30D9xUP31LuPGZ2GdWwMfZbFcfRgDSh42JPwa1bODmt5cw0Y8ACeyrIbfk9IkX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9lyTafPLdelG1TKaLFinw1TOjyI6KkrQyHKkttfnO58WFvScl1TiRcB/iHxKahskoE2+VRLUIhctuDU4sUvQh/g9Arw0LAA4QTxuLFt01XYdigurz4FT15ox2oDGGGrRb3VGjDTXK1OWVJoLMW95EVqyMc9F+Fdej85LHE+8WesIfacjUQtTG1tzYVQTfubZq0+qxXws8QrxMLFtVE38tbeXo+Ok1/U5TUa6FjWflEfvKY3XVcl8RKkXua7fVz/Blj8Gh+dWe2cOxa0lpM75ZHyz9adQrB2Pb4571E4u2xI5un0R0MFJZBQuPDc1G5rPhyk+Hb4LRG3dS0m8IASQUOskv93z978L1+Abu9CLP6d6s5p+BzWxhMUqwQXC/CCpTywrkJ0RG`, expected: `C3c+d5Q9lyTafPLdelG1TKaLFinw1TOjyI6KkrQyHKkttfnO58WFvScl1TiRcB/iHxKahskoE2+VRLUIhctuDU4sUvQh/g9Arw0LAA4QTxuLFt01XYdigurz4FT15ox2oDGGGrRb3VGjDTXK1OWVJoLMW95EVqyMc9F+Fdej85LHE+8WesIfacjUQtTG1tzYVQTfubZq0+qxXws8QrxMLFtVE38tbeXo+Ok1/U5TUa6FjWflEfvKY3XVcl8RKkXua7fVz/Blj8Gh+dWe2cOxa0lpM75ZHyz9adQrB2Pb4571E4u2xI5un0R0MFJZBQuPDc1G5rPhyk+Hb4LRG3dS0m8IASQUOskv93z978L1+Abu9CLP6d6s5p+BzWxhMUqwQXC/CCpTywrkJ0RG`, }, // Basic XSS { in: `test`, expected: `test`, }, { in: `<<<><`, expected: ``, }, { in: "", expected: ``, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: `
`, expected: ``, }, { in: `
`, expected: `
`, }, { in: `
`, expected: `
`, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: "", expected: ``, }, { in: ``, expected: ``, }, { in: `PT SRC="http://ha.ckers.org/xss.js">`, expected: `PT SRC="http://ha.ckers.org/xss.js">`, }, { in: `PT SRC="http://ha.ckers.org/xss.js">`, expected: `PT SRC="http://ha.ckers.org/xss.js">`, }, { in: ``, expected: ``, }, { in: "", expected: ``, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: ` +ADw-SCRIPT+AD4-alert('XSS')`, expected: ` +ADw-SCRIPT+AD4-alert('XSS')`, }, { in: ``, expected: ``, }, { in: `alert("XSS")'); ?>`, expected: `alert("XSS")'); ?>`, }, { in: ``, expected: ``, }, { in: ` "> `, expected: "\n\n\n">\n", }, { in: ` `, expected: ` `, }, { in: ` `, expected: ` `, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: `
`, expected: `
`, }, { in: `
`, expected: `
`, }, { in: `
`, expected: `
`, }, { in: `
`, expected: `
`, }, { in: `
`, expected: `
`, }, { in: ``, expected: `
`, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: `
`, expected: `
`, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: `
  • XSS
    `, expected: `
    • XSS
      `, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: ``, expected: ``, }, { in: `\";alert('XSS');//`, expected: `\";alert('XSS');//`, }, { in: `