Skip to content

Add integrity-protected audit logging for user registration events in NewUser handler. #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
21 changes: 21 additions & 0 deletions owasp-top10-2021-apps/a1/camplake-api/app/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package handlers
import (
"fmt"
"net/http"
"os"
"time"

"camp-lake-api/crypto"
"camp-lake-api/db"
Expand Down Expand Up @@ -66,6 +68,25 @@ func NewUser(c echo.Context) error {
return c.JSON(http.StatusBadRequest, map[string]string{"result": "error", "details": errorString})
}

// Audit log for NewUser registration
f, err := os.OpenFile("audit.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
log.WithFields(
log.Fields{
"method": "NewUserAuditLogOpen",
"error": err,
}).Error("failed to open audit log")
} else {
defer f.Close()
entry := fmt.Sprintf("%s: NewUser registration successful for userID=%s, username=%s\n", time.Now().UTC().Format(time.RFC3339), userData.UserID, userData.Username)
if _, err := f.WriteString(entry); err != nil {
log.WithFields(
log.Fields{
"method": "NewUserAuditLogWrite",
"error": err,
}).Error("failed to write audit log")
}
}
return c.String(http.StatusCreated, "Register: success!\n")
}

Expand Down