Skip to content

fix: eliminate Go security findings and harden file handling - #2

Draft
keller0 wants to merge 5 commits into
masterfrom
cursor/security-upgrades-37e1
Draft

fix: eliminate Go security findings and harden file handling#2
keller0 wants to merge 5 commits into
masterfrom
cursor/security-upgrades-37e1

Conversation

@keller0

@keller0 keller0 commented Jul 23, 2026

Copy link
Copy Markdown
Owner

Summary

  • upgrade Go version directive to 1.25.12 to pull in patched standard-library security fixes
  • upgrade direct dependencies to latest stable (cobra)
  • remove gin stack and refactor HTTP server to standard library net/http
  • remove the transitive gin -> validator -> golang.org/x/crypto dependency chain that kept surfacing module-level security warnings
  • add server-side file name sanitization to prevent path traversal style inputs on upload/delete
  • add mutex protection for shared in-memory state accessed by concurrent requests
  • add unit and HTTP handler tests for core share flows

Why

Repository security checks initially showed reachable vulnerabilities and additional module warnings. After dependency upgrades there was still an unfixed module-level advisory tied to golang.org/x/crypto/openpgp in transitive dependencies. Replacing gin with standard library handlers removes that dependency chain entirely and reduces attack surface. Tests lock in the new HTTP behavior and security hardening.

Changes

  • http.go
    • replaced gin routes with net/http handlers for /, /submit, /clearAll, /deleteFile, /upload, static routes
    • added sanitizeFileName validation for upload/delete file names
    • added JSON helper and template render helper
    • added sync.RWMutex to guard shared state (sData, imgList, fileList)
    • serve uploaded files from http.Dir(tmpFileDir) so absolute and relative folders both work
  • http_test.go
    • unit tests for sanitizeFileName and isImgSimple
    • HTTP tests for index, submit, upload, serve, delete, clearAll, method checks, and old-file loading
  • go.mod
    • removed gin and all related transitive web stack modules
    • retained only cobra direct dependency
  • go.sum
    • regenerated to match reduced dependency graph

Validation

  • go test -v -race -buildvcs ./...
  • go test -cover ./... (about 70.7% statement coverage)
  • govulncheck ./...
  • govulncheck -show verbose ./...

All validation commands pass and govulncheck reports No vulnerabilities found.

Open in Web Open in Cursor 

cursoragent and others added 4 commits July 23, 2026 13:34
Co-authored-by: keller0 <caijiaqi2017@gmail.com>
Co-authored-by: keller0 <caijiaqi2017@gmail.com>
Co-authored-by: keller0 <caijiaqi2017@gmail.com>
…tack

Co-authored-by: keller0 <caijiaqi2017@gmail.com>
@cursor cursor Bot changed the title chore: upgrade Go toolchain and dependencies for security fixes fix: eliminate Go security findings and harden file handling Jul 23, 2026
Add unit and httptest coverage for sanitize/isImg helpers and the
main endpoints (submit, upload, delete, clearAll, index). Also fix
static file serving to use tmpFileDir directly so absolute test dirs work.

Co-authored-by: keller0 <caijiaqi2017@gmail.com>
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