Skip to content

Commit

Permalink
🦺 [open-formulieren/security-issues#36] Removing HTML from component …
Browse files Browse the repository at this point in the history
…tooltips

Added a simplistic sanitize function that sanitizes component data when saving the component. This function removes all HTML content from the component tooltip
  • Loading branch information
robinmolen committed Feb 25, 2025
1 parent e7e8155 commit eb0dee1
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 8 deletions.
14 changes: 8 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"react-select": "^5.8.0",
"react-tabs": "^6.0.2",
"react-use": "^17.2.4",
"sanitize-html": "^2.14.0",
"state-pool": "^0.7.1",
"use-immer": "^0.9.0",
"uuid": "^8.3.2"
Expand Down
6 changes: 5 additions & 1 deletion src/openforms/js/components/formio_builder/WebformBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {IntlProvider} from 'react-intl';
import {getIntlProviderProps} from 'components/admin/i18n';
import {getAvailableAuthPlugins} from 'components/form/cosign';
import {getAvailableDocumentTypes} from 'components/form/file';
import {getComponentEmptyValue} from 'components/utils';
import {getComponentEmptyValue, sanitizeComponentData} from 'components/utils';
import jsonScriptToVar from 'utils/json-script';
import {currentTheme} from 'utils/theme';

Expand Down Expand Up @@ -137,6 +137,10 @@ class WebformBuilder extends WebformBuilderFormio {
// we can't use the original saveComponent, as it relies on this.editForm being
// a thing, which it isn't anymore here.
this.dialog.close();

// Perform some basic component data sanitizing
componentData = sanitizeComponentData(componentData);

this.saveComponentReact(componentData, parent, isNew, original);
this.highlightInvalidComponents();
};
Expand Down
9 changes: 8 additions & 1 deletion src/openforms/js/components/utils.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import {Formio} from 'formiojs';

import {removeAllHTMLContent} from 'utils/sanitizer';

const getComponentEmptyValue = component => {
const componentInstance = Formio.Components.create(component);
return componentInstance.emptyValue;
};

export {getComponentEmptyValue};
const sanitizeComponentData = componentData => ({
...componentData,
tooltip: removeAllHTMLContent(componentData.tooltip),
});

export {getComponentEmptyValue, sanitizeComponentData};
7 changes: 7 additions & 0 deletions src/openforms/js/utils/sanitizer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import sanitizeHtml from 'sanitize-html';

export const removeAllHTMLContent = content =>
sanitizeHtml(content, {
allowedTags: [],
allowedAttributes: {},
});

0 comments on commit eb0dee1

Please sign in to comment.