`

HOWTO: Disable HTTP Methods in Tomcat Introduction

 
阅读更多

HOWTO: Disable HTTP Methods in Tomcat

Introduction

In the Apache web server, if you want to disable access to specific methods, you can take advantage of mod_rewrite and disable just about anything, often with only one or two lines of configuration file entries. In Apache Tomcat, security is enforced by way of security constraints that are built into the Java Servlet specification. These are not contained within the main server.xml file within tomcat but within the web.xml configuration file.

The Java Servlet specification contains a fairly complete collection of security-related configuration parameters that allows you to do, among other things, disable HTTP methods, enable SSL on specific URIs, and allow access to specific resources based upon user role. Security constraints are the way to protect web content within Java-based applications. One common item that crops up in security related scans are HTTP methods allowed on a web site or within a web application. For those of us running our web sites using Apache Tomcat and not a front-end web server like Apache or IIS, having a good understanding of how security constraints work will be vital. This particular HOWTO will examine the steps necessary to disable access to specific HTTP methods.

A security constraint utilizes an xml syntax, just like other configuration directives in web.xml. Values in the examples are bolded to provide better readability. Example 1 is a basic web site, which serves up nothing but JSPs, images, scripts, and styles and does not contain any forms for a user to fill out. Network Security wants all HTTP methods disabled with the exception of HTTP HEAD and GET requests.

Example 1 - Basic Web Site - No Forms

01 // Sample Security Constraint
02  <security-constraint>
03  <web-resource-collection>
04   <web-resource-name><strong>restricted methods</strong></web-resource-name>
05   <url-pattern><strong>/*</strong></url-pattern>
06   <http-method><strong>PUT</strong></http-method>
07   <http-method><strong>POST</strong></http-method>
08   <http-method><strong>DELETE</strong></http-method>
09   <http-method><strong>OPTIONS</strong></http-method>
10   <http-method><strong>TRACE</strong></http-method>
11  </web-resource-collection>
12  <auth-constraint />
13  </security-constraint>

All constraints start out with a <security-contraint> deployment descriptor. The <web-resource-collection> comprises a set of URIs and HTTP Methods that are allowable within that set of URIs. In the example above, a <url-pattern>of /* (meaning everything under the root of the web site has been constrained to only allow access to GET andHEAD only. Setting an authorization constraint to <auth-constraint />, sets an All Users policy so this example literally means: "For any user, deny access to PUT, POST, DELETE, OPTIONS, and TRACE methods". In a stock Tomcat installation, if I were to send an HTTP OPTIONS request, for example, to the web site, it would work. In my newly constrained configuration, OPTIONS requests now fail with an HTTP Status code of 403 - Forbidden.

The second example below takes our basic web site example a step further where a "Contact Us" form has been made available. The site user would fill out a form located under /contact and data would be passed using HTTP POST.

Example 2 - Basic Web Site with Contact Form

01 // Sample Security Constraint
02  <security-constraint>
03  <web-resource-collection>
04   <web-resource-name><strong>restricted methods</strong></web-resource-name>
05   <url-pattern><strong>/*</strong></url-pattern>
06   <http-method><strong>PUT</strong></http-method>
07   <http-method><strong>POST</strong></http-method>
08   <http-method><strong>DELETE</strong></http-method>
09   <http-method><strong>OPTIONS</strong></http-method>
10   <http-method><strong>TRACE</strong></http-method>
11  </web-resource-collection>
12  <auth-constraint />
13  </security-constraint>
14  
15  <security-constraint>
16  <web-resource-collection>
17   <web-resource-name><strong>Contact Form</strong></web-resource-name>
18   <url-pattern><strong>/contact/*</strong></url-pattern>
19   <http-method><strong>PUT</strong></http-method>
20   <http-method><strong>DELETE</strong></http-method>
21   <http-method><strong>OPTIONS</strong></http-method>
22   <http-method><strong>TRACE</strong></http-method>
23  </web-resource-collection>
24  <auth-constraint />
25  </security-constraint>

The constraints here mimic the constraints from the previous example but a secondary set of constraints are applied if the URI pattern matches /contact/*. In this case, the allowable methods are GET, HEAD, and POST.

Conclusion

Security Constraints, although not as complete as those one might find in the Apache Web Server, are a pretty useful way of protecting web applications. This HOWTO concentrated on disabling HTTP methods on specified URIs but you can do quite a bit more with security constraints and future articles will cover these.

分享到:
评论
发表评论

文章已被作者锁定,不允许评论。

相关推荐

    无 adb disable-verity 命令的adb应用程序

    此adb中无adb disable-verity命令,如果在cmd中输入以上命令会报 /system/bin/sh: disable-verity: not found 的错误。具体可看本人的文章 ”/system/bin/sh: disable-verity: not found 的解决方案“ 【使用方式】...

    WordPress原创插件:disable-gutenberg禁用古腾堡编辑器和小工具

    WordPress原创插件:disable-gutenberg禁用古腾堡编辑器和小工具

    (免费)提供 adb -disable-verity 支持

    此adb工具包中包含了adb disable-verity命令,这里免费提供给大家使用,具体可看本人的文章 ”/system/bin/sh: disable-verity: not found 的解决方案“ 【使用方式】 platform-tools解压后即可使用。在cmd中通过cd...

    Android代码-屏蔽home按键

    As there are a lot questions about "how to disable home button in android?" on Stack Overflow, such as how to disable home button in android? Android - Is It possible to disable the click of home ...

    LCD.rar_LCD PWM_ht46r22_io lcd_mcu驱动LCD_source

    IIC: DISABLE PFD: DISABLE PWM: DISABLE WDT: ENABLE CLRWDT: ONE WDT CLOCK SOURCE: T1 WDT TIME OUT SELECT: WDT CLOCK SOURCE/32768 LVR: DISABLE OSC: CRYSTAL SYSVOLT: 3.0V SYSFRAG: 4000KHZ ...

    NMI_watchdog 配置说明

    NMI_watchdog 配置说明 NMI_watchdog 是一种用于记录系统死机日志的机制,它可以在系统崩溃时触发 kdump,记录死机日志,并分析死机的原因。下面是 NMI_watchdog 配置说明的相关知识点: NMI_watchdog 的编写目的 ...

    KBA_160615010248_2_how_to_disable_QC3_0_.pdf

    ### 如何关闭QC3.0 #### 背景与概述 QC3.0(Quick Charge 3.0)是高通公司推出的一种快速充电技术,旨在为移动设备提供更加快速、高效的充电体验。然而,在某些情况下,用户或制造商可能需要禁用这一功能,比如在...

    How to disable_enable a timing check in a design.pdf

    后仿

    This shows how to disable control alt and delete by tricking

    This shows how to disable control alt and delete by tricking the computer into thinking that the screensaver is running.

    adb,支持adb disable-verity命令,解锁system分区

    `adb disable-verity` 是一个特定的adb命令,它涉及到Android系统的安全特性——verity模式。 verity模式是Android为了增强设备的安全性而引入的一种机制。它通过校验系统分区的哈希值来确保系统文件未被篡改,从而...

    VS错误提示:To disable deprecation, use _CRT_SECURE_NO_WARNINGS.

    Severity Code Description ... To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. 解决方案:更改预处理定义 右击项目名,选择Properties 在c/c++下选择Preprocessor 点击图

    centOS7环境下安装openjdk和tomcat文档

    ### CentOS7环境下安装OpenJDK和Tomcat详细指南 #### 一、安装OpenJDK **1.1 查看CentOS自带JDK是否已安装** 首先,我们需要确认系统中是否已经安装了Java运行环境(JRE)或Java开发工具包(JDK)。这一步非常...

    adb-disable-verity

    "adb-disable-verity"是一个与Android设备管理相关的主题,它涉及到ADB(Android Debug Bridge)工具的使用,特别是针对系统验证功能“verity”的禁用过程。在Android系统中,verity是一种安全特性,用于确保系统...

    tomcat-7_API_帮助文档

    have a JDK that is up to date, or disable sendfile behavior in the Connector. 6427312: (fc) FileChannel.transferTo() throws IOException "system call interrupted" 5103988: (fc) FileChannel....

    属性页VC源代码:disable_tab

    标题"属性页VC源代码:disable_tab"暗示我们关注的是如何在属性页中禁用某个特定的选项卡。 `disable_tab`这个关键词可能指的是一个功能,即在运行时禁止用户切换到特定的选项卡。在MFC中,我们可以通过修改`...

    google字体插件-disable-google-fonts

    WordPress的插件:google字体插件-disable-google-fonts 解压后,请将目录名称:wordpress1,修改为:disable-google-fonts

    This is a straight forward example of how to disable any Win

    标题中的“如何禁用Win95/98窗口”表明这是一个关于操作系统,特别是Windows 95和98的教程,具体涉及的是系统界面的自定义和管理。在早期的Windows操作系统中,用户可能会出于安全、性能优化或者个性化需求,想要...

    将Web项目War包部署到Tomcat服务器基本步骤

    -- Uncomment this to disable session persistence across Tomcat restarts --&gt; &lt;!-- --&gt; &lt;!-- Database connection pool configuration --&gt; type="javax.sql.DataSource" maxActive="100" maxIdle="30" ...

    UE(官方下载)

    How to enable and disable autocorrect keywords with syntax highlighting Insert Menu Commands UltraEdit includes several special insert functions under the Insert menu. You can use these functions to ...

    tomcat7使用redis管理session需要的jar包

    -- Uncomment this to disable session persistence across Tomcat restarts --&gt; &lt;!-- --&gt; &lt;!-- Uncomment this to enable Comet connection tacking (provides events on session expiration as well as ...

Global site tag (gtag.js) - Google Analytics