feat: duplicate content detection middleware (spam mitigation)#79
Open
wolframs wants to merge 2 commits intomoltbook:mainfrom
Open
feat: duplicate content detection middleware (spam mitigation)#79wolframs wants to merge 2 commits intomoltbook:mainfrom
wolframs wants to merge 2 commits intomoltbook:mainfrom
Conversation
Adds spamDetection.js middleware that blocks identical content submissions: - Same agent posting identical content within 24h -> blocked - Different agents posting identical comments within 1h -> blocked (catches coordinated bot farms like FinallyOffline/-53k karma) - Cross-agent posts allowed (legitimate cross-posting to submolts) - Content < 20 chars skipped (greetings, emoji reactions) Uses SHA-256 hash of normalized content (lowercase, collapsed whitespace) with in-memory storage, following the same pattern as rateLimit.js. Wired into POST /posts and POST /posts/:id/comments routes, after existing rate limiters. Refs moltbook#76 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
rel770
reviewed
Feb 3, 2026
rel770
left a comment
There was a problem hiding this comment.
Review: Duplicate Content Detection Middleware
Great work on addressing spam! This is exactly the kind of infrastructure the platform needs.
Strengths:
- ✅ SHA-256 hashing with normalization (case, whitespace) - solid approach
- ✅ Different windows for same-agent (24h) vs cross-agent (1h) - good balance
- ✅ Short content exemption (<20 chars) - prevents false positives on reactions
- ✅ Tests included (6 new tests)
- ✅ Uses existing error classes for consistency
Suggestions:
- Consider adding a configurable threshold for the minimum content length (currently hardcoded at 20)
- The periodic cleanup interval should be documented in config
- Consider logging blocked duplicates for moderation review
Security Note:
The cross-agent duplicate detection for comments is smart - catches bot farms posting identical templates. Nice catch on the real-world examples (FinallyOffline, ClawdBot farm).
Human-AI Review Note:
This review was conducted by copilotariel (Claude Opus 4.5) in collaboration with human partner Ariel. We've been reviewing moltbook PRs as part of our open source contribution effort.
Looking forward to seeing this merged! 🦞
— copilotariel (github.com/copilotariel/humanai-community)
…gging - Make minContentLength configurable via config/env (default: 20) - Add all spam detection config to config/index.js with documentation - Log blocked duplicates with [spam] prefix for moderation visibility - Export _MIN_CONTENT_LENGTH for testing Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds spamDetection.js middleware that detects and blocks duplicate content submissions. This addresses the most impactful item from #76 -- content hashing to catch identical spam.
What it does
What it catches today
Observed on the live platform:
Implementation
Tests
6 new tests added to test/api.test.js:
All 21 tests pass (15 existing + 6 new).
What this does not cover (future work from #76)
Refs #76