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

feat: make html sanitization optional #6432

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/source/tags/hypertext.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Use with the following data types: HTML.
| value | <code>string</code> | | Value of the element |
| [valueType] | <code>url</code> \| <code>text</code> | <code>text</code> | Whether the text is stored directly in uploaded data or needs to be loaded from a URL |
| [inline] | <code>boolean</code> | <code>false</code> | Whether to embed HTML directly in Label Studio or use an iframe |
| [sanitizeHtml] | <code>boolean</code> | <code>true</code> | Whether to sanitize the provided html (remove scripts etc) |
| [saveTextResult] | <code>yes</code> \| <code>no</code> | | Whether to store labeled text along with the results. By default, doesn't store text for `valueType=url` |
| [encoding] | <code>none</code> \| <code>base64</code> \| <code>base64unicode</code> | | How to decode values from encoded strings |
| [selectionEnabled] | <code>boolean</code> | <code>true</code> | Enable or disable selection |
Expand Down
5 changes: 4 additions & 1 deletion web/libs/editor/src/tags/object/RichText/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const WARNING_MESSAGES = {
* @param {string} value - value of the element
* @param {url|text} [valueType=url|text] – source of the data, check (Data retrieval)[https://labelstud.io/guide/tasks.html] page for more inforamtion
* @param {boolean} [inline=false] - whether to embed html directly to LS or use iframe (only HyperText)
* @param {boolean} [sanitizeHtml=true] - whether to sanitize the provided html (only HyperText)
* @param {boolean} [saveTextResult=true] – whether or not to save selected text to the serialized data
* @param {boolean} [selectionEnabled=true] - enable or disable selection
* @param {boolean} [clickableLinks=false] – allow annotator to open resources from links
Expand All @@ -57,6 +58,8 @@ const TagAttrs = types.model("RichTextModel", {

inline: false,

sanitizehtml: types.optional(types.boolean, true),

/** Whether or not to save selected text to the serialized data */
savetextresult: types.optional(types.enumeration(["none", "no", "yes"]), () =>
window.LS_SECURE_MODE ? "no" : "none",
Expand Down Expand Up @@ -235,7 +238,7 @@ const Model = types
// clean up the html — remove scripts and iframes
// nodes count better be the same, so replace them with stubs
// we should not sanitize text tasks because we already have htmlEscape in view.js
if (isFF(FF_SAFE_TEXT) && self.type === "text") {
if (!self.sanitizehtml || (isFF(FF_SAFE_TEXT) && self.type === "text")) {
self._value = String(val);
} else {
self._value = sanitizeHtml(String(val));
Expand Down