urlchecks.rst 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. .. _security_urlchecks:
  2. URL Checks
  3. ==========
  4. The :guilabel:`URL External Access Checks` page controls the checks that are performed on user provided URLs that
  5. GeoServer will use to access remote resources.
  6. Currently, the checks are performed on the following functionality:
  7. - WMS GetMap, GetFeatureInfo and GetLegendGraphic requests with remote SLD stylesheets (``sld`` parameter)
  8. - Remote icons referenced by styles (access to icons in the data directory is always allowed)
  9. - WMS GetMap and GetFeatureInfo requests in feature portrayal mode (``REMOTE_OWS`` and ``REMOTE_OWS_TYPE`` parameters)
  10. - WPS remote inputs, either as GET or POST requests
  11. External URLs configured by admins in the GUI (e.g. WFS, cascaded WMS & WMTS data stores) are not subject to this check.
  12. Please refer back to this page for any additional remote service access checks added in the future.
  13. Configuration of URL checks
  14. ---------------------------
  15. Navigate to :menuselection:`Data > URL Checks` page to manage and configure URL Checks.
  16. .. figure:: images/urlchecks.png
  17. URL Checks table
  18. Use the :guilabel:`Enable/Disable URL Checks` enable this safety feature:
  19. * When the :guilabel:`URL checks are enabled` checkbox is enabled, URL checks are performed to limit GeoServer access to remote resources as outlined above.
  20. Enabling URL checks is recommended to limit normal Open Web Service protocols interaction being used for Cross Site Scripting attacks.
  21. * When checkbox disabled, :guilabel:`URL checks are NOT enabled`, GeoServer is provided unrestricted access to remote resources.
  22. Disabling URL Checks is not a secure or recommended setting.
  23. Adding a regular expression based check
  24. ---------------------------------------
  25. The buttons for adding and removing URL checks can be found at the top of the :guilabel:`URL Check list` table.
  26. To add a URL Check, press the :guilabel:`Add new URL check` button. You will be prompted to enter URL check details (as described in :ref:`security_urlchecks_edit` below).
  27. Removing a regular expression based check
  28. -----------------------------------------
  29. To remove a URL Check, select the checkbox next to one or more rows in the :guilabel:`URL Check list` table.
  30. Press the :guilabel:`Remove selected URL checks` button to remove. You will be asked to confirm or cancel the removal. Pressing :guilabel:`OK` removes the selected URL Checks.
  31. .. _security_urlchecks_edit:
  32. Editing a URL Check
  33. -------------------
  34. Regular Expression URL checks can be configured, with the following parameters for each check:
  35. .. list-table::
  36. :widths: 30 70
  37. :header-rows: 1
  38. * - Field
  39. - Description
  40. * - Name
  41. - Name for the check, used to identify it in the list.
  42. * - Description
  43. - Description of the check, for later reference.
  44. * - Regular Expression
  45. - A regular expression used to match allowed URLs
  46. * - Enabled
  47. - Check box to enable or disable the check
  48. .. figure:: images/urlchecks-edit.png
  49. Configure Regular Expression URL check
  50. Testing URL checks
  51. ------------------
  52. The :guilabel:`Test URL Checks with external URL` form allows a URL to be checked, reporting if access is allowed or disallowed.
  53. Test URL Checks form:
  54. .. list-table::
  55. :widths: 30 70
  56. :header-rows: 1
  57. * - Field
  58. - Description
  59. * - URL to check
  60. - Supply URL of external resource to check if access is allowed
  61. Press the :guilabel:`Test URL` button to perform the checks. If at least one URL Check matches the URL, it will be allowed and the test will indicate the URL Check permitting access. Otherwise it will be rejected and the test will indicate that no URL Check matched.
  62. .. figure:: images/urlchecks-test.png
  63. Test URL Checks with external URL
  64. Example RegEx Patterns
  65. ----------------------
  66. The most common pattern allows matching a given host name to allow external graphics from a remote server. This pattern uses ``^`` to mark the start, the host URL, ``.*`` to match anything, and ``$`` to end - as shown in the in following pattern:
  67. ``^https://styles\.server\.net/.*$``
  68. ::
  69. https://styles.server.net/logo.png
  70. To allow external graphics from a specific directory on a remote server:
  71. ``^https://styles\.server\.net/icons/.*$``
  72. ::
  73. https://styles.server.net/icons/forest.png
  74. When working with external graphics making use of SVG parameters use ``(\?.*)?$`` to optionally allow any query parameters after ``?``:
  75. ``^https://styles\.server\.net/icons/.*(\?.*)?$``
  76. ::
  77. https://styles.server.net/icons/forest.png
  78. https://styles.server.net/icons/forest.svg?color=darkgreen
  79. When obtaining content from an API ``\?.*`` is used (as there is no need to support relative paths). As an example ``/geoserver/ows\?`` is used below to access the GeoServer Open Web Service API:
  80. ``^https?://localhost:8080/geoserver/ows\?.*$``
  81. ::
  82. http://localhost:8080/geoserver/ows?service=WMS&version=1.3.0&request=GetCapabilities
  83. To allow for GeoServer virtual web services ``(\w+/)?`` is used for optional workspace name:
  84. ``^https?://localhost:8080/geoserver/(\w+/)?ows\?.*$``
  85. ::
  86. http://localhost:8080/geoserver/ows?service=WMS&version=1.3.0&request=GetCapabilities
  87. http://localhost:8080/geoserver/ne/ows?service=WMS&version=1.3.0&request=GetCapabilities
  88. To limit to Web Feature Service ``?.*SERVICE=WFS.*`` is used to restrict query parameter:
  89. ``^https?://localhost:8080/geoserver/(\w+/)?ows\?.*SERVICE=WFS.*?$``
  90. ::
  91. http://localhost:8080/geoserver/tiger/ows?SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=giant_polygon
  92. To allowing WMS ``REMOTE_OWS`` data access to an external GeoServer WFS service:
  93. ``^https://mapping\.server\.net/geoserver/(\w+/)?ows\?.*SERVICE=WFS.*$``
  94. ::
  95. https://mapping.server.net/geoserver/ows?SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=roads
  96. To allow external graphic access to a remote GeoServer icons:
  97. ``^https://mapping\.server\.net/geoserver/styles/.*(\?.*)?$``
  98. ::
  99. https://mapping.server.net/geoserver/styles/grass_fill.png
  100. https://mapping.server.net/geoserver/styles/ne/airport.svg?fill=gray
  101. File paths can also be checked:
  102. ``^/var/opt/geoserver/data/.*$``
  103. ::
  104. /var/opt/geoserver/data/example.tiff
  105. ``^D:\\\\data\\.*$``
  106. ::
  107. D:\\data\example.tiff
  108. .. note::
  109. The locations being checked are normalized making it easier to write RegEx patterns:
  110. * URLs paths have been normalized to remove any redundant ``\.`` or ``\..`` paths have been removed
  111. * File URLs have been normalized so that ``file:/`` is represented as ``file:///``
  112. * File paths have been normalized using ``/`` on Linux and ``\\`` on Windows
  113. .. note::
  114. Web sites are available to help define a valid Java regular expression pattern. These tools can be used to interpret, explain and test regular expressions. For example:
  115. * https://regex101.com/ (enable the Java 8 flavor)
  116. * https://www.freeformatter.com/java-regex-tester.html