[研究][ASP.NET] Fortify SCA、回到上一頁、Open Redirect 測試
2021-08-10
2022-06-29 更新
續這篇
[研究][ASP.NET]Micro Focus Fortify Static Code Analyzer (SCA) 報告Response.Redirect有Open Redirect問題
http://shaurong.blogspot.com/2021/07/aspnetfortify-sca-open-redirect.html
Micro Focus Fortify SCA ( Static Code Analyzer ) 源碼掃描工具對某些轉址會報告 Open Redirect 問題,本篇測試「回到上一頁」按鈕 (「返回」按鈕) 的幾種做法,是否可以通過 Open Redirect 檢查。
環境:Visual Studio 2019 + WebFrom + Web Application + C#
Default.aspx (如下)
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="URLBugDemo.Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:HyperLink ID="HyperLink1" NavigateUrl="Default2.aspx" runat="server">Default2.aspx</asp:HyperLink><br />
或<br />
<a href="Default2.aspx">Default2.aspx</a>
</div>
</form>
</body>
</html> |
Default.aspx.cs
namespace URLBugDemo
{
public partial class Default : System.Web.UI.Page
{
}
} |
Default2.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default2.aspx.cs" Inherits="URLBugDemo.Default2" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="button" onclick="javascript:window.history.go(-1);"value="返回上一頁1" />
<a href="#" onclick="javascript:history.back();">返回前一頁2</a>
<asp:Button ID="Button1" runat="server" Text="返回上一頁3" OnClick="Button1_Click" />
<asp:Button ID="Button2" runat="server" Text="返回上一頁4" OnClick="Button2_Click" />
<asp:Button ID="Button3" runat="server" Text="返回上一頁5" OnClick="Button3_Click" />
</div>
</form>
</body>
</html>
|
Default2.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security.AntiXss;
namespace URLBugDemo
{
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// 除非有 100% 把握這一頁一定從別網頁連過來,
// 否則應該要測試 Request.UrlReferrer 是否為 null
// 否則會出現「並未將物件參考設定為物件的執行個體。」
if (Request.UrlReferrer != null)
ViewState["UrlReferrer"] = Request.UrlReferrer.ToString();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
// 會看到舊的、Cache 住的畫面
// 測試正常,Fortify SCA 不會報告 Open Redirect |
********************************************************************************
2022-06-29 補
Response.Write("<script language=javascript>history.go(-2);</script>");
回到的畫面,是 cache 的畫面,如果在本畫面新增一筆資料,用此種方式回到該畫面,GridView 不會自動重新 DataBind,看到的是尚未新增一筆的畫面。
(完)
沒有留言:
張貼留言