Skip to content
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

Do not log contents of body for /user/ paths #1111

Merged
merged 1 commit into from
Jul 23, 2024
Merged
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
11 changes: 8 additions & 3 deletions core/web/webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@

app.include_router(api_router, prefix="/api/v2")

LOGGING_EXCLUDELIST = [
"/auth/",
LOGGING_EXCLUDELIST = ["/auth/"]
LOGGING_SENSITIVE_BODY = [
"/users/",
]
LOG_BODY_SIZE_LIMIT = 2000
CONTENT_TOO_LARGE_MESSAGE = f"[Request body > {LOG_BODY_SIZE_LIMIT} bytes, not logged]"
Expand All @@ -112,7 +113,6 @@
@app.middleware("http")
async def log_requests(request: Request, call_next):
req_body = await request.body()

response = await call_next(request)
# Do not log auth-related requests
for path in LOGGING_EXCLUDELIST:
Expand All @@ -138,6 +138,11 @@ async def log_requests(request: Request, call_next):
extra["body"] = CONTENT_TOO_LARGE_MESSAGE.encode("utf-8")
else:
extra["body"] = req_body

for path in LOGGING_SENSITIVE_BODY:
if path in request.url.path:
extra["body"] = b""

if response.status_code == 200:
logger.info("Authorized request", extra=extra)
elif response.status_code == 401:
Expand Down
Loading