Skip to content

Fix/security and bugs#95

Open
Rajaykumar12 wants to merge 7 commits into
masterfrom
fix/security-and-bugs
Open

Fix/security and bugs#95
Rajaykumar12 wants to merge 7 commits into
masterfrom
fix/security-and-bugs

Conversation

@Rajaykumar12

Copy link
Copy Markdown
Collaborator

Summary

  • [security] Replace Math.random() with crypto.randomBytes for generating AUTH_SECRET, POSTGRES_PASSWORD, and REDIS_PASSWORDMath.random is not cryptographically secure
  • [security] Add path traversal boundary check in admin UI file server — reject requests where the resolved path escapes the dist directory with a 403
  • [schema] Add missing violations and status fields to the Contest Mongoose schema — both were read/written throughout the codebase but absent from the schema, causing Mongoose to silently discard all writes
  • [bug] Eliminate TOCTOU race condition in join ID generation — replace the check-then-save loop with a retry-on-duplicate-key strategy that lets the MongoDB unique index enforce atomicity
  • [bug] Fix submission saves not persisting to MongoDB — new Submission() pre-assigns _id, so the old !submission._id guard was always false and the document was never inserted; replaced with Submission.create() for new docs and findByIdAndUpdate for updates
  • [bug] Fix MCQ problem navigation filtering — p.questionType is deprecated; switch to p.type === "mcq" / p.type === "coding" so MCQ/coding tabs sort correctly in the attempt view
  • [bug] Add NaN guard on MCQ correctAnswer index parsing — malformed stored values no longer crash the scorer
  • [bug] Guard NaN in admin daemon disk usage — du output mismatch no longer propagates NaN bytes to the status API
  • [cleanup] Remove unused jwtVerify import from contestAuth middleware
  • [cleanup] Remove no-op setLiveLog((prev) => prev || null) identity call in LogsContext on stream end
  • [cleanup] Wrap all localStorage calls in try/catch to handle private browsing and storage quota errors

Replace Math.random()-based genSecret with Node crypto.randomBytes
to generate AUTH_SECRET, POSTGRES_PASSWORD, and REDIS_PASSWORD.
Add boundary check to ensure resolved file path stays within the
dist directory before serving, returning 403 for traversal attempts.
Both fields were referenced throughout the codebase but absent from
the schema, causing Mongoose to silently discard writes to them.
Replace pre-check uniqueness loop with a retry-on-duplicate strategy
that relies on the MongoDB unique index to atomically enforce uniqueness,
preventing duplicate joinId collisions under concurrent requests.
Use Submission.create() for new submissions (Mongoose pre-assigns _id
on construction so the old guard was always false) and findByIdAndUpdate
with $set/$push for updates, ensuring concurrent submits do not
overwrite each other and data is always persisted to MongoDB.

Also add NaN guard on MCQ correctAnswer index parsing to handle
malformed stored values without crashing.
Add isNaN check after parsing du output to avoid propagating NaN
bytes when the command returns unexpected output.
- Remove unused jwtVerify import from contestAuth middleware
- Fix MCQ problem filtering to use p.type instead of deprecated
  p.questionType field, correcting nav order in attempt view
- Remove no-op setLiveLog identity call in LogsContext on stream end
- Wrap all localStorage calls in try-catch to handle private browsing
  and storage quota errors gracefully
@Rajaykumar12 Rajaykumar12 requested a review from JustModo June 7, 2026 03:52
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.

1 participant