mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-01-24 07:16:52 -06:00
Validate user inputs provided in configuration files before starting pgadmin server. #5907
This commit is contained in:
parent
a9399030f4
commit
6c12829cd4
@ -20,10 +20,29 @@ def get_variables_from_module(module_name):
|
|||||||
variables = {}
|
variables = {}
|
||||||
if module:
|
if module:
|
||||||
variables = {key: value for key, value in module.__dict__.items()
|
variables = {key: value for key, value in module.__dict__.items()
|
||||||
if not (key.startswith('__') or key.startswith('_'))}
|
if not (key.startswith('__') or key.startswith('_')) and
|
||||||
|
validate_config_variable(key, value)}
|
||||||
return variables
|
return variables
|
||||||
|
|
||||||
|
|
||||||
|
def validate_config_variable(key, value):
|
||||||
|
boolean_keys = ['SERVER_MODE', 'ENHANCED_COOKIE_PROTECTION',
|
||||||
|
'SUPPORT_SSH_TUNNEL', 'ALLOW_SAVE_TUNNEL_PASSWORD',
|
||||||
|
'MASTER_PASSWORD_REQUIRED']
|
||||||
|
integer_keys = ['DEFAULT_SERVER_PORT', 'SERVER_HEARTBEAT_TIMEOUT',
|
||||||
|
'LOG_ROTATION_SIZE', 'LOG_ROTATION_AGE',
|
||||||
|
'LOG_ROTATION_MAX_LOG_FILES', 'MAX_SESSION_IDLE_TIME']
|
||||||
|
if key in boolean_keys and not isinstance(value, bool):
|
||||||
|
exception_msg = 'Expected boolean value for %s; got %r' % (key, value)
|
||||||
|
raise ValueError(exception_msg)
|
||||||
|
elif key in integer_keys and not isinstance(value, int):
|
||||||
|
exception_msg = 'Expected integer value for %s; got %r' % (key, value)
|
||||||
|
raise ValueError(exception_msg)
|
||||||
|
else:
|
||||||
|
# Do not validate
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
# Load distribution-specific config overrides
|
# Load distribution-specific config overrides
|
||||||
try:
|
try:
|
||||||
import config_distro
|
import config_distro
|
||||||
|
Loading…
Reference in New Issue
Block a user