浏览代码

Prevents users from sending empty ssh keys

clement 1 年之前
父节点
当前提交
5324a48404
共有 1 个文件被更改,包括 9 次插入0 次删除
  1. 9 0
      src/handler.rs

+ 9 - 0
src/handler.rs

@@ -229,6 +229,15 @@ pub async fn add_ssh_key(ldap_wrapper: web::Data<LdapWrapper>, form: web::Form<F
 
     let uid = session.get("user_id").unwrap().unwrap();
 
+    //todo next time: regex check if a sshkey was provided
+    if form.new_ssh_key.is_empty() {
+        session.insert("error_message", "SSH key can't be empty".to_string()).unwrap();
+        return HttpResponse::Ok()
+        .status(StatusCode::FOUND)
+        .append_header((header::LOCATION, "/ssh"))
+        .finish()
+    }
+
     match ldap_wrapper.manage_ssh_key(uid, form.new_ssh_key.clone(), ldap::ManageSSHOps::ADD).await {
         Ok(_) => return HttpResponse::Ok()
                 .status(StatusCode::FOUND)