Skip to content

Commit

Permalink
Merge pull request #21 from dell/Update-basic-auth-logs
Browse files Browse the repository at this point in the history
logs updated for basic auth
  • Loading branch information
bpjain2004 authored Feb 21, 2022
2 parents c7326c2 + deb435d commit 024f75d
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions api/api_logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"bufio"
"bytes"
"context"
"encoding/base64"
"fmt"
log "github.com/akutz/gournal"
"io"
Expand Down Expand Up @@ -120,25 +121,30 @@ func encryptPassword(buf []byte) []byte {
separator := ""
l = sc.Text()

switch {
case strings.Contains(l, "password"):
match = `"password":"`
separator = `"`
case strings.Contains(l, "Cookie: isisessid="):
match = `isisessid=`
separator = `-`
case strings.Contains(l, "X-Csrf-Token"):
match = `X-Csrf-Token:`
separator = `-`
case strings.Contains(l, "Authorization: Basic"):
match = `Basic `
}
if match != "" {
startIndex, endIndex, matchStrLen := FetchValueIndexForKey(l, match, separator)
if startIndex >= 0 && endIndex > 0 { // if the separator is present then replace only the characters till separator with the special character
l = l[:startIndex+matchStrLen] + "****" + l[startIndex+matchStrLen+endIndex:]
} else if startIndex >= 0 { // if the separator in not present then replace the string to be masked with the special character
l = l[:startIndex+matchStrLen] + "****"
if strings.Contains(l, "Authorization: Basic") {
base64str := strings.Split(l, " ")[2]
decoded, _ := base64.StdEncoding.DecodeString(base64str)
decodedName := strings.Split(string(decoded), ":")[0]
l = "Authorization: " + decodedName + ":******"
} else {
switch {
case strings.Contains(l, "password"):
match = `"password":"`
separator = `"`
case strings.Contains(l, "Cookie: isisessid="):
match = `isisessid=`
separator = `-`
case strings.Contains(l, "X-Csrf-Token"):
match = `X-Csrf-Token:`
separator = `-`
}
if match != "" {
startIndex, endIndex, matchStrLen := FetchValueIndexForKey(l, match, separator)
if startIndex >= 0 && endIndex > 0 { // if the separator is present then replace only the characters till separator with the special character
l = l[:startIndex+matchStrLen] + "****" + l[startIndex+matchStrLen+endIndex:]
} else if startIndex >= 0 { // if the separator in not present then replace the string to be masked with the special character
l = l[:startIndex+matchStrLen] + "****"
}
}
}
fmt.Fprintln(ou, l)
Expand Down

0 comments on commit 024f75d

Please sign in to comment.