From 961bb4976ba1d4f9d535202835d79f7cc446872e Mon Sep 17 00:00:00 2001 From: forest Date: Wed, 12 May 2021 12:21:26 -0500 Subject: [PATCH] remove newlines and strip content first before parsing ssh key name --- capsulflask/console.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/capsulflask/console.py b/capsulflask/console.py index 6c305c6..409bd7a 100644 --- a/capsulflask/console.py +++ b/capsulflask/console.py @@ -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+/_=@:. -]+$\"")