Skip to content

Commit fccd7ad

Browse files
committed
tweak(menu): added grace period for webpipe while closed warning
1 parent c00e224 commit fccd7ad

3 files changed

Lines changed: 18 additions & 4 deletions

File tree

resource/menu/client/cl_base.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
-- TODO: they should be upper case
88
menuIsAccessible = false
99
isMenuVisible = false
10+
tsLastMenuClose = 0
1011
menuPermissions = {}
1112
lastTpCoords = false;
1213

@@ -186,6 +187,7 @@ end)
186187
-- When the escape key is pressed in menu
187188
RegisterSecureNuiCallback('closeMenu', function(_, cb)
188189
isMenuVisible = false
190+
tsLastMenuClose = GetGameTimer()
189191
debugPrint('Releasing all NUI Focus')
190192
SetNuiFocus(false)
191193
SetNuiFocusKeepInput(false)

resource/menu/client/cl_functions.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ function toggleMenuVisibility(visible)
8787
if not isMenuVisible then
8888
SetNuiFocus(false)
8989
SetNuiFocusKeepInput(false)
90+
tsLastMenuClose = GetGameTimer()
9091
end
9192
playLibrarySound('enter')
9293
end

resource/menu/client/cl_webpipe.lua

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ if not TX_MENU_ENABLED then return end
99
-- Vars
1010
local pipeReturnCallbacks = {}
1111
local 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/
2122
RegisterRawNuiCallback('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

Comments
 (0)