feat(logging): add NanoShare wide event instrumentation
Build and Push Docker Container / build-and-push (push) Failing after 51s

- Register quart_common wide-event logging during app setup so every HTTP request emits one canonical structured event.

- Replace the inline security middleware with reusable quart_common security middleware wiring and move skip path configuration into app constants.

- Add NanoShare-specific wide-event context for health checks, auth/error handlers, file list/edit/delete/serve flows and upload outcomes.

- Rename runtime logging/project metadata from simple-picoshare to nanoshare where it is emitted in service context.

- Update my_helpers and quart_common submodules for Convex/wide-event integration and reusable security middleware support.

- Add NanoShare middleware tests covering safe user context, client IP enrichment, missing Convex handling and Convex security lookup failures.
This commit is contained in:
2026-05-13 20:22:43 +02:00
parent 26536a3cde
commit 9c731d6e67
12 changed files with 208 additions and 40 deletions
+9
View File
@@ -12,6 +12,7 @@ from my_modules.functions import (
get_request_context,
)
from quart_common.web.env import is_development_environment
from quart_common.web.wide_event import add_wide_event_context
IGNORED_404_PATHS = [
"/.well-known/",
@@ -64,6 +65,7 @@ async def auth_error(message:str, status_code:int=400):
'Authentication failed. Please try again or contact an administrator.'
)
add_wide_event_context(auth={"operation_status": "error"}, error={"type": "AuthenticationError", "message": message})
logger.error(f"[AUTH:{status_code}] {message}")
if context and context.path.startswith("/api"):
@@ -78,6 +80,7 @@ async def auth_error(message:str, status_code:int=400):
@app.errorhandler(401)
async def handle_unauthorized(e):
context = get_request_context()
add_wide_event_context(auth={"operation_status": "unauthorized"}, error={"type": type(e).__name__, "message": str(e)})
if context.path.startswith("/api"):
return jsonify({"error": "Unauthorized Access", "message": "Gandalf has spoken: You shall not pass… until you log in."}), 401
@@ -109,6 +112,7 @@ async def not_found(e):
path=context.path, status=404
)
add_wide_event_context(error={"type": "NotFound", "message": str(e)})
logger.error(f"[404] Page Not Found: {context.path}")
if context.path.startswith("/api"):
@@ -131,6 +135,7 @@ async def maybe_a_hacker(e=None):
method=request.method,
path=request.path,
)
add_wide_event_context(security={"blocked": True, "block_reason": "honeypot_rate_limit"})
logger.warning(f"[HONEYPOT] Blocked {client_ip} after accessing {request.path}")
return await to_many_requests(e)
@@ -140,6 +145,7 @@ async def maybe_a_hacker(e=None):
file={'name': 'hacker_crap.webp', 'alt': "Someone got Hacked and he says I hate this Hacker crap - Jurassic Park Movie"},
)
add_wide_event_context(security={"blocked": True, "block_reason": "honeypot"})
response = await make_response((rendered, 418))
response.headers['X-Honeypot-Triggered'] = 'true'
response.headers['X-Reason'] = 'Unauthorized access attempt'
@@ -151,6 +157,7 @@ async def to_many_requests(e):
message = "We love your enthusiasm, but our server thought it was being DDoSed… by you. The keyboard needs a new set of keys and we need a nap. Try again soon!"
context = get_request_context()
add_wide_event_context(rate_limit={"limited": True}, error={"type": type(e).__name__, "message": str(e)})
if context.path.startswith("/api") or context.path.endswith('/auth/userinfo') or context.path.endswith('/auth/refresh'):
return jsonify({"error": "Too Many Requests - YOU SHALL NOT PASS (for now)", "message": message}), 429
@@ -168,6 +175,7 @@ async def internal_server_error(e):
return await to_many_requests(e)
context = get_request_context()
add_wide_event_context(error={"type": type(e).__name__, "message": str(e)})
if context.path.startswith("/api"):
return jsonify({"error": "Internal Server Error", "message": "It looks like you broke something... but don't worry, we're fixing it! In the meantime, we may or may not have logged your IP address (just kidding... or are we?). Either way, thanks for helping us find new ways to crash our system. Stay curious, hacker-friend!"}), 500
@@ -185,6 +193,7 @@ async def database_server_error(e):
except LookupError as e:
return await to_many_requests(e)
add_wide_event_context(error={"type": type(e).__name__, "message": str(e)})
logger.error(e)
return await render_template('views/basics/error.htm',
title='Database Error',