Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(2642)

Issue 28042: Strict content type checking for REST and RPC endpoints

Can't Edit
Can't Publish+Mail
Start Review
Created:
15 years, 1 month ago by louiscryan
Modified:
14 years, 11 months ago
Reviewers:
beaton, Rohit Rai, shindig.remailer, awiner
Base URL:
http://svn.apache.org/repos/asf/incubator/shindig/trunk/
Visibility:
Public.

Description

Enable strict content type checks for REST and RPC endpoints and enable it by default. Allowed content types are: JSON -> application/json, text/x-json, application/javascript, application/x-javascript, text/javascript, text/ecmascript XML -> application/xml, text/xml Atom -> application/xml+atom The default output content type for JSON is switched from application/json to application/javascript to enable more convenient browser tests as application/javascript doesnt automatically trigger a download on many browsers. application/x-www-form-urlencoded is now strictly forbidden and will result in an BAD_REQUEST. This is necessary to avoid prevent confusion around OAuth body signing. Servlets will automatically decode the body content into parameters if this content type is set and the body content is not available for the API once this happens. If the body was a JSON AppData update for instance it is lost. There is incompatability here whith Shindig PHP which allows the body through in this case and includes it in the OAuth message verification where Java Shindig simply cannot. A forthcoming patch will address the OAuth compatability issue Containers can control whether they allow unknown content types to pass through the check

Patch Set 1 #

Total comments: 4

Patch Set 2 : Wrong patch last time, sorry #

Total comments: 8

Patch Set 3 : Updated patch and for bitrot #

Total comments: 6
Unified diffs Side-by-side diffs Delta from patch set Stats (+384 lines, -132 lines) Patch
java/common/conf/shindig.properties View 1 2 1 chunk +4 lines, -0 lines 0 comments Download
java/common/src/main/java/org/apache/shindig/protocol/ApiServlet.java View 1 2 8 chunks +100 lines, -5 lines 2 comments Download
java/common/src/main/java/org/apache/shindig/protocol/DataServiceServlet.java View 1 2 3 chunks +46 lines, -24 lines 0 comments Download
java/common/src/main/java/org/apache/shindig/protocol/JsonRpcServlet.java View 1 2 4 chunks +26 lines, -20 lines 0 comments Download
java/common/src/main/java/org/apache/shindig/protocol/conversion/BeanAtomConverter.java View 2 2 chunks +2 lines, -1 line 0 comments Download
java/common/src/main/java/org/apache/shindig/protocol/conversion/BeanJsonConverter.java View 2 5 chunks +21 lines, -15 lines 4 comments Download
java/common/src/main/java/org/apache/shindig/protocol/conversion/BeanJsonLibConverter.java View 2 2 chunks +2 lines, -1 line 0 comments Download
java/common/src/main/java/org/apache/shindig/protocol/conversion/BeanXStreamConverter.java View 2 3 chunks +3 lines, -2 lines 0 comments Download
java/common/src/main/java/org/apache/shindig/protocol/conversion/BeanXmlConverter.java View 2 2 chunks +2 lines, -1 line 0 comments Download
java/common/src/test/java/org/apache/shindig/protocol/ApiServletTest.java View 1 chunk +87 lines, -0 lines 0 comments Download
java/common/src/test/java/org/apache/shindig/protocol/DataServiceServletTest.java View 1 2 6 chunks +16 lines, -10 lines 0 comments Download
java/common/src/test/java/org/apache/shindig/protocol/JsonRpcServletTest.java View 1 2 4 chunks +17 lines, -17 lines 0 comments Download
java/gadgets/src/main/java/org/apache/shindig/gadgets/render/HtmlRenderer.java View 2 3 chunks +3 lines, -3 lines 0 comments Download
java/gadgets/src/test/java/org/apache/shindig/gadgets/render/HtmlRendererTest.java View 2 5 chunks +7 lines, -8 lines 0 comments Download
java/social-api/src/main/java/org/apache/shindig/social/core/util/BeanXStreamAtomConverter.java View 2 2 chunks +2 lines, -1 line 0 comments Download
java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/AbstractLargeRestfulTests.java View 1 2 2 chunks +6 lines, -5 lines 0 comments Download
java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulJsonActivityTest.java View 2 6 chunks +12 lines, -6 lines 0 comments Download
java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulJsonDataTest.java View 2 8 chunks +19 lines, -9 lines 0 comments Download
java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulJsonPeopleTest.java View 2 5 chunks +9 lines, -4 lines 0 comments Download

Messages

Total messages: 9
louiscryan
15 years, 1 month ago (2009-03-13 22:45:01 UTC) #1
awiner
http://codereview.appspot.com/28042/diff/1/7 File java/common/src/main/java/org/apache/shindig/protocol/ApiServlet.java (right): http://codereview.appspot.com/28042/diff/1/7#newcode56 Line 56: typo? application/javascript? http://codereview.appspot.com/28042/diff/1/7#newcode63 Line 63: FORMAT_TO_PREFERRED_CONTENT_TYPE maybe better ...
15 years, 1 month ago (2009-03-13 23:11:04 UTC) #2
louiscryan
Wrong patch last time, sorry
15 years, 1 month ago (2009-03-13 23:23:54 UTC) #3
beaton
I don't know enough about the social-api side of the tree to be particularly useful ...
15 years, 1 month ago (2009-03-14 00:17:18 UTC) #4
louiscryan
Made json output application/json http://codereview.appspot.com/28042/diff/19/1020 File java/common/src/main/java/org/apache/shindig/protocol/ApiServlet.java (right): http://codereview.appspot.com/28042/diff/19/1020#newcode85 Line 85: public static final String ...
15 years, 1 month ago (2009-03-24 21:19:20 UTC) #5
louiscryan
Updated patch and for bitrot
15 years, 1 month ago (2009-03-24 21:19:50 UTC) #6
awiner
Looks good. One recommended refactoring to keep ApiServlet small(er). http://codereview.appspot.com/28042/diff/1049/1065 File java/common/src/main/java/org/apache/shindig/protocol/ApiServlet.java (right): http://codereview.appspot.com/28042/diff/1049/1065#newcode200 Line ...
15 years, 1 month ago (2009-03-24 21:32:10 UTC) #7
louiscryan
Updated as per comments. Committing http://codereview.appspot.com/28042/diff/1049/1065 File java/common/src/main/java/org/apache/shindig/protocol/ApiServlet.java (right): http://codereview.appspot.com/28042/diff/1049/1065#newcode200 Line 200: String contentType) throws ...
15 years, 1 month ago (2009-03-25 00:33:11 UTC) #8
Rohit Rai
14 years, 11 months ago (2009-06-06 07:25:10 UTC) #9
Has someone analyzed the side effects of this change on the existing container
implmentations. I am having a problem with the sample conainer bundled with
Shindig which uses application/x-www-form-urlencoded for setstate and
setevilness calls.

I am new to Shindig and may be wrong. Will be good if someone experienced
verifies this -
Line #117 in samplecontainer.js makes a call to the server -  

        sendRequestToServer('setstate', 'POST',
            gadgets.io.encodeValues({
                "fileurl" : stateFileUrl
            }),
            opt_callback);

Which should be handled by SampleContainerHandler service, but gets blocked by
ApiServlet and throws an error saying "Cannot use disallowed Content-Type
application/x-www-form-urlencoded"

These are the files effected -

samplecontainer.html
samplecontainer.js
SampleContainerHandler.java


On 2009/03/25 00:33:11, louiscryan wrote:
> Updated as per comments. Committing
> 
> http://codereview.appspot.com/28042/diff/1049/1065
> File java/common/src/main/java/org/apache/shindig/protocol/ApiServlet.java
> (right):
> 
> http://codereview.appspot.com/28042/diff/1049/1065#newcode200
> Line 200: String contentType) throws InvalidContentTypeException {
> On 2009/03/24 21:32:11, awiner wrote:
> > checkContentTypes() - and all the constants - should be in a separate class,
> > injected into ApiServlet.  Or just into the subclasses where it's used. 
> > I'd probably name it ContentTypes.
> 
> Done.
> 
> http://codereview.appspot.com/28042/diff/1049/1061
> File
>
java/common/src/main/java/org/apache/shindig/protocol/conversion/BeanJsonConverter.java
> (right):
> 
> http://codereview.appspot.com/28042/diff/1049/1061#newcode75
> Line 75: * @return An object whos toString method will return json
> On 2009/03/24 21:32:11, awiner wrote:
> > whos/whose
> 
> Done.
> 
> http://codereview.appspot.com/28042/diff/1049/1061#newcode145
> Line 145: return value instanceof String ? Boolean.valueOf((String)value) :
> Boolean.TRUE.equals(value);
> On 2009/03/24 21:32:11, awiner wrote:
> > space after )
> 
> Done.
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b