Skip to content

Commit 62455e1

Browse files
committed
Sanitize principals
1 parent c8beac0 commit 62455e1

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

helper/sanitizer.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,9 @@ import "strings"
55
func Sanitize(s string) string {
66
return strings.Replace(s, "\n", "", -1)
77
}
8+
9+
func SanitizeStringSlice(ss []string) {
10+
for i, x := range ss {
11+
ss[i] = Sanitize(x)
12+
}
13+
}

helper/sanitizer_test.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package helper
22

3-
import "testing"
3+
import (
4+
"reflect"
5+
"strings"
6+
"testing"
7+
)
48

59
func TestSanitize(t *testing.T) {
610
ours := "abc"
@@ -19,3 +23,25 @@ func TestSanitizeWithNoNewLines(t *testing.T) {
1923
t.Errorf("Got %s but wanted %s", theirs, ours)
2024
}
2125
}
26+
27+
func TestSliceSanitize(t *testing.T) {
28+
ours := strings.Split("abc aaa def", " ")
29+
30+
theirs := strings.Split("abc aaa\n def\n\n", " ")
31+
SanitizeStringSlice(theirs)
32+
33+
if !reflect.DeepEqual(ours, theirs) {
34+
t.Errorf("Got %v but wanted %v", theirs, ours)
35+
}
36+
}
37+
38+
func TestSliceWithNoNewLinesSanitize(t *testing.T) {
39+
ours := strings.Split("abc aaa def", " ")
40+
41+
theirs := strings.Split("abc aaa def", " ")
42+
SanitizeStringSlice(theirs)
43+
44+
if !reflect.DeepEqual(ours, theirs) {
45+
t.Errorf("Got %v but wanted %v", theirs, ours)
46+
}
47+
}

server/handlers.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ func AuthenticationHandler(next http.Handler) http.Handler {
4747
hasValidPrincipals := CheckPrincipals(user.Principals, signRequest.Principals)
4848

4949
if !hasValidPrincipals {
50+
// Sanitize the principals for logging
51+
helper.SanitizeStringSlice(signRequest.Principals)
5052
authorisationFailed(w, "One or more unauthorised principals requested %v", signRequest.Principals)
5153
}
5254

0 commit comments

Comments
 (0)