Layer7 API Management

  • 1.  How can i check for invalid JSON

    Posted May 11, 2017 05:47 AM

    Hi,

     

    I am wondering if there is a way to check for generic JSON schema. 

    For eg, 

    [{
    "test" : "123"
    }],

    {

    "test" : "123"

    }]

    This should return an error, but I wasnt able to catch the error despite using assertions like Protection against JSON Document or some of the other threat protection assertions.

     

    Thanks for your help



  • 2.  Re: How can i check for invalid JSON

    Posted May 11, 2017 07:03 AM

    Hi Frostiy ,

     

    This is what I would try,

    Send a valid request, it works

     

    For an invalid request, there is a policy falsified error. 



  • 3.  Re: How can i check for invalid JSON
    Best Answer

    Broadcom Employee
    Posted May 11, 2017 07:45 PM

    Hi Frostiy ,

    You can use ${audit.details.last.fullText} to get the last error message.
    Here is an example -> copy the xml below and paste to an empty policy on policy manger- > send your sample payload -> it will return,

    err: Source is not a valid JSON.

     

    <?xml version="1.0" encoding="UTF-8"?>
    <wsp:Policy xmlns:L7p="http://www.layer7tech.com/ws/policy" xmlns:wsp="http://schemas.xmlsoap.org/ws/2002/12/policy">
    <wsp:All wsp:Usage="Required">
    <wsp:OneOrMore wsp:Usage="Required">
    <wsp:All wsp:Usage="Required">
    <L7p:EvaluateJsonPathExpression>
    <L7p:Expression stringValue="test"/>
    </L7p:EvaluateJsonPathExpression>
    <L7p:HardcodedResponse>
    <L7p:Base64ResponseBody stringValue="cmVzdWx0Ogoke2pzb25QYXRoLnJlc3VsdH0="/>
    <L7p:ResponseContentType stringValue="text/plain; charset=UTF-8"/>
    </L7p:HardcodedResponse>
    </wsp:All>
    <wsp:All wsp:Usage="Required">
    <L7p:HardcodedResponse>
    <L7p:Base64ResponseBody stringValue="ZXJyOiAke2F1ZGl0LmRldGFpbHMubGFzdC5mdWxsVGV4dH0="/>
    <L7p:ResponseContentType stringValue="text/plain; charset=UTF-8"/>
    <L7p:ResponseStatus stringValue="601"/>
    </L7p:HardcodedResponse>
    </wsp:All>
    </wsp:OneOrMore>
    </wsp:All>
    </wsp:Policy>

     

    Regards,

    Mark