mirror of
https://github.com/pezkuwichain/pwap.git
synced 2026-07-27 13:35:40 +00:00
fix(web): repair 6 dead internal links + harden forum markdown against stored XSS
Routing: footer "Explorer"/"Validators" pointed to non-existent /network (4 spots in AppLayout + LandingPageDesktop) and Explorer/Forum quick-links pointed to bare /governance (no route) -> all hit the 404 catch-all. Repointed to /explorer and /governance/assembly; footer "Vote" /-> /elections. Security (stored XSS): DiscussionThread.parseMarkdown did regex->HTML then dangerouslySetInnerHTML with no escaping/sanitizer, so <img onerror>/javascript: links in user comments executed. Now escape HTML first, then DOMPurify-sanitize the output to a safe tag/attr allow-list with http(s)-only hrefs.
This commit is contained in:
@@ -9,6 +9,7 @@ import { useTranslation } from 'react-i18next';
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '@/components/ui/dropdown-menu';
|
||||
import { useWebSocket } from '@/contexts/WebSocketContext';
|
||||
import { useToast } from '@/hooks/use-toast';
|
||||
import DOMPurify from 'dompurify';
|
||||
|
||||
interface Comment {
|
||||
id: string;
|
||||
@@ -329,8 +330,18 @@ export function DiscussionThread({ proposalId }: { proposalId: string }) {
|
||||
</div>
|
||||
);
|
||||
|
||||
// SECURITY: user-supplied comment content. Escape all HTML FIRST so raw markup
|
||||
// (e.g. <img src=x onerror=...>) becomes inert text, THEN apply the markdown
|
||||
// transforms, THEN run the result through DOMPurify restricted to a safe tag/attr
|
||||
// allow-list with http(s)-only hrefs. This blocks stored XSS (script/onerror/
|
||||
// javascript: URLs) while keeping basic markdown rendering.
|
||||
const parseMarkdown = (text: string): string => {
|
||||
return text
|
||||
const escaped = (text || '')
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"');
|
||||
const html = escaped
|
||||
.replace(/^### (.*$)/gim, '<h3>$1</h3>')
|
||||
.replace(/^## (.*$)/gim, '<h2>$1</h2>')
|
||||
.replace(/^# (.*$)/gim, '<h1>$1</h1>')
|
||||
@@ -339,6 +350,11 @@ export function DiscussionThread({ proposalId }: { proposalId: string }) {
|
||||
.replace(/\[([^\]]+)\]\(([^)]+)\)/gim, '<a href="$2" class="text-blue-600 hover:underline">$1</a>')
|
||||
.replace(/^> (.*$)/gim, '<blockquote class="border-l-4 border-gray-300 pl-4 italic">$1</blockquote>')
|
||||
.replace(/\n/gim, '<br>');
|
||||
return DOMPurify.sanitize(html, {
|
||||
ALLOWED_TAGS: ['h1', 'h2', 'h3', 'strong', 'em', 'a', 'blockquote', 'br', 'p'],
|
||||
ALLOWED_ATTR: ['href', 'class'],
|
||||
ALLOWED_URI_REGEXP: /^https?:\/\//i,
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user