Skip to content

Commit

Permalink
frontend: disable escaping of special HTML chars for BGPMap graph
Browse files Browse the repository at this point in the history
  • Loading branch information
xddxdd committed Jul 2, 2024
1 parent f0f072c commit 0dd1c07
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions frontend/bgpmap_graph.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"bytes"
"encoding/json"
"fmt"
"strings"
Expand Down Expand Up @@ -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())
}
}

Expand Down
2 changes: 1 addition & 1 deletion frontend/bgpmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 0dd1c07

Please sign in to comment.