Skip to content

Commit 8060477

Browse files
committed
export: Fix XSS vulnerability
Mitigates CVE-2024-47880. See GHSA-79jv-5226-783f By setting the contentType parameter to text/html and choosing export parameters which include a script in the text output, an attacker would be able to execute arbitrary code in the browser, inside OpenRefine's origin. The contentType parameter is not actually supplied in any internal calls, meaning that the content type declared by the exporter is always used, so we drop support for this parameter.
1 parent 10bf087 commit 8060477

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

Diff for: main/src/com/google/refine/commands/project/ExportRowsCommand.java

+5-6
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ public class ExportRowsCommand extends Command {
6767
private static final Logger logger = LoggerFactory.getLogger("ExportRowsCommand");
6868

6969
/**
70-
* This command uses POST but is left CSRF-unprotected as it does not incur a state change.
70+
* This command uses POST but is left CSRF-unprotected as it does not incur a state change. TODO: add CSRF
71+
* protection anyway, as it does not cost much and could still have prevented an XSS vulnerability
7172
*/
7273

7374
@Deprecated(since = "3.9")
@@ -105,11 +106,9 @@ public void doPost(HttpServletRequest request, HttpServletResponse response)
105106
exporter = new CsvExporter('\t');
106107
}
107108

108-
String contentType = params.get("contentType");
109-
if (contentType == null) {
110-
contentType = exporter.getContentType();
111-
}
112-
response.setHeader("Content-Type", contentType);
109+
response.setHeader("Content-Type", exporter.getContentType());
110+
// in case the content-type is text/html, to avoid XSS attacks
111+
response.setHeader("Content-Security-Policy", "script-src 'none'; connect-src 'none'");
113112

114113
String preview = params.get("preview");
115114
if (!"true".equals(preview)) {

0 commit comments

Comments
 (0)