tomcat禁止访问文件与文件目录
最近项目扫描的时候遇到一个问题,需要在tomcat中限制对包含项目信息文件的访问,在使用eclipse写项目是,会生成一个.project文件,这个文件里面包含了项目的关键信息,而且有时候删除扔能继续访问,于是只能对这个文件限制web访问,否则会存在安全漏洞,以下是解决办法:
在tomcat/conf/web.xml中加入以下代码
<security-constraint>
<display-name>Forbidden</display-name>
<web-resource-collection>
<web-resource-name>aaa</web-resource-name><!--//填入要保护的项目名-->
<url-pattern>/.project</url-pattern><!--//填入需要被限制的文件路径-->
</web-resource-collection>
<auth-constraint>
<role-name/>
</auth-constraint>
</security-constraint>
tomcat访问报错跳转
设置自定义的项目报错页面,同样在web.xml中添加:
<error-page>
<error-code>403</error-code>
<location>/error/authlimit.jsp</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/error/pagenotfound.jsp</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/error/servererror.jsp</location>
</error-page>
访问找不到页面 根据情况进行调整即可
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ page import="org.jxstar.util.config.SystemVar,
org.jxstar.security.LicenseVar,
java.util.Map,
org.jxstar.util.factory.FactoryUtil,
org.jxstar.control.login.OneLoginUtil" %>
<%
String contextpath = request.getContextPath();
%>
<!DOCTYPE html>
<html>
<head>
<title>403</title>
<meta name="keywords" content="keyword1,keyword2,keyword3">
<meta name="description" content="this is my page">
<meta name="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
<style>
body{
background-color:#1196EE;
}
img{
width:300px;
}
.error-info{
width:30%;
margin:5% 35%;
text-align:center;
}
.error-desc span{
color:#eee;
font-size:18px;
}
</style>
</head>
<body>
<div class="error-info">
<img src="<%=contextpath %>/resources/images/error/403.png" />
<div class="error-desc">
<span>Sorry,您访问的页面不存在</span>
</div>
</div>
</body>
</html>