Skip to content

Commit 6bbccfc

Browse files
FORMS-15852 xss security fix for svg upload in file attachment (#1462)
* FORMS-15852 xss fix for svg upload in file upload * FORMS-15852 xss fix for svg upload in file upload II * FORMS-15852 xss fix for svg upload in file upload main * FORMS-15852 xss fix for svg upload in file upload main II * FORMS-15852 xss fix for svg upload in file upload main II * FORMS-15852 xss fix for svg upload in file upload main II --------- Co-authored-by: Rajat Khurana <rajatkhurana@adobe.com>
1 parent 5092694 commit 6bbccfc

File tree

4 files changed

+42
-5
lines changed

4 files changed

+42
-5
lines changed

ui.frontend/src/view/FormFileInputWidgetBase.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
* limitations under the License.
1515
******************************************************************************/
1616

17-
import FormField from "./FormField"
18-
import FormFieldBase from "./FormFieldBase"
1917

2018
/**
2119
* This class is responsible for interacting with the file input widget. It implements the file preview,
@@ -126,13 +124,25 @@ class FormFileInputWidgetBase {
126124
return index;
127125
}
128126

127+
static displaySVG(objectUrl) {
128+
const url = objectUrl;
129+
const img = document.createElement('img');
130+
img.src = url;
131+
const newTab = window.open('', '_blank', 'scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,status=no');
132+
newTab?.document?.body.appendChild(img);
133+
}
134+
129135
static previewFileUsingObjectUrl(file) {
130136
if (file) {
131137
if (window.navigator && window.navigator.msSaveOrOpenBlob) { // for IE
132138
window.navigator.msSaveOrOpenBlob(file, file.name);
133139
} else {
134140
let url = window.URL.createObjectURL(file);
135-
window.open(url, '', 'scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,status=no');
141+
if (file.type === 'image/svg+xml') {
142+
this.displaySVG(url)
143+
} else {
144+
window.open(url, '', 'scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,status=no');
145+
}
136146
return url;
137147
}
138148
}
@@ -149,7 +159,6 @@ class FormFileInputWidgetBase {
149159
}
150160
// this would work for dataURl or normal URL
151161
window.open(url, '', 'scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,status=no');
152-
153162
}
154163
// this function maintains a map for
155164
handleFilePreview (event){
Lines changed: 11 additions & 0 deletions
Loading

ui.tests/test-module/libs/support/commands.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
4242

4343

44-
import { recurse } from 'cypress-recurse';
4544
import 'cypress-plugin-snapshots/commands';
45+
import { recurse } from 'cypress-recurse';
4646

4747
const commons = require('../commons/commons'),
4848
siteSelectors = require('../commons/sitesSelectors'),
@@ -768,6 +768,7 @@ const mimeTypes = {
768768
'txt': 'text/plain',
769769
'bat': 'application/x-msdos-program',
770770
'msg': 'application/vnd.ms-outlook',
771+
'svg': 'image/svg+xml',
771772
// Add more mappings as needed
772773
};
773774

ui.tests/test-module/specs/fileinput/fileinputv2.runtime.cy.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,22 @@ describe("Form with File Input V-2 - Basic Tests", () => {
229229
// cy.get('.cmp-adaptiveform-fileinput__filelist').eq(0).children().should('have.length', 0);
230230
})
231231

232+
it("check SVG upload and preview functionality", () => {
233+
let sampleFileNames = ['sample.svg'];
234+
const fileInput = "input[name='fileinput1']";
235+
236+
cy.attachFile(fileInput, [sampleFileNames[0]]);
237+
238+
checkFilePreviewInFileAttachment(fileInput);
239+
240+
cy.get('.cmp-adaptiveform-fileinput__filelist')
241+
.children()
242+
.should('have.length', 1)
243+
.and('contain.text', sampleFileNames[0]);
244+
245+
deleteSelectedFiles(fileInput, [sampleFileNames[0]]);
246+
});
247+
232248
it(`fielinput is disabled when readonly property is true`, () => {
233249
const fileInput5 = "input[name='fileinput5']";
234250
cy.get(fileInput5).should("have.attr", "disabled", "disabled");

0 commit comments

Comments
 (0)