CVE-2022-4767 (published 2022-12-27T15:15Z)

Denial of Service in GitHub repository usememos/memos prior to 0.9.1.

CVSS v3 base score: 7.5, HIGH (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H)

Weakness information:
cwe_id: CWE-400
cwe_name: Uncontrolled Resource Consumption
description: The product does not properly control the allocation and maintenance of a limited resource, thereby enabling an actor to influence the amount of resources consumed, eventually leading to the exhaustion of available resources.
extended_description: 
            Limited resources include memory, file system storage, database connection pool entries, and CPU. If an attacker can trigger the allocation of these limited resources, but the number or size of the resources is not controlled, then the attacker could cause a denial of service that consumes all available resources. This would prevent valid users from accessing the product, and it could potentially have an impact on the surrounding environment. For example, a memory exhaustion attack against an application could slow down the application as well as its host operating system.
            There are at least three distinct scenarios which can commonly lead to resource exhaustion:
               
                  Lack of throttling for the number of allocated resources
                  Losing all references to a resource before reaching the shutdown stage
                  Not closing/returning a resource after processing
               
            Resource exhaustion problems are often result due to an incorrect implementation of the following situations:
               
                  Error conditions and other exceptional circumstances.
                  Confusion over which part of the program is responsible for releasing the resource.
               
         
         

Fix information:
repo_url: https://github.com/usememos/memos
commit_details: repo_url: https://github.com/usememos/memos
author: boojack
author_date: 2022-12-27 21:51:43+08:00
msg: chore: update userinfo validator (#868)

* chore: update userinfo validator

* chore: update actions

* chore: update
repository: repo_url: https://github.com/usememos/memos
repo_name: usememos/memos
description: An open source, lightweight note-taking service. Easily capture and share your great thoughts.
repo_language: Go
owner: usememos
file_changes: filename: backend-tests-default.yml
change_type: ModificationType.ADD
diff: @@ -0,0 +1,20 @@
+name: Backend Test
+
+on:
+  pull_request:
+    branches:
+      - main
+      - "release/v*.*.*"
+    paths:
+      - "web/**"
+
+jobs:
+  go-static-checks:
+    runs-on: ubuntu-latest
+    steps:
+      - run: 'echo "Not required"'
+
+  go-tests:
+    runs-on: ubuntu-latest
+    steps:
+      - run: 'echo "Not required"'

programming_language: CoffeeScript
filename: backend-tests.yml
change_type: ModificationType.MODIFY
diff: @@ -1,12 +1,10 @@
 name: Backend Test
 
 on:
-  push:
+  pull_request:
     branches:
       - main
       - "release/v*.*.*"
-  pull_request:
-    branches: [main]
     paths-ignore:
       - "web/**"
 

programming_language: Shell
filename: frontend-tests-default.yml
change_type: ModificationType.ADD
diff: @@ -0,0 +1,25 @@
+name: Frontend Test
+
+on:
+  pull_request:
+    branches:
+      - main
+      - "release/v*.*.*"
+    paths-ignore:
+      - "web/**"
+
+jobs:
+  eslint-checks:
+    runs-on: ubuntu-latest
+    steps:
+      - run: 'echo "Not required"'
+
+  jest-tests:
+    runs-on: ubuntu-latest
+    steps:
+      - run: 'echo "Not required"'
+
+  frontend-build:
+    runs-on: ubuntu-latest
+    steps:
+      - run: 'echo "Not required"'

programming_language: CoffeeScript
filename: frontend-tests.yml
change_type: ModificationType.MODIFY
diff: @@ -1,12 +1,10 @@
 name: Frontend Test
 
 on:
-  push:
+  pull_request:
     branches:
       - main
       - "release/v*.*.*"
-  pull_request:
-    branches: [main]
     paths:
       - "web/**"
 

programming_language: Markdown
filename: user.go
change_type: ModificationType.MODIFY
diff: @@ -2,6 +2,8 @@ package api
 
 import (
 	"fmt"
+
+	"github.com/usememos/memos/common"
 )
 
 // Role is the type of a role.
@@ -61,9 +63,23 @@ func (create UserCreate) Validate() error {
 	if len(create.Username) < 4 {
 		return fmt.Errorf("username is too short, minimum length is 4")
 	}
+	if len(create.Username) > 32 {
+		return fmt.Errorf("username is too long, maximum length is 32")
+	}
 	if len(create.Password) < 4 {
 		return fmt.Errorf("password is too short, minimum length is 4")
 	}
+	if len(create.Nickname) > 64 {
+		return fmt.Errorf("nickname is too long, maximum length is 64")
+	}
+	if create.Email != "" {
+		if len(create.Email) > 256 {
+			return fmt.Errorf("email is too long, maximum length is 256")
+		}
+		if common.ValidateEmail(create.Email) {
+			return fmt.Errorf("invalid email format")
+		}
+	}
 
 	return nil
 }
@@ -85,6 +101,31 @@ type UserPatch struct {
 	OpenID       *string
 }
 
+func (patch UserPatch) Validate() error {
+	if patch.Username != nil && len(*patch.Username) < 4 {
+		return fmt.Errorf("username is too short, minimum length is 4")
+	}
+	if patch.Username != nil && len(*patch.Username) > 32 {
+		return fmt.Errorf("username is too long, maximum length is 32")
+	}
+	if patch.Password != nil && len(*patch.Password) < 4 {
+		return fmt.Errorf("password is too short, minimum length is 4")
+	}
+	if patch.Nickname != nil && len(*patch.Nickname) > 64 {
+		return fmt.Errorf("nickname is too long, maximum length is 64")
+	}
+	if patch.Email != nil {
+		if len(*patch.Email) > 256 {
+			return fmt.Errorf("email is too long, maximum length is 256")
+		}
+		if common.ValidateEmail(*patch.Email) {
+			return fmt.Errorf("invalid email format")
+		}
+	}
+
+	return nil
+}
+
 type UserFind struct {
 	ID *int `json:"id"`
 

programming_language: Go
filename: user.go
change_type: ModificationType.MODIFY
diff: @@ -198,9 +198,8 @@ func (s *Server) registerUserRoutes(g *echo.Group) {
 		if err := json.NewDecoder(c.Request().Body).Decode(userPatch); err != nil {
 			return echo.NewHTTPError(http.StatusBadRequest, "Malformatted patch user request").SetInternal(err)
 		}
-
-		if userPatch.Email != nil && *userPatch.Email != "" && !common.ValidateEmail(*userPatch.Email) {
-			return echo.NewHTTPError(http.StatusBadRequest, "Invalid email format")
+		if err := userPatch.Validate(); err != nil {
+			return echo.NewHTTPError(http.StatusBadRequest, "Invalid user patch format.").SetInternal(err)
 		}
 
 		if userPatch.Password != nil && *userPatch.Password != "" {

programming_language: Go