-
Notifications
You must be signed in to change notification settings - Fork 161
feat: initialize hubspot project with connection to email [] #9893
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for ecommerce-app-base-components canceled.
|
let sanitized = textStr | ||
// Remove null bytes that can terminate strings in some contexts | ||
.replace(/\0/g, '') | ||
// Remove control characters except common whitespace | ||
.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g, '') | ||
// Remove potential script injection patterns | ||
.replace(/<script[^>]*>.*?<\/script>/gis, '') | ||
.replace(/javascript:/gi, '') | ||
.replace(/vbscript:/gi, '') | ||
.replace(/on\w+\s*=/gi, '') | ||
// Remove data URLs that could contain scripts | ||
.replace(/data:.*?base64/gi, ''); |
Check failure
Code scanning / CodeQL
Incomplete URL scheme check High
This autofix suggestion was applied.
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 4 months ago
To fix the issue, the sanitizeUserInput
function should be updated to comprehensively check for and sanitize URLs with the data:
scheme. This can be achieved by adding a case-insensitive check for any data:
scheme, similar to the existing checks for javascript:
and vbscript:
. The regex targeting data:
URLs with base64
should be replaced with a broader check for any data:
scheme.
Changes will be made to the sanitizeUserInput
function in the file apps/hubspot/functions/utils.ts
. Specifically:
- Replace the regex targeting
data:
URLs withbase64
on line 94 with a more comprehensive check fordata:
URLs. - Ensure the check is case-insensitive and removes all
data:
URLs.
-
Copy modified lines R93-R94
@@ -92,4 +92,4 @@ | ||
.replace(/on\w+\s*=/gi, '') | ||
// Remove data URLs that could contain scripts | ||
.replace(/data:.*?base64/gi, ''); | ||
// Remove data URLs that could contain scripts or other malicious content | ||
.replace(/data:/gi, ''); | ||
|
let sanitized = textStr | ||
// Remove null bytes that can terminate strings in some contexts | ||
.replace(/\0/g, '') | ||
// Remove control characters except common whitespace | ||
.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g, '') | ||
// Remove potential script injection patterns | ||
.replace(/<script[^>]*>.*?<\/script>/gis, '') | ||
.replace(/javascript:/gi, '') | ||
.replace(/vbscript:/gi, '') | ||
.replace(/on\w+\s*=/gi, '') |
Check failure
Code scanning / CodeQL
Incomplete multi-character sanitization High
on
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 4 months ago
To address the issue, we will modify the sanitization logic to repeatedly apply the regular expression replacements until no further changes occur. This ensures that all instances of unsafe patterns, including those that might reappear after partial sanitization, are fully removed. This approach is robust and prevents incomplete sanitization.
The changes will involve wrapping the sanitization logic in a loop that continues until the input string remains unchanged after a pass. This will be implemented in the sanitizeUserInput
function.
-
Copy modified lines R83-R99
@@ -82,14 +82,19 @@ | ||
// Remove or escape potential injection patterns | ||
let sanitized = textStr | ||
// Remove null bytes that can terminate strings in some contexts | ||
.replace(/\0/g, '') | ||
// Remove control characters except common whitespace | ||
.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g, '') | ||
// Remove potential script injection patterns - fixed to handle closing tags with whitespace | ||
.replace(/<script[^>]*>.*?<\/script\s*>/gis, '') | ||
.replace(/javascript:/gi, '') | ||
.replace(/vbscript:/gi, '') | ||
.replace(/on\w+\s*=/gi, '') | ||
// Remove data URLs that could contain scripts | ||
.replace(/data:.*?base64/gi, ''); | ||
let sanitized = textStr; | ||
let previous; | ||
do { | ||
previous = sanitized; | ||
sanitized = sanitized | ||
// Remove null bytes that can terminate strings in some contexts | ||
.replace(/\0/g, '') | ||
// Remove control characters except common whitespace | ||
.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g, '') | ||
// Remove potential script injection patterns - fixed to handle closing tags with whitespace | ||
.replace(/<script[^>]*>.*?<\/script\s*>/gis, '') | ||
.replace(/javascript:/gi, '') | ||
.replace(/vbscript:/gi, '') | ||
.replace(/on\w+\s*=/gi, '') | ||
// Remove data URLs that could contain scripts | ||
.replace(/data:.*?base64/gi, ''); | ||
} while (sanitized !== previous); | ||
|
39019a0
to
50aa2eb
Compare
const textContent = sanitizedHtml | ||
.replace(/<[^>]*>/g, '') // Remove HTML tags from sanitized input |
Check failure
Code scanning / CodeQL
Incomplete multi-character sanitization High
<script
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 4 months ago
To address the issue, we should ensure that the sanitization process is robust and handles all potential edge cases. The best approach is to use a well-tested library like sanitize-html
to sanitize the input securely. This library is specifically designed to remove unsafe HTML elements and attributes while preserving safe content. By replacing the sanitizeUserInput
function with sanitize-html
, we can ensure that the input is thoroughly sanitized before further processing.
The changes will involve:
- Importing the
sanitize-html
library. - Replacing the call to
sanitizeUserInput
with a call tosanitizeHtml
. - Configuring
sanitizeHtml
to remove all unsafe tags and attributes.
-
Copy modified line R2 -
Copy modified lines R35-R38
@@ -1,3 +1,3 @@ | ||
import type { HubSpotRequestContext, HubSpotResponse, ContentBlock } from '../types'; | ||
import { sanitizeUserInput } from '../utils'; | ||
import sanitizeHtml from 'sanitize-html'; | ||
|
||
@@ -34,3 +34,6 @@ | ||
const rawHtml = String(widget.body.html); | ||
const sanitizedHtml = sanitizeUserInput(rawHtml); | ||
const sanitizedHtml = sanitizeHtml(rawHtml, { | ||
allowedTags: [], // Remove all HTML tags | ||
allowedAttributes: {}, // Remove all attributes | ||
}); | ||
|
-
Copy modified lines R15-R16
@@ -14,3 +14,4 @@ | ||
"react": "18.3.1", | ||
"react-dom": "18.3.1" | ||
"react-dom": "18.3.1", | ||
"sanitize-html": "^2.17.0" | ||
}, |
Package | Version | Security advisories |
sanitize-html (npm) | 2.17.0 | None |
let sanitized = textStr | ||
// Remove null bytes that can terminate strings in some contexts | ||
.replace(/\0/g, '') | ||
// Remove control characters except common whitespace | ||
.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g, '') | ||
// Remove potential script injection patterns - fixed to handle closing tags with whitespace | ||
.replace(/<script[^>]*>.*?<\/script\s*>/gis, '') |
Check failure
Code scanning / CodeQL
Incomplete multi-character sanitization High
<script
// Remove control characters except common whitespace | ||
.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g, '') | ||
// Remove potential script injection patterns - fixed to handle closing tags with whitespace | ||
.replace(/<script[^>]*>.*?<\/script\s*>/gis, '') |
Check failure
Code scanning / CodeQL
Bad HTML filtering regexp High
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 4 months ago
To fix the issue, replace the custom regular expression with a well-tested HTML sanitization library, such as DOMPurify
. This library is specifically designed to handle edge cases and ensure robust sanitization of user input. The replacement will involve importing the library and using its sanitize
function to clean the input. This approach eliminates the need for custom regex-based sanitization and ensures comprehensive protection against XSS attacks.
Steps to implement the fix:
- Install the
dompurify
library. - Import
DOMPurify
in the file. - Replace the regex-based sanitization logic with
DOMPurify.sanitize
. - Retain other sanitization steps (e.g., null byte removal, control character removal) as additional safeguards.
-
Copy modified line R2 -
Copy modified lines R88-R91
@@ -1,2 +1,3 @@ | ||
import type { TextNode } from './types'; | ||
import DOMPurify from 'dompurify'; | ||
|
||
@@ -86,10 +87,6 @@ | ||
// Remove control characters except common whitespace | ||
.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g, '') | ||
// Remove potential script injection patterns - fixed to handle closing tags with whitespace | ||
.replace(/<script[^>]*>.*?<\/script\s*>/gis, '') | ||
.replace(/javascript:/gi, '') | ||
.replace(/vbscript:/gi, '') | ||
.replace(/on\w+\s*=/gi, '') | ||
// Remove data URLs that could contain scripts | ||
.replace(/data:.*?base64/gi, ''); | ||
.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g, ''); | ||
|
||
// Use DOMPurify to sanitize HTML content | ||
sanitized = DOMPurify.sanitize(sanitized); | ||
|
-
Copy modified lines R15-R16
@@ -14,3 +14,4 @@ | ||
"react": "18.3.1", | ||
"react-dom": "18.3.1" | ||
"react-dom": "18.3.1", | ||
"dompurify": "^3.2.6" | ||
}, |
Package | Version | Security advisories |
dompurify (npm) | 3.2.6 | None |
3333d05
to
50aa2eb
Compare
ca170c5
to
f86be19
Compare
Purpose
Video is linked to this slack post https://contentful.slack.com/archives/C07QGCRMTU1/p1749063620990619
This is not production level code. The point of this PR is to