Sunday, September 11, 2011

WebScarab and JSON

Webscarab is a Java based proxy server which intercepts HTTP and HTTPS requests for security diagnostics and troubleshooting, it's useful for analysing your webpage to see how your data is flowing.

I've recently been using Webscarab with some GWT applications, but ran into problems with a few RPC calls. The regular POSTS and GETS were being intercepted correctly, but not the JSON replies.

As the JSON replies are being sent as Content-Type 'gzip', it is a simple task of changing the headers to be "text/xml".

Webscarab offers a feature called 'bean-shell', it's used for automated header and content manipulation, as well as many other things. You can find it under the 'Proxy' Tab on the main Webscarab window.
The code I used to do re-write the header is this:

import org.owasp.webscarab.model.Request;
import org.owasp.webscarab.model.Response;
import org.owasp.webscarab.httpclient.HTTPClient;
import java.io.IOException;

public Response fetchResponse(HTTPClient nextPlugin, Request request) throws IOException {
response = nextPlugin.fetchResponse(request);
response.setHeader("Content-Type","text/xml");
return response;
}


Adding this code and enabling the bean-shell feature, means that all replies will come through as text/xml, so it'll pop-up like a regular response, allowing you to analyse and manipulate the content as you see fit.

No comments: