~forest/capsul-flask

961bb4976ba1d4f9d535202835d79f7cc446872e — forest 2 days ago 4590671 master
remove newlines and strip content first before parsing ssh key name
1 files changed, 4 insertions(+), 4 deletions(-)

M capsulflask/console.py
M capsulflask/console.py => capsulflask/console.py +4 -4
@@ 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+/_=@:. -]+$\"")