Skip to content

Commit 44aca4c

Browse files
Alexey PortnovAlexey Portnov
authored andcommitted
Security: path traversal в amo-crm/playback и /v2/media эндпоинтах
- /playback: добавлена проверка на '..' и '//' в параметре view, whitelist расширений файлов (.mp3, .wav, .webm, .ogg) - /v2/media: добавлена проверка на '..' и '/' в параметре token (предотвращает чтение произвольных файлов через io.open), аналогичная проверка view на path traversal
1 parent 210bf4c commit 44aca4c

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

Lib/AmoCrmConf.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,15 +270,30 @@ public function createNginxLocations(): string
270270
' return "ok";'.PHP_EOL.
271271
" ';".PHP_EOL.
272272
" set_by_lua \$result_url '".PHP_EOL.
273-
' local url = "/pbxcore/api/amo-crm/v2/playback"..ngx.var.arg_view;'.PHP_EOL.
273+
' local view = ngx.var.arg_view or ""'.PHP_EOL.
274+
' if view:find("%.%.") or view:find("//") then'.PHP_EOL.
275+
' return "/404"'.PHP_EOL.
276+
' end'.PHP_EOL.
277+
' local allowed = {".mp3", ".wav", ".webm", ".ogg"}'.PHP_EOL.
278+
' local ext = view:lower():match("(%.[a-z0-9]+)$") or ""'.PHP_EOL.
279+
' local ok = false'.PHP_EOL.
280+
' for _, v in ipairs(allowed) do'.PHP_EOL.
281+
' if ext == v then ok = true; break end'.PHP_EOL.
282+
' end'.PHP_EOL.
283+
' if not ok then return "/404" end'.PHP_EOL.
284+
' local url = "/pbxcore/api/amo-crm/v2/playback"..view;'.PHP_EOL.
274285
' return string.gsub(url,ngx.var.document_root,"");'.PHP_EOL.
275286
" ';".PHP_EOL.
276287
' try_files "${result_url}" "${result_url}";'.PHP_EOL.
277288
'}'.PHP_EOL.PHP_EOL.
278289
"location /pbxcore/api/amo-crm/v2/media {".PHP_EOL.
279290
" root /storage/usbdisk1/mikopbx/astspool/monitor;".PHP_EOL.
280291
' set_by_lua $token_exists \''.PHP_EOL.
281-
' local file = "/var/etc/auth/"..tostring(ngx.var.arg_token);'.PHP_EOL.
292+
' local token = tostring(ngx.var.arg_token or "")'.PHP_EOL.
293+
' if token == "" or token:find("%.%.") or token:find("/") then'.PHP_EOL.
294+
' return "fail"'.PHP_EOL.
295+
' end'.PHP_EOL.
296+
' local file = "/var/etc/auth/"..token;'.PHP_EOL.
282297
' local f = io.open(file, "rb")'.PHP_EOL.
283298
' local result = "fail";'.PHP_EOL.
284299
' if f then'.PHP_EOL.
@@ -291,7 +306,11 @@ public function createNginxLocations(): string
291306
' rewrite ^ /pbxcore/api/nchan/auth last;'.PHP_EOL.
292307
' }'.PHP_EOL.
293308
" set_by_lua \$result_url '".PHP_EOL.
294-
' local url = "/pbxcore/api/amo-crm/v2/playback"..ngx.var.arg_view;'.PHP_EOL.
309+
' local view = ngx.var.arg_view or ""'.PHP_EOL.
310+
' if view:find("%.%.") or view:find("//") then'.PHP_EOL.
311+
' return "/404"'.PHP_EOL.
312+
' end'.PHP_EOL.
313+
' local url = "/pbxcore/api/amo-crm/v2/playback"..view;'.PHP_EOL.
295314
' return string.gsub(url,ngx.var.document_root,"");'.PHP_EOL.
296315
" ';".PHP_EOL.
297316
' try_files "${result_url}" "${result_url}";'.PHP_EOL.

0 commit comments

Comments
 (0)