Skip to content

Commit 67e5ee6

Browse files
fix: xss when rendering schema errors (#4256)
* fix: stop rendering config errors as html * Update CHANGELOG.md * Update UnsupportedField.tsx * Fix formatting * Update packages/core/src/components/templates/UnsupportedField.tsx * Update CHANGELOG.md * Update <SchemaField> to match * - Fix lint error * Update CHANGELOG.md - Updating to mention potential breaking change --------- Co-authored-by: Heath C <[email protected]>
1 parent a2dc1cd commit 67e5ee6

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ should change the heading of the (upcoming) version to include a major version b
1818

1919
# 5.19.4
2020

21+
## @rjsf/core
22+
23+
- Fix XSS when rendering schema validation errors [#4254](https://github.com/rjsf-team/react-jsonschema-form/issues/2718)
24+
- NOTE: This will have potential consequences if you are using the [translateString](https://rjsf-team.github.io/react-jsonschema-form/docs/api-reference/form-props/#translatestring) feature and are trying to render HTML. Switching to [Markdown](https://www.markdownguide.org/) will solve your problems.
25+
2126
## @rjsf/utils
2227

2328
- Updated the `ValidatorType` interface to add an optional `reset?: () => void` prop that can be implemented to reset a validator back to initial constructed state

packages/core/src/components/fields/ObjectField.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ class ObjectField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends Fo
263263
return (
264264
<div>
265265
<p className='config-error' style={{ color: 'red' }}>
266-
<Markdown>
266+
<Markdown options={{ disableParsingRawHTML: true }}>
267267
{translateString(TranslatableString.InvalidObjectField, [name || 'root', (err as Error).message])}
268268
</Markdown>
269269
</p>

packages/core/src/components/fields/SchemaField.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,11 @@ function SchemaFieldRender<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
201201

202202
const description = uiOptions.description || props.schema.description || schema.description || '';
203203

204-
const richDescription = uiOptions.enableMarkdownInDescription ? <Markdown>{description}</Markdown> : description;
205-
204+
const richDescription = uiOptions.enableMarkdownInDescription ? (
205+
<Markdown options={{ disableParsingRawHTML: true }}>{description}</Markdown>
206+
) : (
207+
description
208+
);
206209
const help = uiOptions.help;
207210
const hidden = uiOptions.widget === 'hidden';
208211

packages/core/src/components/templates/UnsupportedField.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function UnsupportedField<T = any, S extends StrictRJSFSchema = RJSFSchema, F ex
2727
return (
2828
<div className='unsupported-field'>
2929
<p>
30-
<Markdown>{translateString(translateEnum, translateParams)}</Markdown>
30+
<Markdown options={{ disableParsingRawHTML: true }}>{translateString(translateEnum, translateParams)}</Markdown>
3131
</p>
3232
{schema && <pre>{JSON.stringify(schema, null, 2)}</pre>}
3333
</div>

0 commit comments

Comments
 (0)