Skip to content

Fix subscribe endpoint when subscribers are disabled#4601

Open
Misrilal-Sah wants to merge 1 commit intocachethq:developfrom
Misrilal-Sah:pr/4515-block-subscribe-endpoint
Open

Fix subscribe endpoint when subscribers are disabled#4601
Misrilal-Sah wants to merge 1 commit intocachethq:developfrom
Misrilal-Sah:pr/4515-block-subscribe-endpoint

Conversation

@Misrilal-Sah
Copy link
Copy Markdown

Issue link id: #4515
Description:
This change prevents direct access to subscription creation when email notifications are disabled in settings.
Previously, the subscribe page button was hidden but posting directly to the subscribe endpoint could still create subscriptions.
The fix adds a defensive check in SubscribeController for both subscribe page rendering and subscribe submission, redirecting to the status page when subscribers are disabled.

Copilot AI review requested due to automatic review settings March 31, 2026 18:36
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a defensive server-side guard to prevent subscription creation and subscribe page access when email subscribers are disabled in settings, addressing direct POSTs to the subscribe endpoint.

Changes:

  • Added subscribers_enabled() checks to redirect to the status page from showSubscribe() when subscribers are disabled.
  • Added the same guard to postSubscribe() to block direct subscription creation when subscribers are disabled.
  • Removed an unused $subscriptions = Binput::get('subscriptions'); assignment in postSubscribe().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +48 to +50
if (!subscribers_enabled()) {
return Redirect::route('status-page');
}
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The subscribe routes are already protected by the subscribers route middleware, which performs the same !subscribers_enabled() redirect (see app/Http/Routes/SubscribeRoutes.php:32 and app/Http/Middleware/SubscribersConfigured.php:28-34). Duplicating the gate here in the controller adds a second source of truth that can drift; consider relying on the middleware (or, if the middleware isn’t reliably applied in some deployments, fix the routing/middleware configuration instead of duplicating the check).

Copilot uses AI. Check for mistakes.
Comment on lines 46 to +50
public function showSubscribe()
{
if (!subscribers_enabled()) {
return Redirect::route('status-page');
}
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

showSubscribe() can now return a redirect when subscribers are disabled, but the PHPDoc still declares @return \\Illuminate\\View\\View. Please update the docblock return type to reflect that this method may return a redirect response as well.

Copilot uses AI. Check for mistakes.
Comment on lines 61 to +65
public function postSubscribe()
{
if (!subscribers_enabled()) {
return Redirect::route('status-page');
}
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

postSubscribe() returns a redirect response in all paths (including the new disabled-subscribers guard), but its PHPDoc declares @return \\Illuminate\\View\\View. Update the docblock return type to match the actual response type(s).

Copilot uses AI. Check for mistakes.
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