mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-11 12:46:49 +00:00
fix(storages): the pool target check runs in linear time
The expression that checks a storage pool's target directory nested a repetition inside another, so a crafted target backtracked exponentially: "," followed by 22 dashes and "!" took 1.3 s, and every two more characters four times as long. The field allows 100 characters, so one form post could hold a worker for good (CodeQL py/redos; the page is for superusers). The new expression has no nested repetition and accepts exactly the same targets: compared with the old one on 200,000 random strings over letters, digits, "/", ".", "-", "_", ",", "!", space and newline, they agree on every string. A crafted 100-character target is now checked in microseconds. The tests pin the accepted and refused targets and time the crafted one.
This commit is contained in:
parent
940545c2c4
commit
09fbabf705
2 changed files with 37 additions and 1 deletions
|
|
@ -38,7 +38,10 @@ class AddStgPool(forms.Form):
|
|||
def clean_target(self):
|
||||
storage_type = self.cleaned_data["stg_type"]
|
||||
target = self.cleaned_data["target"]
|
||||
have_symbol = re.match(r"^[^-](\/?((?:[0-9a-zA-Z_])|(?:\.)|((?<!\/)-))*)+$", target)
|
||||
# letters, digits, "_", ".", "/" and "-" not right after "/"; not
|
||||
# starting with "-". Written without nested repetition, which
|
||||
# backtracked exponentially on crafted input.
|
||||
have_symbol = re.match(r"^[^-](?:[/0-9a-zA-Z_.]|(?<!/)-)*$", target)
|
||||
if storage_type in ["dir", "netfs"] and not have_symbol:
|
||||
raise forms.ValidationError(
|
||||
_("The target must not contain any special characters")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue