Uploaded image for project: 'Magnolia'
  1. Magnolia
  2. MAGNOLIA-2967

Handle regex non-matching group errors in RegexpVirtualURIMapping - can block the system

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Critical Critical
    • 4.1.4, 4.2.3, 4.3
    • 4.2.1
    • core
    • None
    • Yes
    • Yes

      If the from URI doesn't have as many groups as the to URI is expecting, the regex matcher used by the RegexpVirtualURIMapping will throw an exception that kills the processing of the request.

      When I accidently removed and saved a VirtualURIFilter config with a blank from URI and a to: URI that was expecting a regex, group - it became impossible for me to fix it via the admin UI:

      The stacktrace looked a bit like this -

      java.lang.IndexOutOfBoundsException: No group 1
      at java.util.regex.Matcher.group(Matcher.java:470)
      at java.util.regex.Matcher.appendReplacement(Matcher.java:737)
      at java.util.regex.Matcher.replaceAll(Matcher.java:813)
      at info.magnolia.cms.beans.config.RegexpVirtualURIMapping.mapURI(RegexpVirtualURIMapping.java:64)
      at info.magnolia.cms.beans.config.VirtualURIManager.getURIMapping(VirtualURIManager.java:83)
      at info.magnolia.cms.filters.VirtualUriFilter.getURIMapping(VirtualUriFilter.java:122)

      The attached patch adds a unit test for the kind of bad configuration, and prior to catching the exception and returning an unchanged URL, the test will fail. This may not be the best way to handle this problem in the long term, but if you would argue that making the server become entirely unresponsive and not allow the user to fix a simple typo is a better approach than trapping the exception and returning a URI that is unchanged from the request, I question how much you like your users

      I thought about making it throw a custom MalformedURIConfig exception and then catching that exception at the VirtualURIFilter level, but since there aren't already testcases existing for the VirtualURIManager or the VirtualURIFilter, I didn't.

        Acceptance criteria

              gjoseph Magnolia International
              ryangardner Ryan Gardner
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved: