Skip to content

Conversation

@xavdid-stripe
Copy link
Member

Why?

The hosted docs were a little late merging, so I wanted to make sure they got linked in the changelog. Plus I added the fully-working example from the original PR to the actual code. I also took the opportunity to make sure the hosted docs matched these working examples.

What?

  • add new example
  • update changelog

See Also

@xavdid-stripe xavdid-stripe requested a review from a team as a code owner December 16, 2025 22:50
@xavdid-stripe xavdid-stripe requested review from jar-stripe and removed request for a team December 16, 2025 22:50
@xavdid-stripe xavdid-stripe enabled auto-merge (squash) December 16, 2025 22:52
handler.handle(webhook_body, sig_header)
return jsonify(success=True), 200
except Exception as e:
return jsonify(error=str(e)), 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 10 days ago

To fix the information exposure, we should avoid returning internal error messages or exception details (like str(e)) to API clients. Instead, log the actual exception—including the traceback if desired—using server-side logging (for example, using Python's standard logging module), and return a generic error message to the client.
The fix requires:

  • Importing logging at the top of the file if not already present.
  • Optionally configuring the logger if desired, or just using the root logger.
  • In the exception handler, log the full exception and traceback using logging.exception() (or similar).
  • Return a generic message in the response, such as "An internal error has occurred.", rather than user-facing exception details.

The code to change is in the exception handler in the webhook() function, specifically on lines 54–55. Logging should be done inside the except block, before returning the generic message.

Suggested changeset 1
examples/event_notification_handler_endpoint.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/examples/event_notification_handler_endpoint.py b/examples/event_notification_handler_endpoint.py
--- a/examples/event_notification_handler_endpoint.py
+++ b/examples/event_notification_handler_endpoint.py
@@ -11,7 +11,7 @@
 
 import os
 from flask import Flask, request, jsonify
-
+import logging
 from stripe import StripeClient, UnhandledNotificationDetails
 from stripe.v2.core import EventNotification
 from stripe.events import V1BillingMeterErrorReportTriggeredEventNotification
@@ -52,4 +52,5 @@
         handler.handle(webhook_body, sig_header)
         return jsonify(success=True), 200
     except Exception as e:
-        return jsonify(error=str(e)), 500
+        logging.exception("Exception occurred while handling webhook")
+        return jsonify(error="An internal error has occurred."), 500
EOF
@@ -11,7 +11,7 @@

import os
from flask import Flask, request, jsonify

import logging
from stripe import StripeClient, UnhandledNotificationDetails
from stripe.v2.core import EventNotification
from stripe.events import V1BillingMeterErrorReportTriggeredEventNotification
@@ -52,4 +52,5 @@
handler.handle(webhook_body, sig_header)
return jsonify(success=True), 200
except Exception as e:
return jsonify(error=str(e)), 500
logging.exception("Exception occurred while handling webhook")
return jsonify(error="An internal error has occurred."), 500
Copilot is powered by AI and may make mistakes. Always verify output.
@xavdid-stripe xavdid-stripe merged commit d587365 into beta Dec 16, 2025
20 checks passed
@xavdid-stripe xavdid-stripe deleted the update-handler-docs branch December 16, 2025 23:43
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.

4 participants