Skip to content

Commit

Permalink
Merge pull request #27 from kitos9112/dev-msoutullo/logEntriesSanitasion
Browse files Browse the repository at this point in the history
fix: add log sanatization entries
  • Loading branch information
kitos9112 authored May 15, 2022
2 parents ebb25a2 + 2b9cb9f commit 87c060e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
15 changes: 6 additions & 9 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
# required for all workflows
security-events: write
# only required for workflows in private repositories
actions: read
contents: read

strategy:
fail-fast: false
Expand All @@ -31,15 +37,6 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
# We must fetch at least the immediate parents so that if this is
# a pull request then we can checkout the head.
fetch-depth: 2

# If this run was triggered by a pull request event, then checkout
# the head of the pull request instead of the merge commit.
- run: git checkout HEAD^2
if: ${{ github.event_name == 'pull_request' }}

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
Expand Down
22 changes: 12 additions & 10 deletions internal/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ func (s *Server) AuthHandler(providerName, rule string) http.HandlerFunc {
// Validate user
valid := ValidateEmail(email, rule)
if !valid {
logger.WithField("email", email).Warn("Invalid email")
escapedEmail := strings.Replace(email, "\n", "", -1)
escapedEmail = strings.Replace(escapedEmail, "\r", "", -1)
logger.WithField("email", escapedEmail).Warn("Invalid email")
// The email address isn't valid so display an error and clear the cookie
// Clearing the cookie will allow the user to try another email address and avoid being trapped on 'Not authorized'
http.SetCookie(w, ClearCookie(r))
Expand Down Expand Up @@ -145,7 +147,7 @@ func (s *Server) AuthCallbackHandler() http.HandlerFunc {
target, err := url.Parse(r.Form.Get("target"))
matched, _ := regexp.MatchString(`^$`, target.Hostname())
if err == nil && matched {
logger.Debug("Incoming request from", target, "is legit")
logger.Debug("Incoming request from", strings.Replace(target.String(), "\n", "", -1), "is legit")
} else {
logger.Error("Invalid target")
}
Expand Down Expand Up @@ -263,20 +265,20 @@ func (s *Server) authRedirect(logger *logrus.Entry, w http.ResponseWriter, r *ht

logger.WithFields(logrus.Fields{
"csrf_cookie": csrf,
"login_url": loginURL,
"login_url": strings.Replace(loginURL, "\n", "", -1),
}).Debug("Set CSRF cookie and redirected to provider login url")
}

func (s *Server) logger(r *http.Request, handler, rule, msg string) *logrus.Entry {
// Create logger
logger := log.WithFields(logrus.Fields{
"handler": handler,
"rule": rule,
"method": r.Header.Get("X-Forwarded-Method"),
"proto": r.Header.Get("X-Forwarded-Proto"),
"host": r.Header.Get("X-Forwarded-Host"),
"uri": r.Header.Get("X-Forwarded-Uri"),
"source_ip": r.Header.Get("X-Forwarded-For"),
"handler": strings.Replace(handler, "\n", "", -1),
"rule": strings.Replace(rule, "\n", "", -1),
"method": strings.Replace(r.Header.Get("X-Forwarded-Method"), "\n", "", -1),
"proto": strings.Replace(r.Header.Get("X-Forwarded-Proto"), "\n", "", -1),
"host": strings.Replace(r.Header.Get("X-Forwarded-Host"), "\n", "", -1),
"uri": strings.Replace(r.Header.Get("X-Forwarded-Uri"), "\n", "", -1),
"source_ip": strings.Replace(r.Header.Get("X-Forwarded-For"), "\n", "", -1),
})

// Log request
Expand Down

0 comments on commit 87c060e

Please sign in to comment.