Validate REST GET params

47 views
Skip to first unread message

victo...@gmail.com

unread,
Mar 11, 2015, 5:16:30 PM3/11/15
to membrane...@googlegroups.com
Hi, we are facing a new issue while trying to use membrane as REST API gateway. Our security team require every incoming request has its parameters validated against some rules. We know membrane validator tag can help against POST body, but we cannot find any documentation to validate the http parameters in GET requests.

Is there anyway we can extract an url param using groovy and validate it using the built-in json validator?

Thanks in advance!

Thomas Bayer

unread,
Mar 12, 2015, 5:19:59 AM3/12/15
to membrane...@googlegroups.com
Hi Victor,
does your URLs look like this:

http://host:port/path?object={ 'color' : 'red' }&p1=3

and you want to validate

{ 'color' : 'red' }

against a json schema?

Cheers,
Thomas

Am 11.03.15 um 22:16 schrieb victo...@gmail.com:

victo...@gmail.com

unread,
Mar 12, 2015, 2:12:22 PM3/12/15
to membrane...@googlegroups.com
Yes, that's exactly what we're looking for.

Thomas Bayer

unread,
Mar 13, 2015, 2:24:08 AM3/13/15
to membrane...@googlegroups.com
Hi Victor,
Membrane can not validate a query parameter against JSON schema out of the box. But it can be accomplished easiliy:

1. Write a custom interceptor
2. Make that interceptor configureable with the location of a json schema file
3. Parse the URL and get the query string
4. Validate
5. In case of invalid:
- Create an error message and set the status code to 400
- Return ABORT from the interceptor

You can look at the custom interceptor example thats included in the distribution.

Cheers,
Thomas

Am 12.03.15 um 19:12 schrieb victo...@gmail.com:
--
You received this message because you are subscribed to the Google Groups "membrane-monitor" group.
To unsubscribe from this group and stop receiving emails from it, send an email to membrane-monit...@googlegroups.com.
To post to this group, send email to membrane...@googlegroups.com.
Visit this group at http://groups.google.com/group/membrane-monitor.
For more options, visit https://groups.google.com/d/optout.

Victor Weng

unread,
Mar 13, 2015, 8:50:28 AM3/13/15
to membrane...@googlegroups.com
Thanks. But can we do it via groovy? If so, could you please give a brief example about how to extract the parameter and using the json validator in groovy? I found very limited doc on how to use the groovy tag and the httpservletrequest object doesn't seem to exist in groovy tag. 

I'm really new to membrane but it has already amazed us with its capabilities. Thanks again! 
You received this message because you are subscribed to a topic in the Google Groups "membrane-monitor" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/membrane-monitor/GszzLKDIHLQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to membrane-monit...@googlegroups.com.

Thomas Bayer

unread,
Mar 13, 2015, 9:10:18 AM3/13/15
to membrane...@googlegroups.com
Hi Victor,
have a look at the groovy sample in the example folder. exc.request is not an object of httpservletrequest but of :

com.predic8.membrane.core.http.Request

see:

http://www.membrane-soa.org/monitor/documentation/api/

The path must be parsed to extract the query param.  Then you can invoke the JSON validator.

If you want we can offer you to implement the interceptor also.

Cheers,
Thomas


Am 13.03.15 um 13:50 schrieb Victor Weng:

Victor Weng

unread,
Mar 13, 2015, 5:43:27 PM3/13/15
to membrane...@googlegroups.com
Thanks. I can implement the interceptor myself and contribute to the project. 

I'm intending to extend the ValidatorInterceptor to introduce  a new property "againstURI" so that when it's true, the jsonSchema Validator will be used against the "json=" param in the url instead of against body. 

Is it an acceptable practice? Thanks. 

Thomas Bayer

unread,
Mar 14, 2015, 6:29:29 AM3/14/15
to membrane...@googlegroups.com
Hi Victor,

Am 13.03.15 um 22:43 schrieb Victor Weng:
Thanks. I can implement the interceptor myself and contribute to the project.
Just clone the projekt on github and make your modifications. If the solution is interessting for others too you can create a pull request.


I'm intending to extend the ValidatorInterceptor to introduce  a new property "againstURI" so that when it's true, the jsonSchema Validator will be used against the "json=" param in the url instead of against body.
That would be a possible solution.

Cheers,
Thomas
Reply all
Reply to author
Forward
0 new messages