File size: 1,443 Bytes
0dd2082
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const BLOCKED_PATTERNS = [
    /hack/i, /exploit/i, /steal/i, /phish/i, /crack\s*password/i,
    /porn/i, /xxx/i, /nsfw/i, /18\+/i, /adult\s*content/i,
    /drug\s*dealer/i, /buy\s*drugs/i, /illegal/i, /counterfeit/i,
    /doxx/i, /stalk/i, /spy\s*on/i, /track\s*someone/i,
    /bomb/i, /weapon/i, /gun\s*shop\s*illegal/i,
    /scrape\s*facebook/i, /scrape\s*instagram/i, /scrape\s*private/i,
];

const BLOCKED_TARGETS = [
    'facebook.com', 'instagram.com', 'twitter.com',
    'linkedin.com', 'bank', 'government',
];

function validate(query) {
    const lower = query.toLowerCase().trim();

    if (!lower || lower.length < 3) {
        return { safe: false, reason: 'Query too short or empty.' };
    }

    if (lower.length > 500) {
        return { safe: false, reason: 'Query exceeds maximum length.' };
    }

    for (const pattern of BLOCKED_PATTERNS) {
        if (pattern.test(lower)) {
            return {
                safe: false,
                reason: 'Query blocked by safety filter. This platform does not support harmful, illegal, or adult content searches.',
            };
        }
    }

    for (const target of BLOCKED_TARGETS) {
        if (lower.includes(target)) {
            return {
                safe: false,
                reason: `Scraping ${target} is not allowed. Please use publicly available sources.`,
            };
        }
    }

    return { safe: true };
}

module.exports = { validate };