Skip to content

Commit

Permalink
Prevent xss injection scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
chakany committed Feb 7, 2024
1 parent 5e156f8 commit 8b8e02a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/routes/[event]/+page.svelte
Expand Up @@ -106,6 +106,10 @@
}
return $nostr.postNewEvent(event)
}
function escapeText(text: string): string {
return value.toString().replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/'/g, "&#39;").replace(/"/g, "&#34;");
}
</script>

<svelte:head>
Expand Down Expand Up @@ -166,7 +170,7 @@
{#if data?.tags.find((t) => t[0] === "filename")[1].endsWith(".md")}
<SvelteMarkdown source={data.content} />
{:else}
<HighlightAuto code={data.content} let:highlighted>
<HighlightAuto code={(() => escapeText(data.content))()} let:highlighted>
<LineNumbers {highlighted} hideBorder wrapLines />
</HighlightAuto>
{/if}
Expand All @@ -180,4 +184,4 @@
</div>
{:catch error}
<span>error</span>
{/await}
{/await}

0 comments on commit 8b8e02a

Please sign in to comment.