remove newlines and strip content first before parsing ssh key name

This commit is contained in:
forest 2021-05-12 12:21:26 -05:00
parent 4590671984
commit 961bb4976b
1 changed files with 4 additions and 4 deletions

View File

@ -301,11 +301,13 @@ def ssh_public_keys():
method = request.form["method"]
content = None
if method == "POST":
content = request.form["content"].replace("\r", " ").replace("\n", " ").strip()
name = request.form["name"]
if not name or len(name.strip()) < 1:
if method == "POST":
parts = re.split(" +", request.form["content"])
parts = re.split(" +", content)
if len(parts) > 2 and len(parts[2].strip()) > 0:
name = parts[2].strip()
else:
@ -316,11 +318,9 @@ def ssh_public_keys():
errors.append(f"Key name '{name}' must match \"^[0-9A-Za-z_@:. -]+$\"")
if method == "POST":
content = request.form["content"]
if not content or len(content.strip()) < 1:
errors.append("Content is required")
else:
content = content.replace("\r", " ").replace("\n", " ").strip()
if not re.match(r"^(ssh|ecdsa)-[0-9A-Za-z+/_=@:. -]+$", content):
errors.append("Content must match \"^(ssh|ecdsa)-[0-9A-Za-z+/_=@:. -]+$\"")