Skip to content
This repository was archived by the owner on May 28, 2018. It is now read-only.

Commit cb0261b

Browse files
author
Michal Gajdos
committed
Update to JERSEY-2637: sensitive params can be exposed in logs even for POST requests
- Changed default behaviour (as was in previous versions) - Added an option to disable injecting query params via @FormParam Change-Id: I3364188abacc327158b5e7e08ef08a60fc94cee4 Signed-off-by: Michal Gajdos <[email protected]>
1 parent 85826a9 commit cb0261b

File tree

9 files changed

+371
-51
lines changed

9 files changed

+371
-51
lines changed

containers/jersey-servlet-core/src/main/java/org/glassfish/jersey/servlet/ServletProperties.java

Lines changed: 48 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33
*
4-
* Copyright (c) 2012-2014 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2012-2015 Oracle and/or its affiliates. All rights reserved.
55
*
66
* The contents of this file are subject to the terms of either the GNU
77
* General Public License Version 2 only ("GPL") or the Common Development
@@ -39,9 +39,10 @@
3939
*/
4040
package org.glassfish.jersey.servlet;
4141

42-
import org.glassfish.hk2.api.ServiceLocator;
4342
import org.glassfish.jersey.internal.util.PropertiesClass;
4443

44+
import org.glassfish.hk2.api.ServiceLocator;
45+
4546
/**
4647
* Jersey servlet container configuration properties.
4748
*
@@ -51,28 +52,27 @@
5152
public final class ServletProperties {
5253

5354
/**
54-
* If set the regular expression is used to match an incoming servlet path URI
55-
* to some web page content such as static resources or JSPs to be handled
56-
* by the underlying servlet engine.
57-
* <p></p>
55+
* If set, indicates the URL pattern of the Jersey servlet filter context path.
56+
* <p>
57+
* If the URL pattern of a filter is set to a base path and a wildcard,
58+
* such as "/base/*", then this property can be used to declare a filter
59+
* context path that behaves in the same manner as the Servlet context
60+
* path for determining the base URI of the application. (Note that with
61+
* the Servlet 2.x API it is not possible to determine the URL pattern
62+
* without parsing the {@code web.xml}, hence why this property is necessary.)
63+
* <p>
5864
* The property is only applicable when {@link ServletContainer Jersey servlet
59-
* container} is configured to run as a {@link javax.servlet.Filter}, otherwise
60-
* this property will be ignored. If a servlet path matches this regular
61-
* expression then the filter forwards the request to the next filter in the
62-
* filter chain so that the underlying servlet engine can process the request
63-
* otherwise Jersey will process the request. For example if you set the value
64-
* to {@code /(image|css)/.*} then you can serve up images and CSS files
65-
* for your Implicit or Explicit Views while still processing your JAX-RS
66-
* resources.
67-
* <p></p>
68-
* The type of this property must be a String and the value must be a valid
69-
* regular expression.
65+
* container} is configured to run as a {@link javax.servlet.Filter}, otherwise this property
66+
* will be ignored.
67+
* <p>
68+
* The value of the property may consist of one or more path segments separate by
69+
* {@code '/'}.
7070
* <p></p>
7171
* A default value is not set.
7272
* <p></p>
7373
* The name of the configuration property is <tt>{@value}</tt>.
7474
*/
75-
public static final String FILTER_STATIC_CONTENT_REGEX = "jersey.config.servlet.filter.staticContentRegex";
75+
public static final String FILTER_CONTEXT_PATH = "jersey.config.servlet.filter.contextPath";
7676

7777
/**
7878
* If set to {@code true} and a 404 response with no entity body is returned
@@ -100,27 +100,28 @@ public final class ServletProperties {
100100
public static final String FILTER_FORWARD_ON_404 = "jersey.config.servlet.filter.forwardOn404";
101101

102102
/**
103-
* If set, indicates the URL pattern of the Jersey servlet filter context path.
104-
* <p>
105-
* If the URL pattern of a filter is set to a base path and a wildcard,
106-
* such as "/base/*", then this property can be used to declare a filter
107-
* context path that behaves in the same manner as the Servlet context
108-
* path for determining the base URI of the application. (Note that with
109-
* the Servlet 2.x API it is not possible to determine the URL pattern
110-
* without parsing the {@code web.xml}, hence why this property is necessary.)
111-
* <p>
103+
* If set the regular expression is used to match an incoming servlet path URI
104+
* to some web page content such as static resources or JSPs to be handled
105+
* by the underlying servlet engine.
106+
* <p></p>
112107
* The property is only applicable when {@link ServletContainer Jersey servlet
113-
* container} is configured to run as a {@link javax.servlet.Filter}, otherwise this property
114-
* will be ignored.
115-
* <p>
116-
* The value of the property may consist of one or more path segments separate by
117-
* {@code '/'}.
108+
* container} is configured to run as a {@link javax.servlet.Filter}, otherwise
109+
* this property will be ignored. If a servlet path matches this regular
110+
* expression then the filter forwards the request to the next filter in the
111+
* filter chain so that the underlying servlet engine can process the request
112+
* otherwise Jersey will process the request. For example if you set the value
113+
* to {@code /(image|css)/.*} then you can serve up images and CSS files
114+
* for your Implicit or Explicit Views while still processing your JAX-RS
115+
* resources.
116+
* <p></p>
117+
* The type of this property must be a String and the value must be a valid
118+
* regular expression.
118119
* <p></p>
119120
* A default value is not set.
120121
* <p></p>
121122
* The name of the configuration property is <tt>{@value}</tt>.
122123
*/
123-
public static final String FILTER_CONTEXT_PATH = "jersey.config.servlet.filter.contextPath";
124+
public static final String FILTER_STATIC_CONTENT_REGEX = "jersey.config.servlet.filter.staticContentRegex";
124125

125126
/**
126127
* Application configuration initialization property whose value is a fully
@@ -148,6 +149,20 @@ public final class ServletProperties {
148149
*/
149150
public static final String PROVIDER_WEB_APP = "jersey.config.servlet.provider.webapp";
150151

152+
/**
153+
* If {@code true} then query parameters will not be treated as form parameters (e.g. injectable using
154+
* {@link javax.ws.rs.FormParam}) in case a Form request is processed by server.
155+
* <p>
156+
* The default value is {@code false}.
157+
* </p>
158+
* <p>
159+
* The name of the configuration property is <tt>{@value}</tt>.
160+
* </p>
161+
*
162+
* @since 2.16
163+
*/
164+
public static final String QUERY_PARAMS_AS_FORM_PARAMS_DISABLED = "jersey.config.servlet.form.queryParams.disabled";
165+
151166
/**
152167
* Identifies the object that will be used as a parent {@link ServiceLocator} in the Jersey
153168
* {@link WebComponent}.

containers/jersey-servlet-core/src/main/java/org/glassfish/jersey/servlet/WebComponent.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
import javax.ws.rs.RuntimeType;
6262
import javax.ws.rs.core.Form;
6363
import javax.ws.rs.core.MediaType;
64+
import javax.ws.rs.core.MultivaluedMap;
6465
import javax.ws.rs.core.Response;
6566
import javax.ws.rs.core.SecurityContext;
6667

@@ -273,29 +274,40 @@ public void dispose(final WebConfig instance) {
273274
* Jersey application handler.
274275
*/
275276
final ApplicationHandler appHandler;
277+
276278
/**
277279
* Jersey background task scheduler - used for scheduling request timeout event handling tasks.
278280
*/
279281
final ScheduledExecutorService backgroundTaskScheduler;
282+
280283
/**
281284
* Web component configuration.
282285
*/
283286
final WebConfig webConfig;
287+
284288
/**
285289
* If {@code true} and deployed as filter, the unmatched requests will be forwarded.
286290
*/
287291
final boolean forwardOn404;
292+
288293
/**
289294
* Cached value of configuration property
290295
* {@link org.glassfish.jersey.server.ServerProperties#RESPONSE_SET_STATUS_OVER_SEND_ERROR}.
291296
* If {@code true} method {@link HttpServletResponse#setStatus} is used over {@link HttpServletResponse#sendError}.
292297
*/
293298
final boolean configSetStatusOverSendError;
299+
294300
/**
295301
* Asynchronous context delegate provider.
296302
*/
297303
private final AsyncContextDelegateProvider asyncExtensionDelegate;
298304

305+
/**
306+
* Flag whether query parameters should be kept as entity form params if a servlet filter consumes entity and
307+
* Jersey has to retrieve form params from servlet request parameters.
308+
*/
309+
private final boolean queryParamsAsFormParams;
310+
299311
/**
300312
* Create and initialize new web component instance.
301313
*
@@ -318,13 +330,15 @@ public WebComponent(final WebConfig webConfig, ResourceConfig resourceConfig) th
318330
final AbstractBinder webComponentBinder = new WebComponentBinder(resourceConfig.getProperties());
319331
resourceConfig.register(webComponentBinder);
320332

321-
ServiceLocator locator = (ServiceLocator) webConfig.getServletContext().getAttribute(ServletProperties.SERVICE_LOCATOR);
333+
final ServiceLocator locator = (ServiceLocator) webConfig.getServletContext()
334+
.getAttribute(ServletProperties.SERVICE_LOCATOR);
322335

323336
this.appHandler = new ApplicationHandler(resourceConfig, webComponentBinder, locator);
324337

325338
this.asyncExtensionDelegate = getAsyncExtensionDelegate();
326339
this.forwardOn404 = webConfig.getConfigType().equals(WebConfig.ConfigType.FilterConfig)
327340
&& resourceConfig.isProperty(ServletProperties.FILTER_FORWARD_ON_404);
341+
this.queryParamsAsFormParams = !resourceConfig.isProperty(ServletProperties.QUERY_PARAMS_AS_FORM_PARAMS_DISABLED);
328342
this.configSetStatusOverSendError = ServerProperties.getValue(resourceConfig.getProperties(),
329343
ServerProperties.RESPONSE_SET_STATUS_OVER_SEND_ERROR, false, Boolean.class);
330344
this.backgroundTaskScheduler = appHandler.getServiceLocator()
@@ -561,14 +575,17 @@ private void filterFormParameters(final HttpServletRequest servletRequest, final
561575
final String queryString = servletRequest.getQueryString();
562576
final List<String> queryParams = queryString != null ? getDecodedQueryParamList(queryString) : Collections.<String>emptyList();
563577

578+
final boolean keepQueryParams = queryParamsAsFormParams || queryParams.isEmpty();
579+
final MultivaluedMap<String, String> formMap = form.asMap();
580+
564581
while (parameterNames.hasMoreElements()) {
565582
final String name = (String) parameterNames.nextElement();
566583
final List<String> values = Arrays.asList(servletRequest.getParameterValues(name));
567584

568-
form.asMap().put(name, queryParams.isEmpty() ? values : filterQueryParams(name, values, queryParams));
585+
formMap.put(name, keepQueryParams ? values : filterQueryParams(name, values, queryParams));
569586
}
570587

571-
if (!form.asMap().isEmpty()) {
588+
if (!formMap.isEmpty()) {
572589
containerRequest.setProperty(InternalServerProperties.FORM_DECODED_PROPERTY, form);
573590

574591
if (LOGGER.isLoggable(Level.WARNING)) {

core-common/src/main/java/org/glassfish/jersey/ExtendedConfig.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33
*
4-
* Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2012-2015 Oracle and/or its affiliates. All rights reserved.
55
*
66
* The contents of this file are subject to the terms of either the GNU
77
* General Public License Version 2 only ("GPL") or the Common Development
@@ -47,6 +47,7 @@
4747
* @author Marek Potociar (marek.potociar at oracle.com)
4848
*/
4949
public interface ExtendedConfig extends Configuration {
50+
5051
/**
5152
* Get the value of the property with a given name converted to {@code boolean}.
5253
* Returns {@code false} if the value is not convertible.

docs/src/main/docbook/appendix-properties.xml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,99 @@
496496
</table>
497497
</section>
498498

499+
<section xml:id="appendix-properties-servlet">
500+
<title>Servlet configuration properties</title>
501+
502+
<para>
503+
List of servlet configuration properties that can be found in &jersey.servlet.ServletProperties; class.
504+
</para>
505+
506+
<table>
507+
<title>List of servlet configuration properties</title>
508+
<tgroup cols="3">
509+
<thead>
510+
<row>
511+
<entry>Constant</entry>
512+
<entry>Value</entry>
513+
<entry>Description</entry>
514+
</row>
515+
</thead>
516+
<tbody>
517+
<row>
518+
<entry>&jersey.servlet.ServletProperties.FILTER_CONTEXT_PATH;</entry>
519+
<entry><literal>jersey.config.servlet.filter.contextPath</literal></entry>
520+
<entry>
521+
<para>
522+
If set, indicates the URL pattern of the Jersey servlet filter context path.
523+
</para>
524+
</entry>
525+
</row>
526+
<row>
527+
<entry>&jersey.servlet.ServletProperties.FILTER_FORWARD_ON_404;</entry>
528+
<entry><literal>jersey.config.servlet.filter.forwardOn404</literal></entry>
529+
<entry>
530+
<para>
531+
If set to <literal>true</literal> and a 404 response with no entity body is returned from either
532+
the runtime or the application then the runtime forwards the request to the next filter in the
533+
filter chain. This enables another filter or the underlying servlet engine to process the request.
534+
Before the request is forwarded the response status is set to 200.
535+
</para>
536+
</entry>
537+
</row>
538+
<row>
539+
<entry>&jersey.servlet.ServletProperties.FILTER_STATIC_CONTENT_REGEX;</entry>
540+
<entry><literal>jersey.config.servlet.filter.staticContentRegex</literal></entry>
541+
<entry>
542+
<para>
543+
If set the regular expression is used to match an incoming servlet path URI to some web page
544+
content such as static resources or JSPs to be handled by the underlying servlet engine.
545+
</para>
546+
</entry>
547+
</row>
548+
<row>
549+
<entry>&jersey.servlet.ServletProperties.JAXRS_APPLICATION_CLASS;</entry>
550+
<entry><literal>javax.ws.rs.Application</literal></entry>
551+
<entry>
552+
<para>
553+
Application configuration initialization property whose value is a fully qualified class name of a
554+
class that implements JAX-RS Application.
555+
</para>
556+
</entry>
557+
</row>
558+
<row>
559+
<entry>&jersey.servlet.ServletProperties.PROVIDER_WEB_APP;</entry>
560+
<entry><literal>jersey.config.servlet.provider.webapp</literal></entry>
561+
<entry>
562+
<para>
563+
Indicates that Jersey should scan the whole web app for application-specific resources and
564+
providers.
565+
</para>
566+
</entry>
567+
</row>
568+
<row>
569+
<entry>&jersey.servlet.ServletProperties.QUERY_PARAMS_AS_FORM_PARAMS_DISABLED;</entry>
570+
<entry><literal>jersey.config.servlet.form.queryParams.disabled</literal></entry>
571+
<entry>
572+
<para>
573+
If <literal>true</literal> then query parameters will not be treated as form parameters
574+
(e.g. injectable using @FormParam) in case a Form request is processed by server.
575+
</para>
576+
</entry>
577+
</row>
578+
<row>
579+
<entry>&jersey.servlet.ServletProperties.SERVICE_LOCATOR;</entry>
580+
<entry><literal>jersey.config.servlet.context.serviceLocator</literal></entry>
581+
<entry>
582+
<para>
583+
Identifies the object that will be used as a parent ServiceLocator in the Jersey WebComponent.
584+
</para>
585+
</entry>
586+
</row>
587+
</tbody>
588+
</tgroup>
589+
</table>
590+
</section>
591+
499592
<section xml:id="appendix-properties-client">
500593
<title>Client configuration properties</title>
501594

docs/src/main/docbook/deployment.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,7 @@ public class MyApplication extends ResourceConfig {
908908
<title>Jersey Servlet container modules</title>
909909

910910
<para>
911-
Jersey uses its own <literal>&jersey.containers.ServletContainer;</literal> implementation of Servlet and
911+
Jersey uses its own <literal>&jersey.servlet.ServletContainer;</literal> implementation of Servlet and
912912
Servlet Filter API to integrate with Servlet containers. As any JAX-RS runtime, Jersey provides support
913913
for Servlet containers that support Servlet specification version 2.5 and higher. To support JAX-RS 2.0
914914
asynchronous resources on top of a Servlet container, support for Servlet specification version 3.0 or higher

0 commit comments

Comments
 (0)