Skip to content

Limit how often a visitor may send a storefront form or upload a file - #1113

Merged
KrzysztofPajak merged 2 commits into
developfrom
fix/storefront-form-rate-limit
Nov 24, 2026
Merged

KrzysztofPajak merged 2 commits into
developfrom
fix/storefront-form-rate-limit

Conversation

@KrzysztofPajak

@KrzysztofPajak KrzysztofPajak commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

The only rate limit in the storefront was the guest-order link page. The forms that mail the store or keep what a visitor sent (contact us, contact a vendor, e-mail a friend, ask a question, product and vendor reviews, blog and news comments, newsletter, password recovery) relied on the optional captcha alone, and the three attribute uploads (product, checkout, contact) store every file in the database with no limit on how many a guest sends. A script could flood the store's mailbox, fill the review queue, or fill the database with uploads.

Changes

  • New rate limiter policy StorefrontForm in GrandCommonStartup: 10 posts in 10 minutes per IP address and per form; the next post in the window gets the existing 429 answer ("Too many requests. Please try again later.").
  • The POST of each form and upload listed above names the policy.
  • Both limits, this one and the guest-order page's, are read from the Security section of appsettings: StorefrontFormRateLimitPermits / StorefrontFormRateLimitWindowMinutes (10 / 10) and GuestOrderRateLimitPermits / GuestOrderRateLimitWindowMinutes (5 / 10). A missing key keeps the default; 0 turns a limit off.

Notes

  • Counted per form, so a customer writing reviews for several products is not stopped by the contact message they sent before; each product's reviews and each upload action count as one form.
  • Behind a proxy or load balancer, the address is the proxy's unless UseForwardedHeaders is on, as for the guest-order page already.
  • The limiter is kept in memory per instance, like the existing policy.
  • A separate default size for attribute uploads is not added: the storefront already ships MaxRequestBodySize 10 MB, which bounds one upload; what was open was the number of uploads, which this limit covers.

Tests

  • RateLimitPartitionTests (new): the configured number of posts passes and the next one is refused; a zero limit or window turns the limit off.
  • StorefrontFormRateLimitTests (new): each of the 13 form and upload POSTs names StorefrontForm.
  • Grand.Web.Tests (668) pass.

Copilot AI balanced review requested due to automatic review settings November 23, 2026 17:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

The guest-order and storefront form limits (permits and window) move to the Security section, with the previous values as defaults; 0 turns a limit off.
@KrzysztofPajak
KrzysztofPajak merged commit b15b9f0 into develop Nov 24, 2026
9 checks passed
@KrzysztofPajak
KrzysztofPajak deleted the fix/storefront-form-rate-limit branch November 24, 2026 15:28
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