mirror of
https://github.com/xddxdd/bird-lg-go
synced 2025-02-16 10:34:27 +01:00
frontend: disable escaping of special HTML chars for BGPMap graph
This commit is contained in:
parent
f0f072c4a6
commit
0dd1c07b66
@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
@ -69,11 +70,15 @@ func (graph *RouteGraph) attrsToString(attrs RouteAttrs) 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 {
|
||||
return err.Error()
|
||||
} else {
|
||||
return string(result)
|
||||
return string(buffer.Bytes())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ func TestBirdRouteToGraphvizXSS(t *testing.T) {
|
||||
fakeResult,
|
||||
}, fakeResult)
|
||||
|
||||
if strings.Contains(result, "<script>") {
|
||||
if strings.Contains(result, fakeResult) {
|
||||
t.Errorf("XSS injection succeeded: %s", result)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user