Skip to content

Conversation

@itschip
Copy link
Member

@itschip itschip commented Dec 2, 2025

No description provided.

itschip and others added 28 commits July 4, 2025 00:25
chore: update readme & env.template
chore(web): turn off only-export-components eslint
---
updated-dependencies:
- dependency-name: react-hook-form
  dependency-version: 7.60.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
* Redesign organization select page to match app.fivemanage.com

* Add comments

* Comments

* Comments
var fileType string

// Get the file type from the header
buf := make([]byte, fileHeader.Size)

Check failure

Code scanning / CodeQL

Slice memory allocation with excessive size value High

This memory allocation depends on a
user-provided value
.
This memory allocation depends on a
user-provided value
.

Copilot Autofix

AI about 1 month ago

To address this vulnerability, introduce a maximum allowed size for file allocations when determining the buffer size for reading the file content. Before performing make([]byte, fileHeader.Size), check whether fileHeader.Size is within acceptable minimum (e.g., greater than zero) and maximum bounds (e.g., a reasonably small upper limit such as 10MB). If the Size is negative, zero, or exceeds your defined maximum, return an error instead of allocating the slice. The best place for this check is just before line 16 in internal/http/httputil/mime.go inside the GetMimeDetails function. You may also want to define the maximum allowed file size as a constant at the top of the file. No new imports or method definitions are needed.

Suggested changeset 1
internal/http/httputil/mime.go

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/internal/http/httputil/mime.go b/internal/http/httputil/mime.go
--- a/internal/http/httputil/mime.go
+++ b/internal/http/httputil/mime.go
@@ -8,10 +8,17 @@
 	"github.com/gabriel-vasile/mimetype"
 )
 
+const MaxMimeReadSize = 10 * 1024 * 1024 // 10MB maximum for mime detection
+
 func GetMimeDetails(fileHeader *multipart.FileHeader, file multipart.File) (string, string, string, error) {
 	var err error
 	var fileType string
 
+	// Check that file size is reasonable before reading
+	if fileHeader.Size <= 0 || fileHeader.Size > MaxMimeReadSize {
+		return "", "", "", fmt.Errorf("file size %d exceeds allowed limit", fileHeader.Size)
+	}
+
 	// Get the file type from the header
 	buf := make([]byte, fileHeader.Size)
 	_, err = file.Read(buf)
EOF
@@ -8,10 +8,17 @@
"github.com/gabriel-vasile/mimetype"
)

const MaxMimeReadSize = 10 * 1024 * 1024 // 10MB maximum for mime detection

func GetMimeDetails(fileHeader *multipart.FileHeader, file multipart.File) (string, string, string, error) {
var err error
var fileType string

// Check that file size is reasonable before reading
if fileHeader.Size <= 0 || fileHeader.Size > MaxMimeReadSize {
return "", "", "", fmt.Errorf("file size %d exceeds allowed limit", fileHeader.Size)
}

// Get the file type from the header
buf := make([]byte, fileHeader.Size)
_, err = file.Read(buf)
Copilot is powered by AI and may make mistakes. Always verify output.
Unable to commit as this autofix suggestion is now outdated

mime := mimetype.Detect(buf)
key := fmt.Sprintf("%s/%s.%s", fileType, filename, mime.Extension())
buf := make([]byte, header.Size)

Check failure

Code scanning / CodeQL

Slice memory allocation with excessive size value High

This memory allocation depends on a
user-provided value
.
This memory allocation depends on a
user-provided value
.

Copilot Autofix

AI about 1 month ago

To fix this vulnerability, the function allocating the slice (encode) must not blindly trust header.Size. It should enforce a reasonable maximum limit (e.g., 32MB or less, based on system needs and policies), and return an error if the file is too large.

  • In internal/service/file/file_service.go, inside func (s *Service) encode(file multipart.File, header *multipart.FileHeader), before the slice allocation (line 234), add a check that header.Size is within an acceptable range (e.g., header.Size <= MAX_SIZE && header.Size >= 0). If it's not, return an error.
  • Define a suitable const maxUploadSize in the file.
  • No new imports are needed, only an error return if the file size is exceeded.
  • The rest of the function can remain unchanged.

Suggested changeset 1
internal/service/file/file_service.go

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/internal/service/file/file_service.go b/internal/service/file/file_service.go
--- a/internal/service/file/file_service.go
+++ b/internal/service/file/file_service.go
@@ -17,6 +17,9 @@
 	"github.com/uptrace/bun"
 )
 
+
+const maxUploadSize = 32 << 20 // 32 MB, adjust as needed
+
 type Service struct {
 	db      *bun.DB
 	storage storage.StorageLayer
@@ -231,6 +234,10 @@
 		return nil, err
 	}
 
+	if header.Size < 0 || header.Size > maxUploadSize {
+		return nil, errors.New("uploaded file size exceeds the allowed maximum")
+	}
+
 	buf := make([]byte, header.Size)
 	_, err := file.Read(buf)
 	if err != nil {
EOF
@@ -17,6 +17,9 @@
"github.com/uptrace/bun"
)


const maxUploadSize = 32 << 20 // 32 MB, adjust as needed

type Service struct {
db *bun.DB
storage storage.StorageLayer
@@ -231,6 +234,10 @@
return nil, err
}

if header.Size < 0 || header.Size > maxUploadSize {
return nil, errors.New("uploaded file size exceeds the allowed maximum")
}

buf := make([]byte, header.Size)
_, err := file.Read(buf)
if err != nil {
Copilot is powered by AI and may make mistakes. Always verify output.
Unable to commit as this autofix suggestion is now outdated
Comment on lines +11 to +42
name: Lint frontend
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./web

strategy:
matrix:
node-version: [22]

steps:
- uses: actions/checkout@v4

- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 10

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache-dependency-path: ./web/pnpm-lock.yaml
cache: 'pnpm'

- name: Install dependencies
run: pnpm install

- name: Run lint
run: pnpm lint

lint_backend:

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}

Copilot Autofix

AI about 1 month ago

To fix the problem, add a permissions block to the lint_frontend job in .github/workflows/lint.yml, matching the minimal set required for the job: contents: read. This should be placed on the same level as other job keys like runs-on and defaults. By setting permissions: contents: read, we ensure the job cannot inadvertently write to repository contents or access other scopes unnecessarily. No further changes are needed, as this addition does not affect job functionality.

Suggested changeset 1
.github/workflows/lint.yml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml
--- a/.github/workflows/lint.yml
+++ b/.github/workflows/lint.yml
@@ -10,6 +10,8 @@
   lint_frontend:
     name: Lint frontend
     runs-on: ubuntu-latest
+    permissions:
+      contents: read
     defaults:
       run:
         working-directory: ./web 
EOF
@@ -10,6 +10,8 @@
lint_frontend:
name: Lint frontend
runs-on: ubuntu-latest
permissions:
contents: read
defaults:
run:
working-directory: ./web
Copilot is powered by AI and may make mistakes. Always verify output.
@itschip itschip merged commit ca18b8f into master Dec 2, 2025
6 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants