Nug*_*ugs 0 c# httpmodule httpcontext
我发现这个伟大的小HttpModule加密和解密所有的查询字符串.它可以在这里找到:HttpModule用于查询字符串加密
有一个主要的缺陷,我真的可以使用一些如何解决的输入.在页面的回发中,跳过HttpMethod POST并且QueryString被解密显示.显然这是一个重大的安全风险.
void context_BeginRequest(object sender, EventArgs e)
{
try
{
HttpContext context = HttpContext.Current;
if (context.Request.Url.OriginalString.Contains("aspx") && context.Request.RawUrl.Contains("?"))
{
string query = ExtractQuery(context.Request.RawUrl);
string path = GetVirtualPath();
if (query.StartsWith(PARAMETER_NAME, StringComparison.OrdinalIgnoreCase))
{
// Decrypts the query string and rewrites the path.
string rawQuery = query.Replace(PARAMETER_NAME, string.Empty);
string decryptedQuery = Decrypt(rawQuery);
context.RewritePath(path, string.Empty, decryptedQuery);
}
else if (context.Request.HttpMethod == "GET")
{
// Encrypt the query string and redirects to the encrypted URL.
// Remove if you don't want all query strings to be encrypted automatically.
string encryptedQuery = Encrypt(query);
context.Response.Redirect(path + encryptedQuery);
}
}
}
catch (ThreadAbortException)
{
//do nothing. let it pass
}
catch (Exception exc)
{
ReportError(exc);
}
}
Run Code Online (Sandbox Code Playgroud)
我试着为POST方法添加一个if:
else if (context.Request.HttpMethod == "POST")
{
if (!query.StartsWith(PARAMETER_NAME, StringComparison.OrdinalIgnoreCase))
{
string encryptedQuery = Encrypt(query);
context.Response.Redirect(path + encryptedQuery);
}
}
Run Code Online (Sandbox Code Playgroud)
然而,这会重新加载页面,因为Response.Redirect,所以PostBack是无用的.
有没有人有任何想法或知道是否有办法确定HttpContext是一个PostBack?
小智 6
在查询字符串中发送敏感数据不是一个好主意.如果您必须在构建查询字符串之前更好地加密数据,而不是加密整个查询字符串.此外,用户更改查询字符串也不应损害您的网站.URI将用户带到他想去的地方,因此通过更改查询字符串(URI)进行导航是Web的标准.网络应该是RestFul.
| 归档时间: |
|
| 查看次数: |
2206 次 |
| 最近记录: |