Skip to content

feat(refacto): get provider endpoint toward clean architecture#767

Merged
leoguillaume merged 8 commits intomainfrom
refacto/get_provider_endpoint
Mar 5, 2026
Merged

feat(refacto): get provider endpoint toward clean architecture#767
leoguillaume merged 8 commits intomainfrom
refacto/get_provider_endpoint

Conversation

@benjaminpilia
Copy link
Copy Markdown
Contributor

No description provided.

@benjaminpilia benjaminpilia force-pushed the refacto/get_provider_endpoint branch from 5c5cb94 to a239066 Compare March 4, 2026 09:49
@benjaminpilia benjaminpilia force-pushed the refacto/get_provider_endpoint branch from a239066 to 57826fa Compare March 4, 2026 09:58
Comment on lines +263 to +271
extra={
"user_id": command.user_id,
"router_id": router_id,
"offset": command.offset,
"limit": command.limit,
"sort_by": command.sort_by,
"sort_order": command.sort_order,
"error_type": type(e).__name__,
},

Check failure

Code scanning / CodeQL

Log Injection High

This log entry depends on a
user-provided value
.

Copilot Autofix

AI 29 days ago

In general, to fix log injection, any user-controlled values included in log messages (either in the main message string or in structured fields such as extra) should be sanitized before logging. Minimal sanitization for plain-text logs is to strip or replace newline (\n) and carriage-return (\r) characters so an attacker cannot split a single log entry into multiple lines or otherwise alter the log structure.

Here, the only tainted value is router_id (coming from the query parameter). The other fields in the extra dict (user_id, offset, limit, sort_by, sort_order) are not directly user-controlled in this snippet or are enums/validated types, and CodeQL has not flagged them. The most targeted, non-invasive fix is therefore:

  • Create a sanitized version of router_id before logging, removing any \r and \n characters.
  • Use that sanitized value in the extra dict.

Since router_id is annotated as int | None, but CodeQL treats it as tainted, it is safest to treat it as possibly string-like when sanitizing. We can:

  • Check if router_id is not None.
  • Convert it to str.
  • Replace \r and \n with empty strings.
  • Use the sanitized string in the log entry.

This change should be made in api/infrastructure/fastapi/endpoints/admin/providers.py inside the get_providers endpoint, in the except block where logger.exception is called. No new imports are needed; basic string methods are sufficient. The runtime behavior of the endpoint (its responses and use case execution) is unchanged; only the representation of router_id in the error log is normalized.

Suggested changeset 1
api/infrastructure/fastapi/endpoints/admin/providers.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/api/infrastructure/fastapi/endpoints/admin/providers.py b/api/infrastructure/fastapi/endpoints/admin/providers.py
--- a/api/infrastructure/fastapi/endpoints/admin/providers.py
+++ b/api/infrastructure/fastapi/endpoints/admin/providers.py
@@ -258,11 +258,14 @@
     try:
         result = await get_providers_use_case.execute(command)
     except Exception as e:
+        sanitized_router_id = None
+        if router_id is not None:
+            sanitized_router_id = str(router_id).replace("\r", "").replace("\n", "")
         logger.exception(
             "Unexpected error while executing get_providers use case",
             extra={
                 "user_id": command.user_id,
-                "router_id": router_id,
+                "router_id": sanitized_router_id,
                 "offset": command.offset,
                 "limit": command.limit,
                 "sort_by": command.sort_by,
EOF
@@ -258,11 +258,14 @@
try:
result = await get_providers_use_case.execute(command)
except Exception as e:
sanitized_router_id = None
if router_id is not None:
sanitized_router_id = str(router_id).replace("\r", "").replace("\n", "")
logger.exception(
"Unexpected error while executing get_providers use case",
extra={
"user_id": command.user_id,
"router_id": router_id,
"router_id": sanitized_router_id,
"offset": command.offset,
"limit": command.limit,
"sort_by": command.sort_by,
Copilot is powered by AI and may make mistakes. Always verify output.
@benjaminpilia benjaminpilia marked this pull request as ready for review March 4, 2026 14:11
@benjaminpilia benjaminpilia changed the title feat(refacto): get router endpoint toward clean architecture feat(refacto): get provider endpoint toward clean architecture Mar 5, 2026
@leoguillaume leoguillaume merged commit 17fc6aa into main Mar 5, 2026
@leoguillaume leoguillaume deleted the refacto/get_provider_endpoint branch March 5, 2026 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[refacto] Refacto GET /v1/admin/providers toward clean architecture

3 participants