Copilot commented on code in PR #3362:
URL: https://github.com/apache/caldera/pull/3362#discussion_r3547853221
##########
app/api/v2/managers/ability_api_manager.py:
##########
@@ -70,20 +67,27 @@ def _validate_ability_data(self, create: bool, data: dict):
if 'id' in data and not validator.match(data['id']):
raise JsonHttpBadRequest(f'Invalid ability ID {data["id"]}. IDs
can only contain '
'alphanumeric characters, hyphens, and
underscores.')
-
# Validate tactic, used for directory creation, lower case if present
if 'tactic' in data:
if not validator.match(data['tactic']):
raise JsonHttpBadRequest(f'Invalid ability tactic
{data["tactic"]}. Tactics can only contain '
'alphanumeric characters, hyphens,
and underscores.')
data['tactic'] = data['tactic'].lower()
-
+ # PATCH: Validate technique_name to block HTML/script injection.
+ # Allowlist covers all legitimate ATT&CK technique name characters:
+ # letters, digits, spaces, hyphens, underscores, parentheses,
+ # slashes, dots, commas, colons, and ampersands.
+ # Excludes < > " ' ; which are not present in any ATT&CK technique
name.
+ technique_name_validator = re.compile(r'^[a-zA-Z0-9\s\-_()/.,&:]+$')
+ if data.get('technique_name') and not
technique_name_validator.match(data['technique_name']):
+ raise JsonHttpBadRequest(f'Invalid technique_name
"{data["technique_name"]}". technique_name can only '
+ 'contain alphanumeric characters, spaces,
hyphens, underscores, '
+ 'parentheses, slashes, dots, commas,
colons, and ampersands.')
Review Comment:
This error message reflects the user-provided `technique_name` back to the
client. If any UI renders API error strings without HTML-escaping, this can
become a reflected XSS vector. Safer to avoid echoing untrusted input in the
message.
##########
app/api/v2/managers/ability_api_manager.py:
##########
@@ -70,20 +67,27 @@ def _validate_ability_data(self, create: bool, data: dict):
if 'id' in data and not validator.match(data['id']):
raise JsonHttpBadRequest(f'Invalid ability ID {data["id"]}. IDs
can only contain '
'alphanumeric characters, hyphens, and
underscores.')
-
# Validate tactic, used for directory creation, lower case if present
if 'tactic' in data:
if not validator.match(data['tactic']):
raise JsonHttpBadRequest(f'Invalid ability tactic
{data["tactic"]}. Tactics can only contain '
'alphanumeric characters, hyphens,
and underscores.')
data['tactic'] = data['tactic'].lower()
-
+ # PATCH: Validate technique_name to block HTML/script injection.
+ # Allowlist covers all legitimate ATT&CK technique name characters:
+ # letters, digits, spaces, hyphens, underscores, parentheses,
+ # slashes, dots, commas, colons, and ampersands.
+ # Excludes < > " ' ; which are not present in any ATT&CK technique
name.
+ technique_name_validator = re.compile(r'^[a-zA-Z0-9\s\-_()/.,&:]+$')
Review Comment:
The allowlist regex uses `\s`, which matches tabs/newlines in addition to
spaces. This contradicts the comment/error text (“spaces”) and can allow
unexpected control characters to be stored.
##########
app/api/v2/managers/ability_api_manager.py:
##########
@@ -14,7 +12,7 @@
class AbilityApiManager(BaseApiManager):
def __init__(self, data_svc, file_svc):
super().__init__(data_svc=data_svc, file_svc=file_svc)
-
+
Review Comment:
There is trailing whitespace on this blank line, which can cause unnecessary
diff churn and may fail linters that check whitespace.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]