Files
nobat724_front/lib/sanitize.js
T
hamed b04bb45ca1 Implement multi-domain SEO improvements:
- Add metadata to login and login-verify pages to prevent indexing.
- Update robots.txt to disallow additional sensitive paths.
- Enhance sitemap generation to filter by city and include accurate last modified dates.
- Refactor canonical URL generation to support multi-domain architecture, ensuring self-canonicalization for city domains.
- Remove deprecated CanonicalHandler component and streamline canonical URL handling.
- Introduce safe JSON-LD output to prevent XSS vulnerabilities.
- Add payment layout with appropriate metadata to prevent indexing.
- Conduct a comprehensive technical SEO audit and implement necessary fixes across the application.
2026-07-05 15:47:47 +03:30

30 lines
877 B
JavaScript

import DOMPurify from "isomorphic-dompurify";
export function sanitizeHtml(html) {
if (!html || typeof html !== "string") return "";
return DOMPurify.sanitize(html, {
ALLOWED_TAGS: [
"p", "br", "strong", "em", "b", "i", "u", "ul", "ol", "li", "a",
"h2", "h3", "h4", "h5", "blockquote", "img", "span", "div",
"table", "thead", "tbody", "tr", "td", "th",
],
ALLOWED_ATTR: ["href", "target", "rel", "src", "alt", "title"],
ALLOW_DATA_ATTR: false,
});
}
// خروجی امن برای <script type="application/ld+json"> — جلوگیری از بستن تگ با داده‌ی کاربر
export function safeJsonLd(obj) {
return JSON.stringify(obj).replace(/</g, "\\u003c");
}
export function safeJsonParse(str, fallback = null) {
if (!str) return fallback;
try {
return JSON.parse(str);
} catch {
return fallback;
}
}