Add spam filter middleware to block common attack patterns#570
Add spam filter middleware to block common attack patterns#570adambarito merged 2 commits intomainfrom
Conversation
Blocks requests to .php, wp-content, wp-admin, wp-login, .env, .trash, license.txt, and other common exploit-probing paths with a 418 response. Applied to all app middlewares (bio, cart, link, nyc, vip). https://claude.ai/code/session_01JeXrk5mVcXKjXPsEt9Li2f
Greptile SummaryThis PR introduces a shared Key observations:
Confidence Score: 4/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Incoming Request] --> B{isSpamRequest\npathname}
B -- match found --> C[spamResponse\nHTTP 418]
B -- no match --> D[Normal Middleware Logic\nbio / cart / link / nyc / vip]
D --> E[DB queries / analytics\ncookie handling / routing]
Reviews (1): Last reviewed commit: "feat: add spam filter middleware to bloc..." | Re-trigger Greptile |
| } | ||
|
|
||
| export function spamResponse() { | ||
| return new NextResponse('Nice try. This isn\'t WordPress. Stop fucking with us.', { |
There was a problem hiding this comment.
Profanity in production response body
The response message contains an expletive ("Stop fucking with us."). While this is returned to bots in the vast majority of cases, it can also be triggered by legitimate users who accidentally hit a false positive (e.g., a developer testing a URL that contains .php or .env in the path), and it would show up in browser windows, logs, or monitoring dashboards. A professional but still dismissive message is a better fit.
| return new NextResponse('Nice try. This isn\'t WordPress. Stop fucking with us.', { | |
| return new NextResponse("Nice try. This isn't WordPress.", { |
| export function isSpamRequest(pathname: string): boolean { | ||
| const lower = pathname.toLowerCase(); | ||
| return SPAM_PATTERNS.some(pattern => lower.includes(pattern)); | ||
| } |
There was a problem hiding this comment.
No logging for blocked requests
When a spam request is blocked, nothing is logged. Adding a log line here would let you monitor attack frequency and patterns over time, and verify the filter is working as expected in production. The log utility is already imported in the consuming middlewares, or it could be imported directly here:
| export function isSpamRequest(pathname: string): boolean { | |
| const lower = pathname.toLowerCase(); | |
| return SPAM_PATTERNS.some(pattern => lower.includes(pattern)); | |
| } | |
| export function isSpamRequest(pathname: string): boolean { | |
| const lower = pathname.toLowerCase(); | |
| const matched = SPAM_PATTERNS.find(pattern => lower.includes(pattern)); | |
| if (matched) console.log(`[spam-filter] blocked "${pathname}" (matched: ${matched})`); | |
| return !!matched; | |
| } |
apps
db
|
- Change response message to "Nice try. Pls go away." - Log blocked requests with matched pattern for observability https://claude.ai/code/session_01JeXrk5mVcXKjXPsEt9Li2f
|
The latest updates on your projects. Learn more about Vercel for GitHub. 14 Skipped Deployments
|
apps
db
|
Summary
This PR introduces a spam filter middleware that blocks requests matching common attack patterns, particularly WordPress-related probes and other malicious requests.
Key Changes
New spam filter module (
packages/lib/src/middleware/spam-filter.ts):isSpamRequest()function that detects requests containing common spam/attack patterns (WordPress paths, PHP files, environment files, etc.)spamResponse()function that returns a 418 I'm a teapot response with a humorous messagepackages/lib/package.jsonfor use across applicationsIntegrated spam filter into all middleware:
apps/bio/src/middleware.tsapps/cart/src/middleware.tsapps/link/src/middleware.tsapps/nyc/src/middleware.tsapps/vip/src/middleware.tsImplementation Details
.php,license.txt,wp-*paths,xmlrpc,.trash, and.envhttps://claude.ai/code/session_01JeXrk5mVcXKjXPsEt9Li2f