Skip to content

Commit 5dfa1df

Browse files
authored
fix: sanitize event type text in Gmail dropdown (calcom#27533)
- Add shared escapeHtml utility function - Apply text sanitization to title/description in content.ts - Refactor linkedin.ts to use shared utility
1 parent efcbc3a commit 5dfa1df

3 files changed

Lines changed: 16 additions & 13 deletions

File tree

companion/extension/entrypoints/content.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/// <reference types="chrome" />
22
import { initGoogleCalendarIntegration } from "../lib/google-calendar";
33
import { initLinkedInIntegration } from "../lib/linkedin";
4+
import { escapeHtml } from "../lib/utils";
45

56
/**
67
* Development-only logging utility for content scripts.
@@ -964,7 +965,7 @@ export default defineContentScript({
964965

965966
contentWrapper.innerHTML = `
966967
<div style="display: flex; align-items: center; margin-bottom: 6px; overflow: hidden;">
967-
<span style="color: #3c4043; font-weight: 500; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block;">${title}</span>
968+
<span style="color: #3c4043; font-weight: 500; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block;">${escapeHtml(title)}</span>
968969
</div>
969970
<div style="display: flex; align-items: center; gap: 8px; overflow: hidden;">
970971
<span style="
@@ -983,7 +984,7 @@ export default defineContentScript({
983984
</span>
984985
${
985986
description
986-
? `<span style="color: #5f6368; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0;">${description}</span>`
987+
? `<span style="color: #5f6368; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0;">${escapeHtml(description)}</span>`
987988
: ""
988989
}
989990
</div>
@@ -1714,7 +1715,7 @@ export default defineContentScript({
17141715

17151716
contentWrapper.innerHTML = `
17161717
<div style="display: flex; align-items: center; margin-bottom: 6px; overflow: hidden;">
1717-
<span style="color: #3c4043; font-weight: 500; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block;">${title}</span>
1718+
<span style="color: #3c4043; font-weight: 500; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block;">${escapeHtml(title)}</span>
17181719
</div>
17191720
<div style="display: flex; align-items: center; gap: 8px; overflow: hidden;">
17201721
<span style="
@@ -1733,7 +1734,7 @@ export default defineContentScript({
17331734
</span>
17341735
${
17351736
description
1736-
? `<span style="color: #5f6368; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0;">${description}</span>`
1737+
? `<span style="color: #5f6368; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0;">${escapeHtml(description)}</span>`
17371738
: ""
17381739
}
17391740
</div>

companion/extension/lib/linkedin.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/// <reference types="chrome" />
2+
import { escapeHtml } from "./utils";
23

34
// LinkedIn integration: inject a Cal.com scheduling button in LinkedIn messaging
45

@@ -951,15 +952,6 @@ export function initLinkedInIntegration() {
951952
}
952953

953954
// ============================================================================
954-
// Utility Functions
955-
// ============================================================================
956-
957-
function escapeHtml(text: string): string {
958-
const div = document.createElement("div");
959-
div.textContent = text;
960-
return div.innerHTML;
961-
}
962-
963955
// ============================================================================
964956
// Initialization
965957
// ============================================================================

companion/extension/lib/utils.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* Escapes HTML special characters to prevent XSS attacks.
3+
* Uses the browser's built-in text encoding via textContent.
4+
*/
5+
export function escapeHtml(text: string): string {
6+
if (typeof text !== "string") return "";
7+
const div = document.createElement("div");
8+
div.textContent = text;
9+
return div.innerHTML;
10+
}

0 commit comments

Comments
 (0)