Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

hide more headers #77

Merged
merged 1 commit into from
Feb 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions pkg/awsutil/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ import (
log "github.com/sirupsen/logrus"
)

var REAuthHeader = regexp.MustCompile(`(?m:^(Auth[^:]*):.*$)`)
var (
RESecretHeader = regexp.MustCompile(`(?m:^([^:]*(Auth|Security)[^:]*):.*$)`)
)

func HideSecureHeaders(dump []byte) []byte {
return RESecretHeader.ReplaceAll(dump, []byte("$1: <hidden>"))
}

func DumpRequest(r *http.Request) string {
dump, err := httputil.DumpRequest(r, true)
Expand All @@ -21,7 +27,7 @@ func DumpRequest(r *http.Request) string {
}

dump = bytes.TrimSpace(dump)
dump = REAuthHeader.ReplaceAll(dump, []byte("$1: <hidden>"))
dump = HideSecureHeaders(dump)
dump = util.IndentBytes(dump, []byte(" > "))
return string(dump)
}
Expand Down
36 changes: 36 additions & 0 deletions pkg/awsutil/util_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package awsutil_test

import (
"fmt"
"testing"

"github.com/rebuy-de/aws-nuke/pkg/awsutil"
)

func TestSecretRegex(t *testing.T) {
cases := []struct{ in, out string }{
{
in: "GET / HTTP/1.1\nAuthorization: Never gonna give you up\nHost: bish",
out: "GET / HTTP/1.1\nAuthorization: <hidden>\nHost: bish",
},
{
in: "GET / HTTP/1.1\nX-Amz-Security-Token: Never gonna let you down\nHost: bash",
out: "GET / HTTP/1.1\nX-Amz-Security-Token: <hidden>\nHost: bash",
},
{
in: "GET / HTTP/1.1\nX-Amz-Security-Token: Never gonna run around and desert you\nAuthorization: Never gonna make you cry",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok. weird. 😉

out: "GET / HTTP/1.1\nX-Amz-Security-Token: <hidden>\nAuthorization: <hidden>",
},
}

for i, tc := range cases {
t.Run(fmt.Sprint(i), func(t *testing.T) {
want := tc.out
have := string(awsutil.HideSecureHeaders([]byte(tc.in)))

if want != have {
t.Errorf("Assertion failed. Want: %#v. Have: %#v", want, have)
}
})
}
}