frontend: disable escaping of special HTML chars for BGPMap graph
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -69,11 +70,15 @@ func (graph *RouteGraph) attrsToString(attrs RouteAttrs) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (graph *RouteGraph) escape(s string) string {
|
func (graph *RouteGraph) escape(s string) string {
|
||||||
result, err := json.Marshal(s)
|
buffer := &bytes.Buffer{}
|
||||||
|
encoder := json.NewEncoder(buffer)
|
||||||
|
encoder.SetEscapeHTML(false)
|
||||||
|
err := encoder.Encode(s)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err.Error()
|
return err.Error()
|
||||||
} else {
|
} else {
|
||||||
return string(result)
|
return string(buffer.Bytes())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ func TestBirdRouteToGraphvizXSS(t *testing.T) {
|
|||||||
fakeResult,
|
fakeResult,
|
||||||
}, fakeResult)
|
}, fakeResult)
|
||||||
|
|
||||||
if strings.Contains(result, "<script>") {
|
if strings.Contains(result, fakeResult) {
|
||||||
t.Errorf("XSS injection succeeded: %s", result)
|
t.Errorf("XSS injection succeeded: %s", result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user