Skip to content

Commit b7f5641

Browse files
committed
feat(site): Validate admin password
1 parent 38c4b10 commit b7f5641

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

press/press/doctype/site/site.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ def validate(self):
367367
self.validate_site_name()
368368
self.validate_bench()
369369
self.set_site_admin_password()
370+
self.validate_admin_password()
370371
self.validate_installed_apps()
371372
self.validate_host_name()
372373
self.validate_site_config()
@@ -392,6 +393,17 @@ def set_site_admin_password(self):
392393
if not self.admin_password:
393394
self.admin_password = frappe.generate_hash(length=16)
394395

396+
def validate_admin_password(self):
397+
# Shell characters can cause issues because they are not escaped
398+
# https://stackoverflow.com/questions/15783701/which-characters-need-to-be-escaped-when-using-bash/44581064#44581064
399+
if not self.is_new():
400+
return # Only validate on new sites, changing the password once created does nothing (yet)
401+
if not self.admin_password or self.is_dummy_password(self.admin_password):
402+
return
403+
SHELL_CHARS = " !\"#$&'()*,;<>?[\\]^`{|}"
404+
if any(c in SHELL_CHARS for c in self.admin_password):
405+
frappe.throw("Admin password must not contain special characters")
406+
395407
def validate_bench(self):
396408
if (
397409
self.status not in ("Broken", "Archived")

0 commit comments

Comments
 (0)