C# 스테이션 간 스크립트 주입 방지 SXX
//Global.asax
<%@ Application Language="C#" %>
<script runat="server">
void Application_Start(object sender, EventArgs e)
{
//
}
void Application_End(object sender, EventArgs e)
{
//
}
void Application_Error(object sender, EventArgs e)
{
//
}
void Session_Start(object sender, EventArgs e)
{
//
}
void Session_End(object sender, EventArgs e)
{
// 。
// : Web.config sessionstate
// InProc , Session_End 。
// StateServer SQLServer, 。
WebContel_damu m_delsession = new WebContel_damu();
m_delsession.CheckLogin_del(Session["user"].ToString());
}
void Application_BeginRequest(object sender, EventArgs e)
{
string q = "
, !";
if (Request.Cookies != null)
{
if (Nvs_Net_Safe.CookieData())
{
Response.Write(q);
Response.End();
}
}
if (Request.UrlReferrer != null)
{
if (Nvs_Net_Safe.referer())
{
Response.Write(q);
Response.End();
}
}
if (Request.RequestType.ToUpper() == "POST")
{
if (Nvs_Net_Safe.PostData())
{
Response.Write(q);
Response.End();
}
}
if (Request.RequestType.ToUpper() == "GET")
{
if (Nvs_Net_Safe.GetData())
{
Response.Write(q);
Response.End();
}
}
}
</script>
//Nvs_Net_Safe
using System;
using System.Web;
using System.Text;
using System.Text.RegularExpressions;
public class Nvs_Net_Safe
{
// private const string StrRegex = @"\b(and|or)\b.{1,6}?(=|>|
private const string StrRegex = @"]+?style=[\w]+?:expression\(|\b(alert|confirm|prompt)\b|^\+/v(8|9)|]*?=[^>]*?[^>]*?>|\b(and|or)\b.{1,6}?(=|>|;
public static bool PostData()
{
bool result = false;
for (int i = 0; i < HttpContext.Current.Request.Form.Count; i++)
{
result = CheckData(HttpContext.Current.Request.Form[i].ToString());
if (result)
{
break;
}
}
return result;
}
public static bool GetData()
{
bool result = false;
for (int i = 0; i < HttpContext.Current.Request.QueryString.Count; i++)
{
result = CheckData(HttpContext.Current.Request.QueryString[i].ToString());
if (result)
{
break;
}
}
return result;
}
public static bool CookieData()
{
bool result = false;
for (int i = 0; i < HttpContext.Current.Request.Cookies.Count; i++)
{
result = CheckData(HttpContext.Current.Request.Cookies[i].Value.ToLower());
if (result)
{
break;
}
}
return result;
}
public static bool referer()
{
bool result = false;
return result = CheckData(HttpContext.Current.Request.UrlReferrer.ToString());
}
public static bool CheckData(string inputData)
{
if (Regex.IsMatch(inputData, StrRegex))
{
return true;
}
else
{
return false;
}
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.