èªåãæ¯åæ°è¦ã§ ASP.NET MVC ã¢ããªã±ã¼ã·ã§ã³ã®éçºãå§ããã¨ãã«å¿ããã®ã§ãä»ã¾ã§ããã°ã«æ¸ããåãã¾ã¨ãã¦ã¿ã¾ããã
ASP.NET MVC 5 ã¨éå®ãã¦ããã®ã¯ã5 ããåã®ãã¼ã¸ã§ã³ã§ã¯ãã°æã¡ã®è¨å®ãç´¹ä»ãã¦ããããã§ãã
Razor ã®ã¿ã使ã
ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new RazorViewEngine());
ã¢ãã¤ã«ãã¥ã¼ãç¡å¹ã«ãã
DisplayModeProvider.Instance.Modes.Clear();
DisplayModeProvider.Instance.Modes.Add(new DefaultDisplayMode());
çæããã URL ãå°æåã«ãã
public static void RegisterRoutes(RouteCollection routes) { routes.LowercaseUrls = true; }
çæããã URL ã®æå¾ã«ã¹ã©ãã·ã¥ãä»ãã
public static void RegisterRoutes(RouteCollection routes) { routes.AppendTrailingSlash = true; }
èªè¨¼ã¯ããã¼ã®ååã夿´ãã
<authentication mode="Forms"> <forms name="auth" /> </authentication>
CSRF ç¨ã¯ããã¼ã®ååã夿´ãã
AntiForgeryConfig.CookieName = "token";
ã»ãã·ã§ã³ã¯ããã¼ã®ååã夿´ãã
<system.web> <sessionState cookieName="session" /> </system.web>
èªè¨¼ã¯ããã¼ã§ SSL ãå¿ é ã«ãã
<authentication mode="Forms"> <forms requireSSL="true" /> </authentication>
CSRF ç¨ã¯ããã¼ã§ SSL ãå¿ é ã«ãã
AntiForgeryConfig.RequireSsl = true;
èªè¨¼ã¯ããã¼ä»¥å¤ã« httpOnly, secure 屿§ã追å ãã
<system.web> <httpCookies httpOnlyCookies="true" requireSSL="true" /> </system.web>
AntiForgery ä½¿ç¨æã« X-Frame-Options ããããåºåããªã
AntiForgeryConfig.SuppressXFrameOptionsHeader = true;
ã¬ã¹ãã³ã¹ãããã« ASP.NET ã®ãã¼ã¸ã§ã³ãåºåããªã
<system.web> <httpRuntime targetFramework="4.5" enableVersionHeader="false" /> </system.web>
ã¬ã¹ãã³ã¹ãããã« ASP.NET MVC ã®ãã¼ã¸ã§ã³ãåºåããªã
MvcHandler.DisableMvcResponseHeader = true;
ã¬ã¹ãã³ã¹ãããã« X-Powered-By ãåºåããªã
<system.webServer> <httpProtocol> <customHeaders> <remove name="X-Powered-By" /> </customHeaders> </httpProtocol> </system.webServer>
ã¬ã¹ãã³ã¹ãããã« Server ãåºåããªã
protected void Application_PreSendRequestHeaders() { Response.Headers.Remove("Server"); }
IP ã¢ãã¬ã¹ã§ã¢ã¯ã»ã¹å¶éãè¡ã
<system.webServer> <security> <ipSecurity allowUnlisted="false" denyAction="NotFound"> <add allowed="true" ipAddress="127.0.0.1"/> <add allowed="true" ipAddress="::0"/> </ipSecurity> </security> </system.webServer>
æå¾ã®æ¹ã¯è¨å®ã¨ããæãã§ã¯ãªãã£ãã§ãããã¾ãæ°ã«ããªãæ¹åã§ãé¡ããã¾ãã