Uploaded image for project: 'HttpComponents HttpClient'
  1. HttpComponents HttpClient
  2. HTTPCLIENT-2023

Whitelist Char Array in DefaultHttpCacheEntrySerializer

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 4.5.10
    • 4.5.11, 5.0 Beta7
    • HttpCache
    • None
    • Patch

    Description

      Intro
      Please add char array to ALLOWED_CLASS_PATTERNS in DefaultHttpCacheEntrySerializer.

      Further Explanation
      The current ALLOWED_CLASS_PATTERNS looks like this:

      private static final List<Pattern> ALLOWED_CLASS_PATTERNS = Collections.unmodifiableList(Arrays.asList(
              Pattern.compile("^(\\[L)?org\\.apache\\.http\\.(.*)"),
              Pattern.compile("^(\\[L)?java\\.util\\.(.*)"),
              Pattern.compile("^(\\[L)?java\\.lang\\.(.*)$"),
              Pattern.compile("^\\[B$")));
      

      As we can se byte arrays are allowed (at the end) but not char arrays. This currently blocks me from upgrading from 4.5.8 to 4.5.10 because the HttpCacheEntry may contain char arrays.

      The field "HttpCacheEntry.responseHeaders.headers" can be of the implementing type "BufferedHeader" which contains a "private final CharArrayBuffer buffer;" field, which contains "private char[] buffer;".

      Proposed Solution
      Maybe it would make sense to whitelist all arrays of primitives (as opposed to just arrays of bytes)? That way future code changes does not risk breaking the DefaultHttpCacheEntrySerializer?

      The code might look something like this?

      private static final List<Pattern> ALLOWED_CLASS_PATTERNS = Collections.unmodifiableList(Arrays.asList(
              Pattern.compile("^(?:\\[+L)?org\\.apache\\.http\\..*$"),
              Pattern.compile("^(?:\\[+L)?java\\.util\\..*$"),
              Pattern.compile("^(?:\\[+L)?java\\.lang\\..*$"),
              Pattern.compile("^\\[+Z$"), // boolean
              Pattern.compile("^\\[+B$"), // byte
              Pattern.compile("^\\[+C$"), // char
              Pattern.compile("^\\[+D$"), // double
              Pattern.compile("^\\[+F$"), // float
              Pattern.compile("^\\[+I$"), // int
              Pattern.compile("^\\[+J$"), // long
              Pattern.compile("^\\[+S$") // short
      ));
      

      Note that I removed groups where unnecessary (to avoid capturing) and made the required group non capturing "?:" as well as added support for arrays of arrays of arrays.

      Attachments

        Issue Links

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            Unassigned Unassigned
            Olof Larsson Olof Larsson
            Votes:
            2 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 20m
                20m

                Slack

                  Issue deployment