温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

jspxcms中怎样使用jsp文件

发布时间:2022-01-19 15:43:35 来源:亿速云 阅读:137 作者:柒染 栏目:开发技术

这篇文章给大家介绍jspxcms中怎样使用jsp文件,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

系统中默认禁止jsp的访问。允许jsp访问容易导致一些漏洞,最为常见的攻击方式是通过上传jsp文件获取webshell。

在com.jspxcms.core.ShiroConfig中定义了对jsp jspx后缀的过滤。

    @Bean
    public FilterRegistrationBean jspDispatcherFilterRegistrationBean() {
        FilterRegistrationBean filterRegistration = new FilterRegistrationBean();
        filterRegistration.setFilter(new JspDispatcherFilter());
        filterRegistration.setEnabled(true);
        filterRegistration.addInitParameter("prefix", "/jsp");
        filterRegistration.addUrlPatterns("*.jsp");
        filterRegistration.addUrlPatterns("*.jspx");
        filterRegistration.setDispatcherTypes(DispatcherType.REQUEST);
        return filterRegistration;
    }

其中com.jspxcms.common.web.JspDispatcherFilter就是过滤器。

    /**
     * 是否允许访问 JSP 或 JSPX 文件。默认 false 。
     */
    private boolean allowed = false;
    /**
     * 请求转发地址前缀。只允许特定目录的 jsp(jspx) 允许被访问。默认为 /jsp 。比如访问 /abc.jsp 通过请求转发实际上访问的文件为 /jsp/abc.jsp 。
     */
    private String prefix = "/jsp";

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        if (!allowed) {
            ((HttpServletResponse) response).sendError(HttpServletResponse.SC_FORBIDDEN, "JSP Access Denied");
            return;
        }
        HttpServletRequest req = (HttpServletRequest) request;
        String uri = req.getRequestURI();
        String ctx = req.getContextPath();
        if (StringUtils.isNotBlank(ctx)) {
            uri = uri.substring(ctx.length());
        }
        request.getRequestDispatcher(prefix + uri).forward(request, response);
    }

    public void init(FilterConfig filterConfig) throws ServletException {
        String allowed = filterConfig.getInitParameter("allowed");
        if ("true".equals(allowed)) {
            this.allowed = true;
        }
        String prefix = filterConfig.getInitParameter("prefix");
        if (StringUtils.isNotBlank(prefix)) {
            this.prefix = prefix;
        }
    }

在这个过滤器中默认不允许任何jsp的直接访问。但对于某些一定需要使用jsp的情况,预留了一个相对安全的访问jsp的方法。就是所有的jsp请求,都转发到/jsp目录下,这防止了攻击者将jsp文件上传到uploads等目录导致的攻击。因为只有上传到/jsp目录的jsp文件才能被访问。

可以修改JspDispatcherFilter的private boolean allowed = true;。然后将jsp文件放到/jsp目录中。比如创建/jsp/abc.jsp文件,访问路径是/abc.jsp。

关于jspxcms中怎样使用jsp文件就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI