Update server.js
Browse files
server.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
const express = require('express');
|
| 2 |
const { collect } = require('@themarkup/blacklight-collector');
|
| 3 |
-
// استيراد المكتبة بشكل صحيح
|
| 4 |
const SecureCheck = require('securecheck');
|
| 5 |
const path = require('path');
|
| 6 |
|
|
@@ -22,30 +21,18 @@ function normalizeUrl(inputUrl) {
|
|
| 22 |
}
|
| 23 |
}
|
| 24 |
|
| 25 |
-
// دالة لحساب درجة الخصوصية (A+ إلى F)
|
| 26 |
function calculatePrivacyGrade(blacklight, securecheck) {
|
| 27 |
let score = 100;
|
| 28 |
-
|
| 29 |
-
// خصم على المتتبعين
|
| 30 |
const trackerCount = blacklight?.hosts?.thirdParty?.length || 0;
|
| 31 |
score -= Math.min(trackerCount * 5, 40);
|
| 32 |
-
|
| 33 |
-
// خصم على البصمة الرقمية
|
| 34 |
const hasFingerprinting = (blacklight?.canvasFingerprinters?.length > 0) ||
|
| 35 |
(blacklight?.canvasFontFingerprinters?.length > 0);
|
| 36 |
if (hasFingerprinting) score -= 25;
|
| 37 |
-
|
| 38 |
-
// خصم على تسجيل الجلسات وضغط المفاتيح
|
| 39 |
if (blacklight?.sessionRecorders?.length > 0) score -= 15;
|
| 40 |
if (blacklight?.keyLogging?.length > 0) score -= 20;
|
| 41 |
-
|
| 42 |
-
// خصم على SSL غير صالح
|
| 43 |
if (!securecheck?.ssl?.valid) score -= 20;
|
| 44 |
-
|
| 45 |
-
// خصم على هيدرات الأمان المفقودة
|
| 46 |
if (!securecheck?.headers?.strictTransportSecurity) score -= 5;
|
| 47 |
if (!securecheck?.headers?.contentSecurityPolicy) score -= 5;
|
| 48 |
-
|
| 49 |
score = Math.max(0, Math.min(100, Math.round(score)));
|
| 50 |
|
| 51 |
let grade;
|
|
@@ -55,43 +42,30 @@ function calculatePrivacyGrade(blacklight, securecheck) {
|
|
| 55 |
else if (score >= 65) grade = 'C';
|
| 56 |
else if (score >= 55) grade = 'D';
|
| 57 |
else grade = 'F';
|
| 58 |
-
|
| 59 |
return { score, grade };
|
| 60 |
}
|
| 61 |
|
| 62 |
app.post('/scan', async (req, res) => {
|
| 63 |
const { url: inputUrl, mode } = req.body;
|
| 64 |
-
|
| 65 |
-
if (!inputUrl) {
|
| 66 |
-
return res.status(400).json({ success: false, error: 'URL is required' });
|
| 67 |
-
}
|
| 68 |
|
| 69 |
const url = normalizeUrl(inputUrl);
|
| 70 |
-
if (!url) {
|
| 71 |
-
return res.status(400).json({ success: false, error: 'Invalid URL format' });
|
| 72 |
-
}
|
| 73 |
|
| 74 |
console.log(`🔍 Scanning: ${url} (Mode: ${mode || 'deep'})`);
|
| 75 |
|
| 76 |
try {
|
| 77 |
const isDeep = mode === 'deep';
|
| 78 |
-
|
| 79 |
const allTests = [
|
| 80 |
-
'cookies',
|
| 81 |
-
'
|
| 82 |
-
'
|
| 83 |
-
'
|
| 84 |
-
'canvas_font_fingerprinters',
|
| 85 |
-
'key_logging',
|
| 86 |
-
'session_recorders',
|
| 87 |
-
'google_analytics',
|
| 88 |
-
'twitter_pixel',
|
| 89 |
-
'tiktok_pixel'
|
| 90 |
];
|
| 91 |
|
| 92 |
-
// إعدادات
|
| 93 |
-
const
|
| 94 |
-
blTests: allTests,
|
| 95 |
numPages: isDeep ? 2 : 1,
|
| 96 |
defaultWaitUntil: isDeep ? 'networkidle2' : 'domcontentloaded',
|
| 97 |
captureHar: isDeep,
|
|
@@ -109,104 +83,66 @@ app.post('/scan', async (req, res) => {
|
|
| 109 |
]
|
| 110 |
};
|
| 111 |
|
| 112 |
-
// تشغيل الفحصين بشكل متوازٍ
|
| 113 |
const [blacklightResult, secureCheckResult] = await Promise.all([
|
| 114 |
-
collect(url,
|
| 115 |
-
|
| 116 |
-
return { error: err.message };
|
| 117 |
-
}),
|
| 118 |
-
new SecureCheck(url).scan().catch(err => {
|
| 119 |
-
console.error('SecureCheck error:', err.message);
|
| 120 |
-
return { error: err.message };
|
| 121 |
-
})
|
| 122 |
]);
|
| 123 |
|
| 124 |
-
|
|
|
|
|
|
|
| 125 |
|
| 126 |
-
|
| 127 |
-
const thirdPartyDomains = blacklightResult.hosts?.thirdParty || [];
|
| 128 |
const trackerCount = thirdPartyDomains.length;
|
| 129 |
-
const cookiesCount =
|
| 130 |
-
const thirdPartyCookies =
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
const
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
advice = '✅ هذا الموقع يحترم خصوصيتك بشكل ممتاز.';
|
| 143 |
-
} else if (grade === 'B' || grade === 'C') {
|
| 144 |
-
advice = '⚠️ هذا الموقع به بعض المخاوف المتعلقة بالخصوصية.';
|
| 145 |
-
} else if (grade === 'D') {
|
| 146 |
-
advice = '🔴 هذا الموقع يستخدم العديد من المتتبعين. كن حذرًا.';
|
| 147 |
-
} else {
|
| 148 |
-
advice = '⛔️ هذا الموقع ينتهك خصوصيتك بشكل خطير. تجنب مشاركة أي معلومات حساسة.';
|
| 149 |
-
}
|
| 150 |
|
| 151 |
const summary = {
|
| 152 |
-
url:
|
| 153 |
-
final_url:
|
| 154 |
-
grade
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
},
|
| 161 |
-
cookies: {
|
| 162 |
-
total: cookiesCount,
|
| 163 |
-
third_party: thirdPartyCookies
|
| 164 |
-
},
|
| 165 |
-
fingerprinting: {
|
| 166 |
-
detected: hasFingerprinting
|
| 167 |
-
},
|
| 168 |
-
session_recording: {
|
| 169 |
-
detected: hasSessionRecording
|
| 170 |
-
},
|
| 171 |
-
key_logging: {
|
| 172 |
-
detected: hasKeyLogging
|
| 173 |
-
},
|
| 174 |
ssl: {
|
| 175 |
-
valid:
|
| 176 |
-
issuer:
|
| 177 |
-
expires_in_days:
|
| 178 |
-
grade:
|
| 179 |
},
|
| 180 |
security_headers: {
|
| 181 |
-
hsts: !!
|
| 182 |
-
csp: !!
|
| 183 |
-
x_frame_options:
|
| 184 |
},
|
| 185 |
-
advice
|
| 186 |
};
|
| 187 |
|
| 188 |
res.json({
|
| 189 |
success: true,
|
| 190 |
-
summary
|
| 191 |
-
details: {
|
| 192 |
-
blacklight: blacklightResult,
|
| 193 |
-
securecheck: secureCheckResult
|
| 194 |
-
}
|
| 195 |
});
|
| 196 |
-
|
| 197 |
} catch (error) {
|
| 198 |
console.error('Scan error:', error);
|
| 199 |
-
res.status(500).json({
|
| 200 |
-
success: false,
|
| 201 |
-
error: error.message
|
| 202 |
-
});
|
| 203 |
}
|
| 204 |
});
|
| 205 |
|
| 206 |
-
app.get('/', (req, res) =>
|
| 207 |
-
res.sendFile(path.join(__dirname, 'public', 'index.html'));
|
| 208 |
-
});
|
| 209 |
|
| 210 |
-
app.listen(PORT, '0.0.0.0', () => {
|
| 211 |
-
console.log(`🚀 PrivacyScan v2.0 running on port ${PORT}`);
|
| 212 |
-
});
|
|
|
|
| 1 |
const express = require('express');
|
| 2 |
const { collect } = require('@themarkup/blacklight-collector');
|
|
|
|
| 3 |
const SecureCheck = require('securecheck');
|
| 4 |
const path = require('path');
|
| 5 |
|
|
|
|
| 21 |
}
|
| 22 |
}
|
| 23 |
|
|
|
|
| 24 |
function calculatePrivacyGrade(blacklight, securecheck) {
|
| 25 |
let score = 100;
|
|
|
|
|
|
|
| 26 |
const trackerCount = blacklight?.hosts?.thirdParty?.length || 0;
|
| 27 |
score -= Math.min(trackerCount * 5, 40);
|
|
|
|
|
|
|
| 28 |
const hasFingerprinting = (blacklight?.canvasFingerprinters?.length > 0) ||
|
| 29 |
(blacklight?.canvasFontFingerprinters?.length > 0);
|
| 30 |
if (hasFingerprinting) score -= 25;
|
|
|
|
|
|
|
| 31 |
if (blacklight?.sessionRecorders?.length > 0) score -= 15;
|
| 32 |
if (blacklight?.keyLogging?.length > 0) score -= 20;
|
|
|
|
|
|
|
| 33 |
if (!securecheck?.ssl?.valid) score -= 20;
|
|
|
|
|
|
|
| 34 |
if (!securecheck?.headers?.strictTransportSecurity) score -= 5;
|
| 35 |
if (!securecheck?.headers?.contentSecurityPolicy) score -= 5;
|
|
|
|
| 36 |
score = Math.max(0, Math.min(100, Math.round(score)));
|
| 37 |
|
| 38 |
let grade;
|
|
|
|
| 42 |
else if (score >= 65) grade = 'C';
|
| 43 |
else if (score >= 55) grade = 'D';
|
| 44 |
else grade = 'F';
|
|
|
|
| 45 |
return { score, grade };
|
| 46 |
}
|
| 47 |
|
| 48 |
app.post('/scan', async (req, res) => {
|
| 49 |
const { url: inputUrl, mode } = req.body;
|
| 50 |
+
if (!inputUrl) return res.status(400).json({ success: false, error: 'URL is required' });
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
const url = normalizeUrl(inputUrl);
|
| 53 |
+
if (!url) return res.status(400).json({ success: false, error: 'Invalid URL format' });
|
|
|
|
|
|
|
| 54 |
|
| 55 |
console.log(`🔍 Scanning: ${url} (Mode: ${mode || 'deep'})`);
|
| 56 |
|
| 57 |
try {
|
| 58 |
const isDeep = mode === 'deep';
|
|
|
|
| 59 |
const allTests = [
|
| 60 |
+
'cookies', 'third_party_trackers', 'fb_pixel_events',
|
| 61 |
+
'canvas_fingerprinters', 'canvas_font_fingerprinters',
|
| 62 |
+
'key_logging', 'session_recorders', 'google_analytics',
|
| 63 |
+
'twitter_pixel', 'tiktok_pixel'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
];
|
| 65 |
|
| 66 |
+
// الإعدادات الأصلية التي كانت تعمل بنجاح
|
| 67 |
+
const blacklightOptions = {
|
| 68 |
+
blTests: isDeep ? allTests : ['cookies', 'third_party_trackers', 'fb_pixel_events'],
|
| 69 |
numPages: isDeep ? 2 : 1,
|
| 70 |
defaultWaitUntil: isDeep ? 'networkidle2' : 'domcontentloaded',
|
| 71 |
captureHar: isDeep,
|
|
|
|
| 83 |
]
|
| 84 |
};
|
| 85 |
|
|
|
|
| 86 |
const [blacklightResult, secureCheckResult] = await Promise.all([
|
| 87 |
+
collect(url, blacklightOptions).catch(err => ({ error: err.message })),
|
| 88 |
+
new SecureCheck(url).scan().catch(err => ({ error: err.message }))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
]);
|
| 90 |
|
| 91 |
+
// تجنب الأخطاء إذا فشل Blacklight
|
| 92 |
+
const blacklight = blacklightResult.error ? { hosts: {} } : blacklightResult;
|
| 93 |
+
const securecheck = secureCheckResult.error ? { ssl: {}, headers: {} } : secureCheckResult;
|
| 94 |
|
| 95 |
+
const thirdPartyDomains = blacklight.hosts?.thirdParty || [];
|
|
|
|
| 96 |
const trackerCount = thirdPartyDomains.length;
|
| 97 |
+
const cookiesCount = blacklight.cookies?.length || 0;
|
| 98 |
+
const thirdPartyCookies = blacklight.cookies?.filter(c => c.thirdParty)?.length || 0;
|
| 99 |
+
const hasFingerprinting = (blacklight.canvasFingerprinters?.length > 0) ||
|
| 100 |
+
(blacklight.canvasFontFingerprinters?.length > 0);
|
| 101 |
+
const hasSessionRecording = blacklight.sessionRecorders?.length > 0;
|
| 102 |
+
const hasKeyLogging = blacklight.keyLogging?.length > 0;
|
| 103 |
+
|
| 104 |
+
const { score, grade } = calculatePrivacyGrade(blacklight, securecheck);
|
| 105 |
+
|
| 106 |
+
const advice = grade === 'A+' || grade === 'A' ? '✅ هذا الموقع يحترم خصوصيتك بشكل ممتاز.' :
|
| 107 |
+
grade === 'B' || grade === 'C' ? '⚠️ هذا الموقع به بعض المخاوف المتعلقة بالخصوصية.' :
|
| 108 |
+
grade === 'D' ? '🔴 هذا الموقع يستخدم العديد من المتتبعين. كن حذرًا.' :
|
| 109 |
+
'⛔️ هذا الموقع ينتهك خصوصيتك بشكل خطير. تجنب مشاركة أي معلومات حساسة.';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
|
| 111 |
const summary = {
|
| 112 |
+
url: blacklight.url || url,
|
| 113 |
+
final_url: blacklight.uri_dest || url,
|
| 114 |
+
grade, score,
|
| 115 |
+
scan_time_sec: blacklight.scanTime || 0,
|
| 116 |
+
trackers: { count: trackerCount, top_domains: thirdPartyDomains.slice(0, 5) },
|
| 117 |
+
cookies: { total: cookiesCount, third_party: thirdPartyCookies },
|
| 118 |
+
fingerprinting: { detected: hasFingerprinting },
|
| 119 |
+
session_recording: { detected: hasSessionRecording },
|
| 120 |
+
key_logging: { detected: hasKeyLogging },
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
ssl: {
|
| 122 |
+
valid: securecheck?.ssl?.valid || false,
|
| 123 |
+
issuer: securecheck?.ssl?.issuer || 'Unknown',
|
| 124 |
+
expires_in_days: securecheck?.ssl?.daysRemaining || 0,
|
| 125 |
+
grade: securecheck?.ssl?.grade || 'N/A'
|
| 126 |
},
|
| 127 |
security_headers: {
|
| 128 |
+
hsts: !!securecheck?.headers?.strictTransportSecurity,
|
| 129 |
+
csp: !!securecheck?.headers?.contentSecurityPolicy,
|
| 130 |
+
x_frame_options: securecheck?.headers?.xFrameOptions || 'Missing'
|
| 131 |
},
|
| 132 |
+
advice
|
| 133 |
};
|
| 134 |
|
| 135 |
res.json({
|
| 136 |
success: true,
|
| 137 |
+
summary,
|
| 138 |
+
details: { blacklight: blacklightResult, securecheck: secureCheckResult }
|
|
|
|
|
|
|
|
|
|
| 139 |
});
|
|
|
|
| 140 |
} catch (error) {
|
| 141 |
console.error('Scan error:', error);
|
| 142 |
+
res.status(500).json({ success: false, error: error.message });
|
|
|
|
|
|
|
|
|
|
| 143 |
}
|
| 144 |
});
|
| 145 |
|
| 146 |
+
app.get('/', (req, res) => res.sendFile(path.join(__dirname, 'public', 'index.html')));
|
|
|
|
|
|
|
| 147 |
|
| 148 |
+
app.listen(PORT, '0.0.0.0', () => console.log(`🚀 PrivacyScan v2.0 running on port ${PORT}`));
|
|
|
|
|
|