Skip to content
This repository was archived by the owner on Feb 2, 2024. It is now read-only.

Conversation

@cwardzala
Copy link
Member

  • Add WYSIWYG Editor to Forms page
  • update WYSIWYG Editor to sanitize HTML

- Add WYSIWYG Editor to Forms page
- update WYSIWYG Editor to sanitize HTML
@aws-amplify-us-east-1
Copy link

This pull request is automatically being deployed by Amplify Hosting (learn more).

Access this pull request here: https://pr-89.djk07gpj85mlq.amplifyapp.com

Copy link
Collaborator

@nsmedira nsmedira left a comment

Choose a reason for hiding this comment

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

reviewed and approved with suggestions 2023-01-06 at 14:35 ET

Comment on lines +18 to +21
SafeInnerHTML.propTypes = {
as: PropTypes.elementType,
html: PropTypes.string
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

if we merged in the work on TS in this PR, we could write this in TS from the start and replace propTypes with Props interface

Copy link
Member Author

Choose a reason for hiding this comment

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

Yea, seems like that PR is not quite ready for prime time.

Copy link
Contributor

Choose a reason for hiding this comment

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

now that the TS PR has been approved, can we refactor this to typescript

Comment on lines +142 to +150
<WysiwygEditor
label="WYSIWYG Editor"
html={`<p>Pellentesque habitant <strong style="color: red">morbi tristique senectus</strong> <img src=x onerror=alert('this should never get shown') /> fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>`}
/>
<WysiwygEditor
label="Read Only WYSIWYG Editor"
html="<p>Pellentesque habitant <strong>morbi tristique senectus</strong> <img src=x onerror=alert('this should never get shown') /> et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>"
readOnly
/>
Copy link
Collaborator

Choose a reason for hiding this comment

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

would the intent of this code (i.e. presumably to demonstrate that alert('this should never get shown') is never executed) be better expressed as a jest test?

e.g. pseudo

describe('WysiwygEditor', () => {
    test('html prop is sanitized', () => {
        render(<WysiwygEditor html={<img src=x onerror=alert('this should never get shown') />)

        expect(wysiwygEditorDiv).toHaveTextContent('');
    })
})

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, 100%

Copy link
Collaborator

@nsmedira nsmedira left a comment

Choose a reason for hiding this comment

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

reviewed and approved 2023-01-17 at 11:04 ET

Forms should be built with <a href="https://jaredpalmer.com/formik/">Formik</a>.
Forms should be built with{' '}
<a href="https://jaredpalmer.com/formik/" target="_blank" rel="noopener noreferrer">
Formik <FaExternalLinkAlt style={{ fontSize: '75%' }} />
Copy link
Contributor

Choose a reason for hiding this comment

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

either add title, aria-label, or aria-hidden. As of now the screen reader has no context for this icon.

<p>
The HTML content passed into and generated from <code>WysiwygEditor</code> is sanitized with{' '}
<a href="https://github.com/cure53/DOMPurify" target="_blank" rel="noopener noreferrer">
DOMPurify <FaExternalLinkAlt style={{ fontSize: '75%' }} />
Copy link
Contributor

Choose a reason for hiding this comment

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

class instead of inline style

Copy link
Contributor

Choose a reason for hiding this comment

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

either add title, aria-label, or aria-hidden. As of now the screen reader has no context for this icon.

Copy link
Contributor

@nclayt0n nclayt0n left a comment

Choose a reason for hiding this comment

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

reviewed with comments 1/17

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants