Skip to content

Commit

Permalink
[JENKINS-23378] Servlet 3.1
Browse files Browse the repository at this point in the history
Start declaring servlet 3.1 dependency
  • Loading branch information
kohsuke committed Feb 25, 2016
1 parent da91c95 commit 8713646
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 31 deletions.
4 changes: 2 additions & 2 deletions core/pom.xml
Expand Up @@ -243,8 +243,8 @@ THE SOFTWARE.
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
29 changes: 3 additions & 26 deletions core/src/main/java/hudson/WebAppMain.java
Expand Up @@ -117,7 +117,9 @@ public Locale get() {

installLogger();

markCookieAsHttpOnly(context);
// Set the session cookie as HTTP only.
// See https://www.owasp.org/index.php/HttpOnly for the discussion of this topic in OWASP
context.getSessionCookieConfig().setHttpOnly(true);

final FileAndDescription describedHomeDir = getHomeDir(event);
home = describedHomeDir.file.getAbsoluteFile();
Expand Down Expand Up @@ -254,31 +256,6 @@ public void run() {
}
}

/**
* Set the session cookie as HTTP only.
*
* @see <a href="https://www.owasp.org/index.php/HttpOnly">discussion of this topic in OWASP</a>
*/
private void markCookieAsHttpOnly(ServletContext context) {
try {
Method m;
try {
m = context.getClass().getMethod("getSessionCookieConfig");
} catch (NoSuchMethodException x) { // 3.0+
LOGGER.log(Level.FINE, "Failed to set secure cookie flag", x);
return;
}
Object sessionCookieConfig = m.invoke(context);

// not exposing session cookie to JavaScript to mitigate damage caused by XSS
Class scc = Class.forName("javax.servlet.SessionCookieConfig");
Method setHttpOnly = scc.getMethod("setHttpOnly",boolean.class);
setHttpOnly.invoke(sessionCookieConfig,true);
} catch (Exception e) {
LOGGER.log(Level.WARNING, "Failed to set HTTP-only cookie flag", e);
}
}

public void joinInit() throws InterruptedException {
initThread.join();
}
Expand Down
7 changes: 4 additions & 3 deletions war/src/main/webapp/WEB-INF/web.xml
Expand Up @@ -23,10 +23,11 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1"
metadata-complete="true">
<display-name>Jenkins v${project.version}</display-name>
<description>Build management system</description>

Expand Down

0 comments on commit 8713646

Please sign in to comment.