Skip to content
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

sanitized text should have target attribute in links #1463

Merged
merged 4 commits into from
Nov 4, 2024
Merged

sanitized text should have target attribute in links #1463

merged 4 commits into from
Nov 4, 2024

Conversation

im-shiv
Copy link
Contributor

@im-shiv im-shiv commented Oct 24, 2024

No description provided.

@im-shiv im-shiv requested a review from rismehta October 24, 2024 09:24
Copy link
Collaborator

@rismehta rismehta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check comments

Copy link

codecov bot commented Oct 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.32%. Comparing base (6bbccfc) to head (8129b88).
Report is 2 commits behind head on dev.

Additional details and impacted files
@@             Coverage Diff              @@
##                dev    #1463      +/-   ##
============================================
+ Coverage     82.28%   82.32%   +0.03%     
- Complexity      924      926       +2     
============================================
  Files           103      103              
  Lines          2371     2376       +5     
  Branches        321      323       +2     
============================================
+ Hits           1951     1956       +5     
  Misses          257      257              
  Partials        163      163              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@im-shiv im-shiv requested a review from rismehta October 24, 2024 09:35
@@ -66,7 +66,10 @@
updateValue(value) {
// html sets undefined value as undefined string in input value, hence this check is added
let actualValue = typeof value === "undefined" ? "" : value;
const sanitizedValue = window.DOMPurify ? window.DOMPurify.sanitize(actualValue) : actualValue;
let sanitizedValue = window.DOMPurify ? window.DOMPurify.sanitize(actualValue, {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There may be several attributes that could be filtered out by DOMPurify. Please validate all scenarios that are exposed. We are also planning to provide the complete HTML view, so DOMPurify needs to be capable of handling all these situations.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for future reference, this should have been done before addition of DOMPurify in the code.
Also, allowing different attributes exposes new risks for vulnerabilities, making use of DOMPurify irrelevant.
IMO, we should let customer come with a use-case and then provide a fix for it, if there is any.

Copy link
Collaborator

@rismehta rismehta Oct 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for future reference, this should have been done before addition of DOMPurify in the code.

Yes, but since it wasn't addressed prior to the addition and is now considered a bug, please verify all the use cases currently exposed in the RTE.

Also, allowing different attributes exposes new risks for vulnerabilities, making use of DOMPurify irrelevant.

No, it's relevant. Someone could modify the JSON and still launch an XSS attack. Therefore, we should selectively sanitize the content based on our specific use cases through the RTE.

IMO, we should let customer come with a use-case and then provide a fix for it, if there is any.

No, in this case, we have already exposed a set of features, so all of them need to be validated as part of this PR to prevent any further regression. In fact, let's add all of the RTE use-cases as part of the test collateral itself.

Copy link
Collaborator

@rismehta rismehta Oct 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about doing this, let's write a function specifically for cleaning HTML in text component, since we have exposed a lot of RTE use-cases

// Custom configuration for DOMPurify
const cleanHTML = (dirtyHTML) => {
    // Specify the allowed tags and attributes
    const allowedTags = [
        'b', 'strong',
        'i', 'em',
        'u',
        'small',
        'blockquote',
        'code',
        'ul', 'ol', 'li',
        'a',
        'img',
        'table', 'tr', 'td', 'th',
        'h1', 'h2', 'h3', 'h4', 'h5', 'h6',
        'br', 'p'
    ];

    const allowedAttributes = {
        // Allow attributes for links
        'a': ['href', 'target', 'rel'],
        // Allow attributes for images
        'img': ['src', 'alt', 'title']
    };

    // Sanitize the HTML
    const sanitizedHTML = DOMPurify.sanitize(dirtyHTML, {
        ALLOWED_TAGS: allowedTags,
        ALLOWED_ATTR: allowedAttributes
    });

    return sanitizedHTML;
};

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@adobe-bot
Copy link

Accessibility Violations Found

Id Impact
focus-order-semantics minor
label-title-only serious
landmark-one-main moderate
region moderate
target-size serious

@adobe-bot
Copy link

Accessibility Violations Found

Id Impact
label-title-only serious
target-size serious

1 similar comment
@adobe-bot
Copy link

Accessibility Violations Found

Id Impact
label-title-only serious
target-size serious

@adobe-bot
Copy link

Lighthouse scores (mobile)

Performance Accessibility Best-Practices SEO
Scores 94 96 96 75

@adobe-bot
Copy link

Lighthouse scores (desktop)

Performance Accessibility Best-Practices SEO
Scores 100 96 96 75

@adobe-bot
Copy link

Accessibility Violations Found

Id Impact
label-title-only serious
target-size serious

@adobe-bot
Copy link

Accessibility Violations Found

Id Impact
focus-order-semantics minor
label-title-only serious
landmark-one-main moderate
region moderate
target-size serious

@adobe-bot
Copy link

Lighthouse scores (mobile)

Performance Accessibility Best-Practices SEO
Scores 94 96 96 75

@adobe-bot
Copy link

Lighthouse scores (desktop)

Performance Accessibility Best-Practices SEO
Scores 100 96 96 75

@adobe-bot
Copy link

Accessibility Violations Found

Id Impact
label-title-only serious
target-size serious

2 similar comments
@adobe-bot
Copy link

Accessibility Violations Found

Id Impact
label-title-only serious
target-size serious

@adobe-bot
Copy link

Accessibility Violations Found

Id Impact
label-title-only serious
target-size serious

Copy link
Collaborator

@rismehta rismehta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check comments

@rismehta
Copy link
Collaborator

Please fix the test failures in this PR

@adobe-bot
Copy link

Accessibility Violations Found

Id Impact
focus-order-semantics minor
label-title-only serious
landmark-one-main moderate
region moderate
target-size serious

@adobe-bot
Copy link

Lighthouse scores (mobile)

Performance Accessibility Best-Practices SEO
Scores 93 96 96 75

@adobe-bot
Copy link

Lighthouse scores (desktop)

Performance Accessibility Best-Practices SEO
Scores 100 96 96 75

@adobe-bot
Copy link

Accessibility Violations Found

Id Impact
label-title-only serious
target-size serious

2 similar comments
@adobe-bot
Copy link

Accessibility Violations Found

Id Impact
label-title-only serious
target-size serious

@adobe-bot
Copy link

Accessibility Violations Found

Id Impact
label-title-only serious
target-size serious

@im-shiv im-shiv requested a review from rismehta October 30, 2024 08:57
@adobe-bot
Copy link

Accessibility Violations Found

Id Impact
focus-order-semantics minor
label-title-only serious
landmark-one-main moderate
region moderate
target-size serious

@adobe-bot
Copy link

Lighthouse scores (desktop)

Performance Accessibility Best-Practices SEO
Scores 100 96 96 75

@adobe-bot
Copy link

Lighthouse scores (mobile)

Performance Accessibility Best-Practices SEO
Scores 93 96 96 75

@adobe-bot
Copy link

Accessibility Violations Found

Id Impact
label-title-only serious
target-size serious

2 similar comments
@adobe-bot
Copy link

Accessibility Violations Found

Id Impact
label-title-only serious
target-size serious

@adobe-bot
Copy link

Accessibility Violations Found

Id Impact
label-title-only serious
target-size serious

@im-shiv im-shiv requested a review from barshat7 October 30, 2024 09:21
Copy link
Contributor

@barshat7 barshat7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rismehta rismehta merged commit 7c29f5d into dev Nov 4, 2024
12 checks passed
@rismehta rismehta deleted the san branch November 4, 2024 05:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants