Skip to content

Commit 9202dd9

Browse files
committed
Escape website title in webview HTML
- HTML-escape title before inserting it into <title>. ├── apps │ └── editor │ ├── package.json │ └── src │ └── views │ └── prompt │ ├── backend │ │ ├── message-handlers │ │ │ ├── handle-open-website.ts │ │ │ ├── handle-paste-url.ts │ │ │ └── index.ts │ │ ├── prompt-view-provider.ts │ │ └── utils │ │ ├── persistent-text-storage.ts │ │ ├── symbols │ │ │ ├── replace-symbols.ts │ │ │ └── website │ │ │ └── replace-website-symbol.ts │ │ └── website-fetcher.ts │ ├── frontend │ │ ├── Main │ │ │ ├── Main.tsx │ │ │ └── MainView │ │ │ └── MainView.tsx │ │ └── Prompt.tsx │ └── types │ └── messages.ts └── packages └── ui └── src └── components └── editor └── common └── prompts └── PromptField ├── PromptField.tsx └── hooks └── use-handlers └── handle-input-click.ts
1 parent 975550a commit 9202dd9

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

‎apps/editor/src/views/prompt/backend/message-handlers/handle-open-website.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ export const handle_open_website = async (
9292

9393
const csp = webview_panel.webview.cspSource
9494

95+
const escaped_title = title
96+
.replace(/&/g, '&amp;')
97+
.replace(/</g, '&lt;')
98+
.replace(/>/g, '&gt;')
99+
.replace(/"/g, '&quot;')
100+
.replace(/'/g, '&#039;')
101+
95102
webview_panel.webview.html = `
96103
<!DOCTYPE html>
97104
<html lang="en">
@@ -102,7 +109,7 @@ export const handle_open_website = async (
102109
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.1/styles/vs2015.min.css">
103110
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.1/highlight.min.js"></script>
104111
<script>document.addEventListener('DOMContentLoaded', () => hljs.highlightAll());</script>
105-
<title>${title}</title>
112+
<title>${escaped_title}</title>
106113
<style>
107114
body {
108115
line-height: 1.5;

0 commit comments

Comments
 (0)