[研究]Forify SCA 的 Open Redirect 問題(四)用 ASP.NET + JavaScript 來解決
2021-08-10
[研究]Forify SCA 的 Open Redirect 問題(一)重導 Response.Redirect() 與 Server.Transfer()
https://shaurong.blogspot.com/2021/07/aspnetfortify-sca-open-redirect.html
[研究]Forify SCA 的 Open Redirect 問題(二)ckeditor 的 tmpFrameset.html
https://shaurong.blogspot.com/2021/07/aspnetfortify-scatmpframesethtmlopen.html
[研究]Forify SCA 的 Open Redirect 問題(三)回到上一頁按鈕、返回按鈕https://shaurong.blogspot.com/2021/08/aspnet-fortify-scaopen-redirect.html
[研究]Forify SCA 的 Open Redirect 問題(四)用 ASP.NET + JavaScript 來解決http://shaurong.blogspot.com/2021/08/forify-sca-open-redirect-aspnet.html
突然想到 ASP.NET + JavaScript 方式可否順利重導,不被 Micro Focus Forify SCA (Static Code Analyzer ) 原始碼掃描 報告有 Open Redirect 問題呢?測試了一下
protected void Button4_Click(object sender, EventArgs e)
{
// similar behavior as an HTTP redirect
// Fortify SCA 的 Open Redirect 問題過關
Response.Write("<script language=javascript>window.location.replace('http://www.hinet.net');</script>");
}
protected void Button5_Click(object sender, EventArgs e)
{
// similar behavior as clicking on a link
// Fortify SCA 的 Open Redirect 問題過關
Response.Write("<script language=javascript>window.location.href = 'http://www.hinet.net';</script>");
}
protected void Button6_Click(object sender, EventArgs e)
{
// similar behavior as an HTTP redirect
// 把網址手動改成 http://localhost:1669/Default2.aspx?reurl=www.hinet.net ,測試失敗,
// 網址變成 http://localhost:1669/www.hinet.net
// 把網址手動改成 http://localhost:1669/Default2.aspx?reurl=http://www.hinet.net ,測試成功
// Fortify SCA 的 Open Redirect 問題過關
string reUrl = Request.QueryString["reUrl"].ToString();
Response.Write("<script language=javascript>window.location.replace('" + reUrl + "');</script>");
}
protected void Button7_Click(object sender, EventArgs e)
{
// similar behavior as clicking on a link
// 把網址手動改成 http://localhost:1669/Default2.aspx?reurl=www.hinet.net ,測試失敗
// 網址依然沒變,畫面也沒轉走
// 把網址手動改成 http://localhost:1669/Default2.aspx?reurl=http://www.hinet.net ,測試失敗,
// 網址變成 http://localhost:1669/Default2.aspx?reurl=http%3a%2f%2fwww.hinet.net ,畫面沒轉走
// Fortify SCA 的 Open Redirect 問題過關
string reUrl = Request.QueryString["reUrl"].ToString();
Response.Write("<script language=javascript>window.location.href = ''" + reUrl + "'';</script>");
}
protected void Button8_Click(object sender, EventArgs e)
{
// similar behavior as clicking on a link
// 把網址手動改成 http://localhost:1669/Default2.aspx?reurl=www.hinet.net ,測試失敗
// 網址依然沒變,畫面也沒轉走
// 把網址手動改成 http://localhost:1669/Default2.aspx?reurl=http://www.hinet.net ,測試成功,
// Fortify SCA 會報告 Open Redirect 問題
string reUrl = Request.QueryString["reUrl"].ToString();
Response.Redirect(reUrl);
} |
終於找到一個不用 Server.Transfer(),而且轉址的參數是變動的的解法。
(甚至可以是外部網址)
(完)
沒有留言:
張貼留言