"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files
Go azure-blobazure-blob-storageazure-filesbackblaze-b2cloud-storagedropboxencryptionftpfuse-filesystemgogolanggoogle-cloud-storagegoogle-driveonedriveopenstack-swiftrclones3sftpsyncwebdav
Remove `Authorization:` headers from `--dump-headers` output
Nick Craig-Wood318e335137eb
diff --git a/docs/content/docs.md b/docs/content/docs.mdindex 2a6112b29..d9d29905b 100644--- a/docs/content/docs.md+++ b/docs/content/docs.md@@ -543,6 +543,13 @@ here which are used for testing. These start with remote name egWrite CPU profile to file. This can be analysed with `go tool pprof`.+### --dump-auth ###++Dump HTTP headers - will contain sensitive info such as+`Authorization:` headers - use `--dump-headers` to dump without+`Authorization:` headers. Can be very verbose. Useful for debugging+only.+### --dump-bodies ###Dump HTTP headers and bodies - may contain sensitive info. Can be@@ -555,8 +562,11 @@ and exclude options are filtering on.### --dump-headers ###-Dump HTTP headers - may contain sensitive info. Can be very verbose.-Useful for debugging only.+Dump HTTP headers with `Authorization:` lines removed. May still+contain sensitive info. Can be very verbose. Useful for debugging+only.++Use `--dump-auth` if you do want the `Authorization:` headers.### --memprofile=FILE ###diff --git a/fs/config.go b/fs/config.goindex 5d9610813..89556f23e 100644--- a/fs/config.go+++ b/fs/config.go@@ -76,6 +76,7 @@ var (timeout = pflag.DurationP("timeout", "", 5*60*time.Second, "IO idle timeout")dumpHeaders = pflag.BoolP("dump-headers", "", false, "Dump HTTP headers - may contain sensitive info")dumpBodies = pflag.BoolP("dump-bodies", "", false, "Dump HTTP headers and bodies - may contain sensitive info")+ dumpAuth = pflag.BoolP("dump-auth", "", false, "Dump HTTP headers with auth info")skipVerify = pflag.BoolP("no-check-certificate", "", false, "Do not verify the server SSL certificate. Insecure.")AskPassword = pflag.BoolP("ask-password", "", true, "Allow prompt for password for encrypted configuration.")deleteBefore = pflag.BoolP("delete-before", "", false, "When synchronizing, delete files on destination before transfering")@@ -287,6 +288,7 @@ type ConfigInfo struct {Timeout time.Duration // Data channel timeoutDumpHeaders boolDumpBodies bool+ DumpAuth boolFilter *FilterInsecureSkipVerify bool // Skip server certificate verificationDeleteBefore bool // Delete before checking@@ -341,6 +343,7 @@ func LoadConfig() {Config.IgnoreExisting = *ignoreExistingConfig.DumpHeaders = *dumpHeadersConfig.DumpBodies = *dumpBodies+ Config.DumpAuth = *dumpAuthConfig.InsecureSkipVerify = *skipVerifyConfig.LowLevelRetries = *lowLevelRetriesConfig.UpdateOlder = *updateOlderdiff --git a/fs/http.go b/fs/http.goindex accd9f41f..c6734c9f2 100644--- a/fs/http.go+++ b/fs/http.go@@ -3,6 +3,7 @@package fsimport (+ "bytes""crypto/tls""net""net/http"@@ -112,7 +113,7 @@ func (ci *ConfigInfo) Transport() http.RoundTripper {// t.ExpectContinueTimeoutci.initTransport(t)// Wrap that http.Transport in our own transport- transport = NewTransport(t, ci.DumpHeaders, ci.DumpBodies)+ transport = NewTransport(t, ci.DumpHeaders, ci.DumpBodies, ci.DumpAuth)})return transport}@@ -131,15 +132,17 @@ type Transport struct {*http.TransportlogHeader boollogBody bool+ logAuth bool}// NewTransport wraps the http.Transport passed in and logs all// roundtrips including the body if logBody is set.-func NewTransport(transport *http.Transport, logHeader, logBody bool) *Transport {+func NewTransport(transport *http.Transport, logHeader, logBody, logAuth bool) *Transport {return &Transport{Transport: transport,logHeader: logHeader,logBody: logBody,+ logAuth: logAuth,}}@@ -180,13 +183,48 @@ func checkServerTime(req *http.Request, resp *http.Response) {checkedHostMu.Unlock()}+var authBuf = []byte("Authorization: ")++// cleanAuth gets rid of one Authorization: header within the first 4k+func cleanAuth(buf []byte) []byte {+ // Find how much buffer to check+ n := 4096+ if len(buf) < n {+ n = len(buf)+ }+ // See if there is an Authorization: header+ i := bytes.Index(buf[:n], authBuf)+ if i < 0 {+ return buf+ }+ i += len(authBuf)+ // Overwrite the next 4 chars with 'X'+ for j := 0; i < len(buf) && j < 4; j++ {+ if buf[i] == '\n' {+ break+ }+ buf[i] = 'X'+ i+++ }+ // Snip out to the next '\n'+ j := bytes.IndexByte(buf[i:], '\n')+ if j < 0 {+ return buf[:i]+ }+ n = copy(buf[i:], buf[i+j:])+ return buf[:i+n]+}+// RoundTrip implements the RoundTripper interface.func (t *Transport) RoundTrip(req *http.Request) (resp *http.Response, err error) {// Force user agentreq.Header.Set("User-Agent", UserAgent)// Log request- if t.logHeader || t.logBody {+ if t.logHeader || t.logBody || t.logAuth {buf, _ := httputil.DumpRequestOut(req, t.logBody)+ if !t.logAuth {+ buf = cleanAuth(buf)+ }Debug(nil, "%s", separatorReq)Debug(nil, "%s (req %p)", "HTTP REQUEST", req)Debug(nil, "%s", string(buf))@@ -195,7 +233,7 @@ func (t *Transport) RoundTrip(req *http.Request) (resp *http.Response, err error// Do round tripresp, err = t.Transport.RoundTrip(req)// Log response- if t.logHeader || t.logBody {+ if t.logHeader || t.logBody || t.logAuth {Debug(nil, "%s", separatorResp)Debug(nil, "%s (req %p)", "HTTP RESPONSE", req)if err != nil {diff --git a/fs/http_test.go b/fs/http_test.goindex b5b8e7837..a1e2c55f3 100644--- a/fs/http_test.go+++ b/fs/http_test.go@@ -38,3 +38,27 @@ func TestSetDefaults(t *testing.T) {assert.Equal(t, old.TLSNextProto, new.TLSNextProto, "when checking .TLSNextProto")assert.Equal(t, old.MaxResponseHeaderBytes, new.MaxResponseHeaderBytes, "when checking .MaxResponseHeaderBytes")}++func TestCleanAuth(t *testing.T) {+ for _, test := range []struct {+ in string+ want string+ }{+ {"", ""},+ {"floo", "floo"},+ {"Authorization: ", "Authorization: "},+ {"Authorization: \n", "Authorization: \n"},+ {"Authorization: A", "Authorization: X"},+ {"Authorization: A\n", "Authorization: X\n"},+ {"Authorization: AAAA", "Authorization: XXXX"},+ {"Authorization: AAAA\n", "Authorization: XXXX\n"},+ {"Authorization: AAAAA", "Authorization: XXXX"},+ {"Authorization: AAAAA\n", "Authorization: XXXX\n"},+ {"Authorization: AAAA\n", "Authorization: XXXX\n"},+ {"Authorization: AAAAAAAAA\nPotato: Help\n", "Authorization: XXXX\nPotato: Help\n"},+ {"Sausage: 1\nAuthorization: AAAAAAAAA\nPotato: Help\n", "Sausage: 1\nAuthorization: XXXX\nPotato: Help\n"},+ } {+ got := string(cleanAuth([]byte(test.in)))+ assert.Equal(t, test.want, got, test.in)+ }+}