Skip to content

feat: start v0.5 foundations#22

Merged
typelicious merged 2 commits into
mainfrom
codex/feature/v0.5-foundations-2026-03-12
Mar 12, 2026
Merged

feat: start v0.5 foundations#22
typelicious merged 2 commits into
mainfrom
codex/feature/v0.5-foundations-2026-03-12

Conversation

@typelicious
Copy link
Copy Markdown
Collaborator

No description provided.

@github-advanced-security
Copy link
Copy Markdown

You are seeing this message because GitHub Code Scanning has recently been set up for this repository, or this pull request contains the workflow file for the Code Scanning tool.

What Enabling Code Scanning Means:

  • The 'Security' tab will display more code scanning analysis results (e.g., for the default branch).
  • Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results.
  • You will be able to see the analysis results for the pull request's branch on this overview once the scans have completed and the checks have passed.

For more information about GitHub Code Scanning, check out the documentation.

Comment thread foundrygate/main.py
effective_body,
) = await _resolve_image_route_preview(body, headers)
except HookExecutionError as exc:
return JSONResponse({"error": str(exc), "type": "request_hook_error"}, status_code=500)

Check warning

Code scanning / CodeQL

Information exposure through an exception Medium

Stack trace information
flows to this location and may be exposed to an external user.

Copilot Autofix

AI 3 months ago

In general, the fix is to avoid returning raw exception messages to the client. Instead, log the detailed error (including stack trace) on the server and return a generic, non-sensitive message plus a stable error type/code to the client. This preserves debuggability while preventing information exposure.

Concretely for foundrygate/main.py:

  • In the image_generations endpoint, update the except HookExecutionError as exc: handler.
  • Before returning, log the exception with logger.exception(...) (which records the stack trace) or logger.error(..., exc_info=True).
  • Change the JSON response to use a generic message like "Request hook execution failed" instead of str(exc). Keep the "type": "request_hook_error" field so existing clients that key off the type are unaffected.
  • No new imports are needed; logger is already defined.

Only the lines inside that except HookExecutionError block (around 580–583) need to change.

Suggested changeset 1
foundrygate/main.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/foundrygate/main.py b/foundrygate/main.py
--- a/foundrygate/main.py
+++ b/foundrygate/main.py
@@ -578,7 +578,11 @@
             effective_body,
         ) = await _resolve_image_route_preview(body, headers)
     except HookExecutionError as exc:
-        return JSONResponse({"error": str(exc), "type": "request_hook_error"}, status_code=500)
+        logger.exception("Request hook execution failed")
+        return JSONResponse(
+            {"error": "Request hook execution failed", "type": "request_hook_error"},
+            status_code=500,
+        )
     except ValueError as exc:
         return JSONResponse({"error": str(exc), "type": "invalid_request_error"}, status_code=400)
 
EOF
@@ -578,7 +578,11 @@
effective_body,
) = await _resolve_image_route_preview(body, headers)
except HookExecutionError as exc:
return JSONResponse({"error": str(exc), "type": "request_hook_error"}, status_code=500)
logger.exception("Request hook execution failed")
return JSONResponse(
{"error": "Request hook execution failed", "type": "request_hook_error"},
status_code=500,
)
except ValueError as exc:
return JSONResponse({"error": str(exc), "type": "invalid_request_error"}, status_code=400)

Copilot is powered by AI and may make mistakes. Always verify output.
Comment thread foundrygate/main.py
except HookExecutionError as exc:
return JSONResponse({"error": str(exc), "type": "request_hook_error"}, status_code=500)
except ValueError as exc:
return JSONResponse({"error": str(exc), "type": "invalid_request_error"}, status_code=400)

Check warning

Code scanning / CodeQL

Information exposure through an exception Medium

Stack trace information
flows to this location and may be exposed to an external user.

Copilot Autofix

AI 3 months ago

In general, to fix information exposure via exceptions, avoid returning raw exception messages or stack traces to clients. Instead, log detailed information on the server and respond with a generic, user-safe error message and optionally a stable error code. This preserves debuggability while preventing attackers from learning about internal state or implementation details.

For this specific case in foundrygate/main.py, we should change the except ValueError as exc: block in the image_generations endpoint so it no longer includes str(exc) in the JSON returned to the client. The safest approach without changing external behavior too much is:

  • Log the exception (including its message and/or stack trace) using the existing logger.
  • Return a generic message like "Invalid request" (or similar) along with the existing "type": "invalid_request_error" field, so clients can still programmatically detect the error type.

Concretely:

  • In foundrygate/main.py, locate the except ValueError as exc: block around line 582.
  • Add a logging call, for example logger.warning("Invalid image generation request: %s", exc) (or logger.exception if stack trace logging is desired).
  • Replace the JSON body so that it uses a fixed string (e.g., "Invalid request") instead of str(exc).

No additional imports are required because logger is already defined at the top of the file via logging.getLogger("foundrygate").

Suggested changeset 1
foundrygate/main.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/foundrygate/main.py b/foundrygate/main.py
--- a/foundrygate/main.py
+++ b/foundrygate/main.py
@@ -580,7 +580,8 @@
     except HookExecutionError as exc:
         return JSONResponse({"error": str(exc), "type": "request_hook_error"}, status_code=500)
     except ValueError as exc:
-        return JSONResponse({"error": str(exc), "type": "invalid_request_error"}, status_code=400)
+        logger.warning("Invalid image generation request: %s", exc)
+        return JSONResponse({"error": "Invalid request", "type": "invalid_request_error"}, status_code=400)
 
     prompt = effective_body["prompt"].strip()
     image_fields = _collect_image_request_fields(effective_body)
EOF
@@ -580,7 +580,8 @@
except HookExecutionError as exc:
return JSONResponse({"error": str(exc), "type": "request_hook_error"}, status_code=500)
except ValueError as exc:
return JSONResponse({"error": str(exc), "type": "invalid_request_error"}, status_code=400)
logger.warning("Invalid image generation request: %s", exc)
return JSONResponse({"error": "Invalid request", "type": "invalid_request_error"}, status_code=400)

prompt = effective_body["prompt"].strip()
image_fields = _collect_image_request_fields(effective_body)
Copilot is powered by AI and may make mistakes. Always verify output.
@typelicious typelicious merged commit 4e106c7 into main Mar 12, 2026
10 checks passed
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.

2 participants