Skip to content

Commit 281851f

Browse files
author
Thilo Hohlt
authored
Merge pull request #34 from archtika/devel
Escape user input <ins> and <del> elements in logs
2 parents 0c15769 + 5a62148 commit 281851f

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

web-app/src/routes/(authenticated)/website/[websiteId]/logs/+page.server.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,18 @@ export const actions: Actions = {
8080

8181
const htmlDiff = (oldValue: string, newValue: string) => {
8282
const diff = dmp.diff_main(oldValue, newValue);
83-
dmp.diff_cleanupSemantic(diff);
8483

8584
return diff
8685
.map(([op, text]) => {
86+
const escapedText = text.replace(/</g, "&lt;").replace(/>/g, "&gt;");
87+
8788
switch (op) {
8889
case 1:
89-
return `<ins>${text}</ins>`;
90+
return `<ins>${escapedText}</ins>`;
9091
case -1:
91-
return `<del>${text}</del>`;
92+
return `<del>${escapedText}</del>`;
9293
default:
93-
return text;
94+
return escapedText;
9495
}
9596
})
9697
.join("");

web-app/src/routes/(authenticated)/website/[websiteId]/logs/+page.svelte

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -141,24 +141,20 @@
141141
<button type="submit">Compute diff</button>
142142
</form>
143143
{#if form?.logId === id && form?.currentDiff}
144-
<pre>{@html DOMPurify.sanitize(
145-
// .replace takes escaped text representations of line breaks and converts them to real line breaks that render correctly in HTML
146-
form.currentDiff.replace(/\\r\\n|\\n|\\r/g, "\n").replace(/\\\"/g, '"'),
147-
{
148-
ALLOWED_TAGS: ["ins", "del"]
149-
}
150-
)}</pre>
144+
<pre>{@html form.currentDiff
145+
.replace(/\\\"/g, '"')
146+
.replace(/\\r\\n|\\n|\\r/g, "\n")}</pre>
151147
{/if}
152148
{/if}
153149

154150
{#if new_value && !old_value}
155151
<h4>New value</h4>
156-
<pre>{DOMPurify.sanitize(newValue)}</pre>
152+
<pre>{newValue.replace(/\\\"/g, '"').replace(/\\r\\n|\\n|\\r/g, "\n")}</pre>
157153
{/if}
158154

159155
{#if old_value && !new_value}
160156
<h4>Old value</h4>
161-
<pre>{DOMPurify.sanitize(oldValue)}</pre>
157+
<pre>{oldValue.replace(/\\\"/g, '"').replace(/\\r\\n|\\n|\\r/g, "\n")}</pre>
162158
{/if}
163159
</Modal>
164160
</td>

0 commit comments

Comments
 (0)