簡體   English   中英

瀏覽器(Edge、Firefox、Chrome)在 6 分鍾后重定向“303 See Other”請求

[英]Browsers (Edge, Firefox, Chrome) redirecting after 6 minutes for a "303 See Other" request

用例:如果用戶超過最大 (5) 次登錄嘗試,我的 web 應用程序應將用戶重定向到 401 鎖定 html 頁面。

問題:一旦所有登錄嘗試都用完,頁面將在 6 分鍾后重定向,而不是立即重定向。 這在所有瀏覽器中都可以觀察到。

它是如何完成的:我正在使用 jQuery 發送 Ajax POST 調用以登錄。

  1. 用戶輸入錯誤的密碼並單擊登錄按鈕。 該頁面顯示前 4 次嘗試的密碼無效。
  2. 在第 5 次嘗試時,后端代碼 (cgi) 以 HTTP 狀態代碼“303 See Other”和 URL 響應:“/restarting/”
  3. 我們構建了一個名為 mod_access 的 LigHTTPd 插件。 如果用戶請求任何其他頁面(例如主頁),插件作業是在 5 次嘗試失敗后檢查並返回“303 See Other”代碼和 URL:“/errors/en/401lockedout.html”頁面作為響應。 因此,當瀏覽器調用 /restarting/ URL 時,mod_access 插件將視為未授權請求並返回 303。

環境和編程語言: LigHTTPd web server, HTML, jQuery, C++

服務器日志分析:(我跳過前 4 次嘗試的請求,因為第 5 次嘗試在這里很重要)

第五次登錄請求:

1980-01-06 02:50:12: (../../lighttpd-1.4.55/src/connections.c.774) fd: 9 request-len: 666 \nPOST /submitLogin/ HTTP/1.1\r\nHost : localhost\r\nConnection: keep-alive\r\nContent-Length: 123\r\nAccept: application/json, text/javascript, / ; q=0.01\r\nX-Requested-With: XMLHttpRequest\r\nUser-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36 Edg /108.0.1462.54\r\n內容類型:application/x-www-form-urlencoded; charset=UTF-8\r\nOrigin: http://localhost\r\nReferer: http://localhost/\r\nAccept-Encoding: gzip, deflate\r\nAccept-Language: en-GB,en;q =0.9\r\nCookie: SID=abc; _TESTCOOKIESUPPORT=1; sess=def\r\n\r\n

CGI 應用程序恢復為“303 See Other”,位置為 /restarting/

1980-01-06 02:50:13: (../../lighttpd-1.4.55/src/response.c.125) 響應標頭:\nHTTP/1.1 303 參見其他\r\n位置:/restarting/\ r\n連接:關閉\r\nX-內容類型選項:nosniff\r\nX-XSS-保護:1; 模式=塊\r\n內容長度:992\r\n日期:1980 年 1 月 6 日星期日 02:50:13 GMT\r\n服務器:XYZ\r\n\r\n 1980-01-06 02:50: 13: (../../lighttpd-1.4.55/src/mod_cgi.c.1190) CGI pid 3868 死於信號 11

瀏覽器發送了一個 GET 請求 /restarting/ 頁面

1980-01-06 02:50:13: (../../lighttpd-1.4.55/src/connections.c.774) fd: 9 request-len: 551 \nGET /restarting/ HTTP/1.1\r\n主機: localhost\r\n連接: keep-alive\r\n接受: application/json, text/javascript, / ; q=0.01\r\nX-Requested-With: XMLHttpRequest\r\nUser-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36 Edg /108.0.1462.54\r\nReferer: http://localhost/\r\nAccept-Encoding: gzip, deflate\r\nAccept-Language: en-GB,en;q=0.9\r\nCookie: SID=abc; _TESTCOOKIESUPPORT=1; sess=def\r\n\r\n

mode_access 阻止了請求並發送了另一個“303 See Other”,位置為:http://localhost/errors/en/401lockedout.html

1980-01-06 02:50:13: (../../lighttpd-1.4.55/src/mod_access.c.125) 鎖定改革為 /errors/en/401lockedout.html 1980-01-06 02:50: 13: (../../lighttpd-1.4.55/src/mod_access.c.322) 被阻止的 URI: /cgi/ui.cgi 1980-01-06 02:50:13: (../../lighttpd- 1.4.55/src/mod_access.c.323) 重定向到鎖定頁面 http://localhost/errors/en/401lockedout.html 1980-01-06 02:50:13: (../../lighttpd-1.4.55 /src/response.c.125) Response-Header: \nHTTP/1.1 303 See Other\r\nLocation: http://localhost/errors/en/401lockedout.html\r\nX-Content-Type-Options: nosniff\r \nX-XSS-保護:1; 模式=塊\r\n傳輸編碼:分塊\r\n日期:星期日,1980 年 1 月 6 日 02:50:13 GMT\r\n服務器:XYZ\r\n\r\n

服務器未收到任何請求(來自瀏覽器開發人員工具),並且瀏覽器未向 401lockedout.html 頁面發送 GET 請求。

6 分鍾后,服務器收到瀏覽器對鎖定頁面的請求。

1980-01-06 02:56:14: (../../lighttpd-1.4.55/src/connections.c.774) fd: 9 request-len: 646 \n GET /errors/en/401lockedout.html HTTP /1.1\r\nHost: localhost\r\nConnection: keep-alive\r\nAccept: application/json, text/javascript, / ; q=0.01\r\nX-Requested-With: XMLHttpRequest\r\nUser-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36 Edg /108.0.1462.54\r\nReferer: http://localhost/\r\nAccept-Encoding: gzip, deflate\r\nAccept-Language: en-GB,en;q=0.9\r\nCookie: SID=abc; _TESTCOOKIESUPPORT=1; sess=def\r\nIf-None-Match: "1764933797"\r\nIf-Modified-Since: Fri, 16 Dec 2022 08:20:12 GMT\r\n\r\n

1980-01-06 02:56:14: (../../lighttpd-1.4.55/src/response.c.125) 響應標頭:\nHTTP/1.1 304 未修改\r\n內容類型:文本/ html\r\n接受范圍:字節\r\nETag:“1764933797”\r\n上次修改時間:2022 年 12 月 16 日星期五 08:20:12 GMT\r\nX-Content-Type-Options:nosniff\r\ nX-XSS-保護:1; 模式=塊\r\n日期:1980 年 1 月 6 日星期日 02:56:14 GMT\r\n服務器:XYZ\r\n\r\n

這是瀏覽器開發人員工具的片段瀏覽器網絡調用

這以前可以工作,但現在不工作。

我試圖找到根本原因並修復它但無法解決。 任何指示肯定會幫助我解決這個問題。

我們構建了一個名為 mod_access 的 LigHTTPd 插件。

您是說您有一個與 lighttpd 插件 ( mod_access ) 同名的自定義插件嗎?

另外: mod_ma.net和幾行自定義 lua 代碼可能比自定義 C++ 更簡單、更便攜,甚至可能更快。

對於您的自定義插件,您很可能沒有正確結束 lighttpd 內部的響應,因此當默認的 6 分鍾寫入空閑超時到期並且連接關閉時,lighttpd 可能會刷新響應。 Transfer-Encoding: chunked\r\n在 lighttpd 對您的 mod_access 處理程序的響應中告訴我您可能沒有告訴 lighttpd 內部響應已完成( r->resp_body_finished = 1

(../../lighttpd-1.4.55/src/mod_cgi.c.1190) CGI pid 3868 died with signal 11

您的 CGI 似乎也崩潰了。 信號 11 是 Linux 上的 SIGSEGV。

旁白:請回顧一下為什么您可以在 CGI 中處理身份驗證策略時編寫自定義 C++ 插件。 為了適當的安全性,無論如何,您應該在一個地方處理身份驗證策略,作為確保策略得到執行的一部分。

PS 服務器的官方名稱一直是“lighttpd”; 從來沒有“LightHTTPd”。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM