0
下記の乱雑なHTML構文について私のお詫び申し上げます。 http.authorizeRequest()
csrfを有効にすると、403エラーが発生します。もちろん、もし私がcsrf.disable()
を持っていれば、すべて正常に動作します。なぜSpring csrfは私に403ネットワークエラーを与えますか?
<form:form>
タグが自動的にCSRFトークンを使用したことは理解していますが、これは以下のURLが機能しなくなるためです。
誰かが私が理解していないことを教えてもらえますか?
NetworkError: 403 Forbidden - http://localhost:8080/AssetCore/createGuideline/
マイConfigurationクラス:
@SuppressWarnings("deprecation")
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter{
private final Logger log = Logger.getLogger (this.getClass());
/**
* This class gets called during startup.
*/
/**
* Configure http security.
*/
@Override
protected void configure(HttpSecurity http) throws Exception {
/**
* This method gets called when the app starts up.
* I believe that all the patterns for the MVC and rest calls will need to go here.
*/
log.info("configure(): called to set up authorizedRequest pattern matching.");
http
.logout().logoutSuccessUrl("/login?loggedout=true").invalidateHttpSession(true).deleteCookies("JSESSIONID")
.logoutRequestMatcher(new AntPathRequestMatcher("/logout"));
http.authorizeRequests()
.antMatchers(HttpMethod.PUT, "/assessment/**").permitAll()
.antMatchers("/createGuideline/**",).permitAll()
}
JSP:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags"%>
<%@ taglib prefix="ark" tagdir="/WEB-INF/tags" %>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="content-type"
content="text/html; charset=windows-1252">
<meta charset="utf-8">
<title>ASSET Core - PCC</title>
<jsp:include page="ourCSSandJS.jsp" />
<link rel="stylesheet" href="/AssetCore/resources/css/pccStyle.css">
<link rel="stylesheet" href="/AssetCore/resources/css/scrollbar.css">
<link rel="stylesheet" href="/AssetCore/resources/css/mcp_style.css">
<script>var storedFormatExtraArgs = [];</script>
<script src="/AssetCore/resources/js/valid/pcc.js"></script>
<script src="/AssetCore/resources/js/controlFormatting.js"></script>
<script src="/AssetCore/resources/js/valid/controlCard.js"></script>
<script src="/AssetCore/resources/js/thirdParty/jquery.scrollbar.min.js"></script>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
</head>
<body>` <form:form id="customGuide" method="POST"
action="/AssetCore/createGuideline">
<fieldset>
<legend id="createGuideline">Create Guideline</legend>
<p>
<label for="gName">Name</label><br /> <input type="text"
id="gName" name="gName" />
</p>`
一見すると、うまくいくはずです。 Chromeで試してみて、ネットワークインスペクタでcsrfトークンがフォームの投稿に含まれているかどうか確認してください。 – Taylor
そうは思わない。これは私が得たものである:リクエストURLます。http:// localhost:8080/AssetCore/createGuideline/ リクエスト方法:POST ステータスコード:403禁止 リモートアドレス:[:: 1]:8080 レスポンスヘッダ ソースを表示 キャッシュコントロール:no-cache、no-store、max-age = 0、must-revalidate コンテンツ言語:en-US コンテンツの長さ:2106 コンテンツタイプ:text/html; charset = ISO-8859- 1 日付:金、2016年9月16日19時14分44秒GMT が有効期限:0 プラグマ:キャッシュなし サーバー:Apacheの-コヨーテ/ 1.1 X-Content-Typeの-オプション: X-フレーム・オプションnosniff: DENY X-XSS保護:1; mode = block リクエストヘッダー – DenisMP
リクエストボディにあるドキュメントを誤解しない限り、それはレスポンスヘッダーです(私は思います)。 – Taylor