Skip to content

fix(moderation): resolve false positive regex triggers in spam detection for code snippets and markdown links #1381

Description

@Pcmhacker-hero

Description

The automated spam detection filter in frontend/src/lib/validation/spamDetection.ts and backend/app/core/moderation_terms.py uses overly aggressive regex matching for URL counting and keyword analysis. When developers share legitimate markdown code snippets (e.g. http.ListenAndServe(':8080', nil) or documentation links), posts and comments are falsely blocked as spam.

Steps to Reproduce

  1. Create a project update post containing a code snippet with 3 HTTP import statements and 2 GitHub repo links.
  2. Click 'Publish Update'.
  3. The submission is rejected with 'Spam detected: excessive link count and suspicious keywords'.

Expected Behavior

  • Frontend/Backend: Strip Markdown code blocks (...) and inline code ticks (...) before running spam keyword and link density analysis.
  • Backend: Whitelist trusted developer domains (e.g. github.com, npmjs.com, docs.python.org, stackoverflow.com).

Implementation Hints

Frontend (frontend/src/lib/validation/spamDetection.ts):

export function sanitizeForSpamCheck(content: string): string {
  return content
    .replace(/```[\s\S]*?```/g, "")
    .replace(/`[^`]*`/g, "")
    .trim();
}

export function detectSpam(rawContent: string): boolean {
  const sanitized = sanitizeForSpamCheck(rawContent);
  const links = sanitized.match(/https?:\/\/[^\s]+/gi) || [];
  const untrustedLinks = links.filter(link => !isTrustedDeveloperDomain(link));
  return untrustedLinks.length > 3;
}

Affected Files

  • frontend/src/lib/validation/spamDetection.ts
  • backend/app/core/moderation_terms.py
  • backend/app/routers/moderation.py

Labels
type:bug, level:intermediate, GSSoC-26

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions