fix(security): remediate audit vulnerabilities SEC-001 through SEC-023
Deploy Canina / deploy (push) Successful in 2m25s
E2E Playwright Tests / Run Full E2E & Security Suites (push) Failing after 7s

This commit is contained in:
parsa committed 2026-09-23 23:00:25 +03:30
1 parent dc88677169
commit bd49fbc4a0
31 files changed
+867 -114

No files matched your search

+2 -1
View File
@@ -151,7 +151,8 @@ export class ApiKeysService {
.catch(() => {});
const scopes = key.scopes.split(',').map((s) => s.trim().toLowerCase());
const hasAdminScope = scopes.includes('*') || scopes.includes('admin') || scopes.includes('all');
// SEC-016: Disallow wildcard '*' from granting admin role; require explicit 'admin' scope
const hasAdminScope = scopes.includes('admin');
return {
id: key.id,
+5 -1
View File
@@ -51,7 +51,11 @@ export class MediaService {
}
const uniqueSuffix = Date.now() + '-' + Math.round(Math.random() * 1e9);
const ext = path.extname(originalname);
const ext = path.extname(originalname).toLowerCase();
const ALLOWED_EXTENSIONS = ['.jpg', '.jpeg', '.png', '.webp', '.gif', '.pdf'];
if (!ALLOWED_EXTENSIONS.includes(ext)) {
throw new BadRequestException('پسوند فایل ارسالی مجاز نیست (فرمت SVG و فایل‌های اجرایی مسدود هستند).');
}
const filename = `${uniqueSuffix}${ext}`;
const filePath = path.join(uploadDir, filename);
+21 -1
View File
@@ -179,7 +179,27 @@ export class SslService {
const cleanDomain = domain
.replace(/^https?:\/\//, '')
.replace(/\/.*$/, '')
.trim();
.trim()
.toLowerCase();
// SEC-009: Strict domain validation preventing SSRF
const DOMAIN_REGEX = /^(?!-)[a-zA-Z0-9-]{1,63}(?<!-)(\.[a-zA-Z0-9-]{1,63})*\.[a-zA-Z]{2,}$/;
const IP_REGEX = /^(?:\d{1,3}\.){3}\d{1,3}$|^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$/;
if (
!cleanDomain ||
!DOMAIN_REGEX.test(cleanDomain) ||
IP_REGEX.test(cleanDomain) ||
cleanDomain === 'localhost' ||
cleanDomain.endsWith('.local') ||
cleanDomain.endsWith('.internal')
) {
return resolve({
onlineCheck: false,
error: 'فرمت نام دامنه نامعتبر است یا آدرس‌های IP و داخلی مجاز نیستند.',
});
}
const socket = tls.connect(
{
host: cleanDomain,