
我有一個 URL 重寫規則來防止從定義清單之外的任何 URL 訪問該網站。400 Bad Request
如果 URL 不在清單中,則該規則會傳回。
<rule name="No unknown hosts" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^example\.com$" negate="true" />
<add input="{HTTP_HOST}" pattern="^www\.example\.com$" negate="true" />
<add input="{HTTP_HOST}" pattern="^admin\.example\.com$" negate="true" />
</conditions>
<action type="CustomResponse" statusCode="400" />
</rule>
我嘗試阻止的 URL 範例包括mail.example.com
或102.15.63.233
。這效果很好,除了當隱藏段附加到 URL 時,就像這樣mail.example.com/bin/
。這會轉到我的自訂404 錯誤頁面,該頁面看起來很糟糕,因為所有樣式表和其他資源(圖像等)都不會解析,因為URL 被阻止並返回400。觸發PCI DSS 掃描中出現錯誤,因為他們認為我允許目錄瀏覽。
我幾乎花了一整天的時間用我能想到的各種可能的方式進行谷歌搜索,但沒有成功。哦,這樣做的原因是,無效的 HOST 標頭不能被用來欺騙我們的網站重定向到惡意網站(許多其他重寫規則依賴於該功能)。我希望這裡有人能給出答案。