@@ -9,6 +9,7 @@ if not TX_MENU_ENABLED then return end
99-- Vars
1010local pipeReturnCallbacks = {}
1111local pipeCallbackCounter = 1
12+ local menuCloseGracePeriod = 750
1213
1314--- @class StaticCacheEntry
1415--- @field body string
@@ -19,14 +20,24 @@ local staticCacheData = {}
1920
2021-- catching all NUI requests for https://monitor/WebPipe/
2122RegisterRawNuiCallback (' WebPipe' , function (req , cb )
22- if not menuIsAccessible or not isMenuVisible then
23- return txPrint (' ^1NUI request received while the menu is not accessible or visible.' )
24- end
25-
2623 local path = req .path
2724 local headers = req .headers
2825 local body = req .body
2926 local method = req .method
27+
28+ -- Check if the menu is accessible and visible, otherwise it might be a CSRF attempt
29+ -- Does not trigger within a 750ms grace period after the menu is closed
30+ if
31+ (not menuIsAccessible or not isMenuVisible )
32+ and (GetGameTimer () - tsLastMenuClose ) > menuCloseGracePeriod
33+ then
34+ txPrint (' ^1NUI WebPipe request received the request below while the menu is not accessible or visible:' )
35+ txPrint ((' ^3%s %s' ):format (method , string.sub (path , 1 , 100 )))
36+ return cb ({
37+ status = 403 ,
38+ body = ' {}' ,
39+ })
40+ end
3041 debugPrint ((" ^3WebPipe[^1%d^3]^0 ^2%s ^4%s^0" ):format (pipeCallbackCounter , method , path ))
3142
3243 -- Check for CSRF attempt
0 commit comments