Skip to content

[nsoc] Comprehensive Code Audit: 20 Bugs and Issues Found #128

Description

@jeeva5655

Comprehensive Code Audit: 20 Bugs and Issues Found

As part of the Nexus Spring of Code (nsoc), I have conducted a thorough code review and identified the following meaningful bugs and issues in this repository. I would like to be assigned to fix these.

  1. CORS allows all origins with credentials (main.py:92-98) - allow_origins=["*"] combined with allow_credentials=True is a security misconfiguration. Browsers block this combination, but it indicates an insecure design intent.

  2. Default admin password is hardcoded (main.py:134) - When users.json does not exist, the system creates an "admin" account with password "admin123". This is a well-known default credential.

  3. users.json is a flat file database (main.py:132-149) - User credentials are stored in a JSON file. This has no concurrent access protection - multiple simultaneous registrations could corrupt the file.

  4. Deprecated datetime.utcnow() usage (main.py:157) - datetime.utcnow() is deprecated in Python 3.12+. Should use datetime.now(timezone.utc) instead.

  5. analyze_logs is synchronous and blocks the event loop (main.py:276) - The analyze_logs function in logic.py runs synchronously. When called from the async endpoint, it blocks the entire FastAPI event loop.

  6. .DS_Store file committed to repository - A macOS .DS_Store file is in the root directory, indicating the .gitignore is incomplete.

  7. Path traversal protection is incomplete (main.py:263) - The filename sanitization replaces ".." and "/" but does not handle URL-encoded sequences like %2e%2e or null bytes.

  8. SSE endpoint accepts arbitrary file_path via query parameter (main.py:288-290) - The /analyze-process endpoint takes file_path as a query parameter. A malicious user could pass any system path, leading to unauthorized file access.

  9. No password strength validation on /register (main.py:195-210) - The registration endpoint accepts any password, including single characters. There is no minimum length, complexity, or common password check.

  10. Rate limiter commented out on /verify-chain (main.py:339) - The @limiter.limit decorator is commented out on the verify-chain endpoint, allowing unlimited requests.

  11. Exception handler returns 404 HTML page for 500 errors (main.py:113-123) - The generic exception handler returns the 404.html template for all 500 errors. Users see a "Not Found" page when the real error is an internal server error.

  12. users.json is committed to repository (users.json) - The user database file with hashed passwords is committed to version control. This should be in .gitignore.

  13. No token refresh mechanism - JWTs expire after ACCESS_TOKEN_EXPIRE_MINUTES but there is no refresh token endpoint. Users must re-login.

  14. Upload directory is never cleaned up (main.py:127-128) - The UPLOAD_DIR is created at startup but files that fail to be deleted in the finally block accumulate.

  15. Insecure default set contains duplicates (main.py:40-41) - The _INSECURE_DEFAULTS set contains "change-this-to-a-long-random-secret-in-production" twice, which is harmless but indicates copy-paste errors.

  16. No content-type validation on file upload - The MIME type check uses python-magic which reads file bytes, but the Content-Type header sent by the client is never validated against the detected type.

  17. Chain verification response uses emoji in notes (main.py:387-391) - Emoji characters in API responses can cause encoding issues in some clients.

  18. No API documentation - The FastAPI app title is set but there are no endpoint descriptions or example responses in the Swagger UI.

  19. Missing logout endpoint - There is no endpoint to invalidate JWTs. Once a token is issued, it remains valid until expiry.

  20. No test suite - The repository has no tests for the authentication, file upload, or analysis endpoints.

Labels
bug, security, enhancement

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions