Skip to content

Commit ff14eb9

Browse files
committed
Merge branch 'GHSA-cvwp-r2g2-j824' into develop
2 parents 5850c56 + 16f6caf commit ff14eb9

1 file changed

Lines changed: 34 additions & 8 deletions

File tree

glances/outputs/glances_restful_api.py

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,6 +1267,38 @@ def _api_config_section_item(self, section: str, item: str):
12671267

12681268
return GlancesJSONResponse(ret_item)
12691269

1270+
# Args keys that must always be redacted (even for authenticated users)
1271+
_ALWAYS_REDACTED_ARGS = frozenset({'password'})
1272+
1273+
# Args keys redacted when no authentication is configured
1274+
_SENSITIVE_ARGS = frozenset(
1275+
{
1276+
'password',
1277+
'snmp_community',
1278+
'snmp_user',
1279+
'snmp_auth',
1280+
'conf_file',
1281+
'username',
1282+
}
1283+
)
1284+
1285+
def _sanitize_args(self):
1286+
"""Return a sanitized copy of self.args as a dict.
1287+
1288+
- password hash is always redacted (even for authenticated users)
1289+
- other sensitive fields are redacted when no authentication is configured
1290+
"""
1291+
args_json = vars(self.args).copy()
1292+
if not self.args.password:
1293+
for key in self._SENSITIVE_ARGS:
1294+
if key in args_json:
1295+
args_json[key] = '********'
1296+
else:
1297+
for key in self._ALWAYS_REDACTED_ARGS:
1298+
if key in args_json and args_json[key]:
1299+
args_json[key] = '********'
1300+
return args_json
1301+
12701302
def _api_args(self):
12711303
"""Glances API RESTful implementation.
12721304
@@ -1275,10 +1307,7 @@ def _api_args(self):
12751307
HTTP/404 if others error
12761308
"""
12771309
try:
1278-
# Get the RAW value of the args' dict
1279-
# Use vars to convert namespace to dict
1280-
# Source: https://docs.python.org/%s/library/functions.html#vars
1281-
args_json = vars(self.args)
1310+
args_json = self._sanitize_args()
12821311
except Exception as e:
12831312
raise HTTPException(status.HTTP_404_NOT_FOUND, f"Cannot get args ({str(e)})")
12841313

@@ -1296,10 +1325,7 @@ def _api_args_item(self, item: str):
12961325
raise HTTPException(status.HTTP_400_BAD_REQUEST, f"Unknown argument item {item}")
12971326

12981327
try:
1299-
# Get the RAW value of the args' dict
1300-
# Use vars to convert namespace to dict
1301-
# Source: https://docs.python.org/%s/library/functions.html#vars
1302-
args_json = vars(self.args)[item]
1328+
args_json = self._sanitize_args()[item]
13031329
except Exception as e:
13041330
raise HTTPException(status.HTTP_404_NOT_FOUND, f"Cannot get args item ({str(e)})")
13051331

0 commit comments

Comments
 (0)