Skip to content
This repository was archived by the owner on Oct 20, 2022. It is now read-only.

Commit a5ab190

Browse files
Prevent swf attack in jsonp responses.
1 parent babd716 commit a5ab190

File tree

5 files changed

+11
-4
lines changed

5 files changed

+11
-4
lines changed

ReleaseNotes.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
Version 1.1.2
2+
-----------------------------------------
3+
- Fix security threat of swf injection in jsonp.
4+
15
Version 1.1.1
26
-----------------------------------------
37
- Move from google-collect-1.0 to guava-r07.

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<groupId>com.google.visualization</groupId>
1111
<artifactId>visualization-datasource</artifactId>
1212
<name>Google Visualization Data Source Library</name>
13-
<version>1.1.1</version>
13+
<version>1.1.2</version>
1414
<description>This library makes it easy to implement a Visualization data source so that you can
1515
easily chart or visualize your data from any of your data stores.
1616
The library implements the Google Visualization API wire protocol and query language.

src/main/java/com/google/visualization/datasource/DataSourceHelper.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,9 @@ public static String generateResponse(DataTable dataTable, DataSourceRequest dat
285285
response = HtmlRenderer.renderDataTable(dataTable, dataSourceRequest.getUserLocale());
286286
break;
287287
case JSONP:
288-
response = JsonRenderer.renderJsonResponse(
288+
// Appending a comment to the response to prevent the first characters to be the
289+
// response handler which is not controlled by the server.
290+
response = "// Data table response\n" + JsonRenderer.renderJsonResponse(
289291
dataSourceRequest.getDataSourceParameters(), responseStatus, dataTable);
290292
break;
291293
case JSON:

src/main/java/com/google/visualization/datasource/base/DataSourceParameters.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ public void setOutputType(OutputType outputType) {
223223
* @return The response handler.
224224
*/
225225
public String getResponseHandler() {
226-
return responseHandler;
226+
// Remove characters that can be a threat when injecting scripts.
227+
return responseHandler.replaceAll("[^a-zA-Z0-9_\\.]", "");
227228
}
228229

229230
/**

src/test/java/com/google/visualization/datasource/DataSourceHelperTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ public void testGenerateResponse() throws DataSourceException {
226226
new DataSourceParameters("out:jsonp"),
227227
ULocale.UK);
228228
assertEquals(
229-
"google.visualization.Query.setResponse("
229+
"// Data table response\ngoogle.visualization.Query.setResponse("
230230
+ "{\"version\":\"0.6\",\"status\":\"ok\",\"sig\":\"1548939605\","
231231
+ "\"table\":{\"cols\":[{\"id\":\"col1\",\"label\":\"column1\","
232232
+ "\"type\":\"number\",\"pattern\":\"\"},"

0 commit comments

Comments
 (0)