@rjsf/core 5.16.0 → 5.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -69,10 +69,15 @@ function FileInfoPreview<T = any, S extends StrictRJSFSchema = RJSFSchema, F ext
69
69
  return null;
70
70
  }
71
71
 
72
- if (type.indexOf('image') !== -1) {
72
+ // If type is JPEG or PNG then show image preview.
73
+ // Originally, any type of image was supported, but this was changed into a whitelist
74
+ // since SVGs and animated GIFs are also images, which are generally considered a security risk.
75
+ if (['image/jpeg', 'image/png'].includes(type)) {
73
76
  return <img src={dataURL} style={{ maxWidth: '100%' }} className='file-preview' />;
74
77
  }
75
78
 
79
+ // otherwise, let users download file
80
+
76
81
  return (
77
82
  <>
78
83
  {' '}
@@ -121,17 +126,26 @@ function FilesInfo<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends F
121
126
  }
122
127
 
123
128
  function extractFileInfo(dataURLs: string[]): FileInfoType[] {
124
- return dataURLs
125
- .filter((dataURL) => dataURL)
126
- .map((dataURL) => {
129
+ return dataURLs.reduce((acc, dataURL) => {
130
+ if (!dataURL) {
131
+ return acc;
132
+ }
133
+ try {
127
134
  const { blob, name } = dataURItoBlob(dataURL);
128
- return {
129
- dataURL,
130
- name: name,
131
- size: blob.size,
132
- type: blob.type,
133
- };
134
- });
135
+ return [
136
+ ...acc,
137
+ {
138
+ dataURL,
139
+ name: name,
140
+ size: blob.size,
141
+ type: blob.type,
142
+ },
143
+ ];
144
+ } catch (e) {
145
+ // Invalid dataURI, so just ignore it.
146
+ return acc;
147
+ }
148
+ }, [] as FileInfoType[]);
135
149
  }
136
150
 
137
151
  /**