Skip to content

Commit

Permalink
fix: prevent xss in form block reading sent data from BE response
Browse files Browse the repository at this point in the history
  • Loading branch information
giuliaghisini committed Apr 12, 2024
1 parent 6a47f33 commit b4139d2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
14 changes: 5 additions & 9 deletions src/components/FormView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,10 @@ const FormView = ({
/* Function that replaces variables from the user customized message */
const replaceMessage = (text) => {
let i = 0;
while (i < data.subblocks.length) {
let idField = getFieldName(
data.subblocks[i].label,
data.subblocks[i].field_id,
);
text = text.replaceAll(
'${' + idField + '}',
formData[idField]?.value || '',
);
const sent_data = formState.result.data;
while (i < sent_data.length) {
let idField = sent_data[i].label;
text = text.replaceAll('${' + idField + '}', sent_data[i].value ?? '');
i++;
}
return text;
Expand All @@ -92,6 +87,7 @@ const FormView = ({
{data.description && (
<p className="description">{data.description}</p>
)}

{formState.result ? (
<Message positive role="alert">
{/* Custom message */}
Expand Down
5 changes: 4 additions & 1 deletion src/components/View.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,10 @@ const View = ({ data, id, path }) => {
if (submitResults?.loaded) {
setFormState({
type: FORM_STATES.success,
result: intl.formatMessage(messages.formSubmitted),
result: {
message: intl.formatMessage(messages.formSubmitted),
...submitResults.result,
},
});
captcha.reset();
const formItem = document.getElementById(formid);
Expand Down
9 changes: 6 additions & 3 deletions src/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ export const submitForm = (state = initialState, action = {}) => {
...state.subrequests,
[action.subrequest]: {
...(state.subrequests[action.subrequest] || {
items: [],
total: 0,
batching: {},
result: null,
}),
error: null,
loaded: false,
Expand All @@ -62,6 +60,7 @@ export const submitForm = (state = initialState, action = {}) => {
}
: {
...state,
result: null,
error: null,
loading: true,
loaded: false,
Expand All @@ -74,6 +73,7 @@ export const submitForm = (state = initialState, action = {}) => {
...state.subrequests,
[action.subrequest]: {
...(state.subrequests[action.subrequest] || {}),
result: action.result,
error: null,
loaded: true,
loading: false,
Expand All @@ -82,6 +82,7 @@ export const submitForm = (state = initialState, action = {}) => {
}
: {
...state,
result: action.result,
error: null,
loaded: true,
loading: false,
Expand All @@ -94,6 +95,7 @@ export const submitForm = (state = initialState, action = {}) => {
...state.subrequests,
[action.subrequest]: {
...(state.subrequests[action.subrequest] || {}),
result: null,
loading: false,
loaded: false,
},
Expand All @@ -102,6 +104,7 @@ export const submitForm = (state = initialState, action = {}) => {
: {
...state,
error: action.error,
result: null,
loading: false,
loaded: false,
};
Expand Down

0 comments on commit b4139d2

Please sign in to comment.