Skip to content

Commit

Permalink
websocket: fix NPE when dispatching events (#1798)
Browse files Browse the repository at this point in the history
Change WebSocketAPI to check if the event has parameters before using
them.
Update changes in ZapAddOn.xml file and about help page.
  • Loading branch information
thc202 authored and psiinon committed Sep 17, 2018
1 parent 5f0510b commit f78a610
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
21 changes: 12 additions & 9 deletions src/org/zaproxy/zap/extension/websocket/WebSocketAPI.java
Expand Up @@ -484,15 +484,18 @@ public void eventReceived(Event ev) {
jsonTarget.put("target.maxDepth", target.getMaxDepth());
json.put("event.target", jsonTarget);
}
// Can't use json.putAll as that performs auto json conversion, which we dont want
for ( Entry<String, String> entry : ev.getParameters().entrySet()) {
try {
JSONSerializer.toJSON(entry.getValue());
// Its valid JSON so escape
json.put(entry.getKey(), "'" + entry.getValue() + "'");
} catch (JSONException e) {
// Its not a valid JSON object so can add as is
json.put(entry.getKey(), entry.getValue());

if (ev.getParameters() != null) {
// Can't use json.putAll as that performs auto json conversion, which we dont want
for ( Entry<String, String> entry : ev.getParameters().entrySet()) {
try {
JSONSerializer.toJSON(entry.getValue());
// Its valid JSON so escape
json.put(entry.getKey(), "'" + entry.getValue() + "'");
} catch (JSONException e) {
// Its not a valid JSON object so can add as is
json.put(entry.getKey(), entry.getValue());
}
}
}
try {
Expand Down
1 change: 1 addition & 0 deletions src/org/zaproxy/zap/extension/websocket/ZapAddOn.xml
Expand Up @@ -7,6 +7,7 @@
<url></url>
<changes>
<![CDATA[
Fix an exception when dispatching events.
]]>
</changes>
<classnames>
Expand Down
Expand Up @@ -18,7 +18,7 @@ <H2>History</H2>

<H3>Version 19 - TBD</H3>
<ul>
<li></li>
<li>Fix an exception when dispatching events.</li>
</ul>

<H3>Version 18 - 2018/08/01</H3>
Expand Down

0 comments on commit f78a610

Please sign in to comment.