fix: /config no longer shows secret options.
Release / release (push) Successful in 11s

This commit is contained in:
slawek committed 2026-10-23 22:48:31 +02:00
1 parent a4cffb67e4
commit c377801be0
4 files changed
+36 -12

No files matched your search

+8 -9
View File
@@ -33,7 +33,7 @@ WEB_STATE = pathlib.Path('/run/vpn-router/web.json')
FILTER_ANCHOR = '# End required lines'
#: Configuration options whose values are masked wherever the configuration is shown.
#: Configuration options left out wherever the configuration is shown.
SECRET_OPTION = re.compile(r'(^psk$)|secret|password|token|_key$')
BLOCKS = (
@@ -381,14 +381,13 @@ def refresh_web(cfg, ctx):
"""Hand the web service the features and facts it shows.
The service reads the file at each request: the features of the router,
the configuration with its secrets masked and the facts resolved from the
system, which it cannot work out with the standard library alone. The file
is readable by root only. The service follows a changed address or port
itself.
the configuration without its secret options and the facts resolved from
the system, which it cannot work out with the standard library alone. The
file is readable by root only. The service follows a changed address or
port itself.
"""
masked = {
section: {option: '********' if SECRET_OPTION.search(option) and value else value
for option, value in options.items()}
public = {
section: {option: value for option, value in options.items() if not SECRET_OPTION.search(option)}
for section, options in cfg.items()
}
WEB_STATE.parent.mkdir(parents=True, exist_ok=True)
@@ -400,7 +399,7 @@ def refresh_web(cfg, ctx):
'wireguard': bool(vpnrouter.wg_ready(ctx)),
'openvpn': bool(vpnrouter.openvpn_ready(ctx)),
'users': bool(vpnrouter.p2s_ready(ctx) or vpnrouter.openvpn_ready(ctx)),
'configuration': masked,
'configuration': public,
'network': {
'external_interface': ctx['wan_iface'],
'internal_interface': ctx['int_iface'],