Uploaded image for project: 'CXF'
  1. CXF
  2. CXF-8619

Potential double-urldecode of @Form parameters

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.4.5
    • 3.5.0, 3.4.6
    • None
    • None
    • Unknown

    Description

      Where form parameters are retrieved via HttpServletRequest.getParameter methods (https://github.com/apache/cxf/blob/master/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/FormUtils.java#L176-L180), the key and value are already URL decoded.

       

      They are then subsequently decoded again: https://github.com/apache/cxf/blob/master/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java#L1172-L1178

       

      The effect here is that an endpoint like this:

      @POST
      @Path("/api")
      @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
      @Produces(MediaType.TEXT_PLAIN)
      public Response myWebService(@Context HttpServletRequest request, @Context HttpServletResponse res, @FormParam("p1") String p1) {
          LOGGER.info("Value received: " + p1);
          return Response.ok(p1).build();
      }

      if called with a payload of

      p1=hello%2bworld

      would receive "hello world" and not "hello+world".

       

      This has been observed when running in Apache TomEE, when running with a servlet filter that also calls HttpServletRequest.getParameter(). The effect here is that Tomcat consumes the request inputstream, parses the form data and populates a parameter map. In turn, when the call propagates to CXF, the inputstream is empty, so it falls back to the servlet parameters (which have already been urldecoded).

      PR with a test to follow, and I'll follow up on the mailing list too.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              jgallimore Jonathan Gallimore
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: