From 255c08a6def04d89993b6d4d75a93cd90855b3bf Mon Sep 17 00:00:00 2001 From: Nikita Skryabin Date: Thu, 20 Feb 2025 23:38:27 +0300 Subject: [PATCH] feat(podkop.js): add validation for cache file path to ensure it meets specific criteria --- .../resources/view/podkop/podkop.js | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/luci-app-podkop/htdocs/luci-static/resources/view/podkop/podkop.js b/luci-app-podkop/htdocs/luci-static/resources/view/podkop/podkop.js index 88f310c..c9d25c7 100644 --- a/luci-app-podkop/htdocs/luci-static/resources/view/podkop/podkop.js +++ b/luci-app-podkop/htdocs/luci-static/resources/view/podkop/podkop.js @@ -715,13 +715,39 @@ return view.extend({ return true; }; - o = s.taboption('additional', form.Value, 'cache_file', 'Cache File Path', 'Select or enter path for sing-box cache file'); + o = s.taboption('additional', form.Value, 'cache_file', 'Cache File Path', 'Select or enter path for sing-box cache file. Change this ONLY if you know what you are doing'); o.value('/tmp/cache.db', 'RAM (/tmp/cache.db)'); o.value('/usr/share/sing-box/cache.db', 'Flash (/usr/share/sing-box/cache.db)'); o.default = '/tmp/cache.db'; o.rmempty = false; o.ucisection = 'main'; + o.validate = function(section_id, value) { + if (!value) { + return _('Cache file path cannot be empty'); + } + + if (!value.startsWith('/')) { + return _('Path must be absolute (start with /)'); + } + + if (!value.endsWith('cache.db')) { + return _('Path must end with cache.db'); + } + + const parts = value.split('/').filter(Boolean); + if (parts.length < 2) { + return _('Path must contain at least one directory (like /tmp/cache.db)'); + } + + const pathRegex = /^\/(?:[^/]+\/)+[^/]+\.db$/; + if (!pathRegex.test(value)) { + return _('Invalid path format. Must be like /tmp/cache.db'); + } + + return true; + }; + // Diagnostics tab o = s.tab('diagnostics', _('Diagnostics'));