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

Allow escaping of more than just tags #540

Closed
Zsar opened this issue Feb 21, 2022 · 3 comments · May be fixed by #668
Closed

Allow escaping of more than just tags #540

Zsar opened this issue Feb 21, 2022 · 3 comments · May be fixed by #668

Comments

@Zsar
Copy link

Zsar commented Feb 21, 2022

The problem to solve

I would like the sanitised string to be displayed exactly as input. Discarding text is not helpful, as it will be missing.
options.disallowedTagsMode = 'recursiveEscape' already exists to escape tags instead of removing them. Attributes, etc. are still removed instead of escaped though.

User Story:

  1. We start with (mostly) everything disallowed.
  2. User attempts to input HTML, sees the resulting text and copy&pastes directly into a feature request to allow the tag/attribute/style/whatever they want and do not get.
  3. (If the requested element can be safely allowed) we copy&paste the text directly into our mock project for TDD.
  4. loop 2., 3.
  5. Profit!

Proposed solution

I, personally, would like a simple switch options.disallowedEverythingMode: 'discard' | 'escape' | 'recursiveEscape' or similar.

Alternatives

Mirroring the lists and records of options akin to how the existing options.disallowedTagsMode mirrors options.allowedTags is probably the more sensible approach:

options.disallowedAttributesMode: 'discard' | 'escape' | 'recursiveEscape'
options.disallowedStylesMode: 'discard' | 'escape' | 'recursiveEscape'
<etc.>

Mayhap a synthetic "all the things" could be added as a function on top of those:
function setDisallowedEverythingMode(mode: 'discard' | 'escape' | 'recursiveEscape') {/* set every flag to mode */}

Additional context

options: {
  allowedAttributes: {},
  allowedTags: [],
  disallowedTagsMode: 'recursiveEscape',
  nonTextTags: [],
  selfClosing: [],
}

Input: "Cursed Project <img src=x onerror=alert('AllYourBaseAreBelongToUs!');>"
Expected: Cursed Project <img src=x onerror=alert('AllYourBaseAreBelongToUs!');>
Displayed: Cursed Project <img></img>

@boutell
Copy link
Member

boutell commented Feb 22, 2022 via email

@boutell
Copy link
Member

boutell commented Feb 22, 2022 via email

@stale
Copy link

stale bot commented Apr 24, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Apr 24, 2022
@stale stale bot closed this as completed Jun 12, 2022
benelliott added a commit to benelliott/sanitize-html that referenced this issue Jul 8, 2024
benelliott added a commit to benelliott/sanitize-html that referenced this issue Jul 8, 2024
benelliott added a commit to benelliott/sanitize-html that referenced this issue Jul 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants