Skip to content

Fix multiple security vulnerabilities (CWE-798, CWE-915, CWE-347, CWE-942)#28

Open
saaa99999999 wants to merge 1 commit into
makinhs:masterfrom
saaa99999999:fix/security-vulnerabilities
Open

Fix multiple security vulnerabilities (CWE-798, CWE-915, CWE-347, CWE-942)#28
saaa99999999 wants to merge 1 commit into
makinhs:masterfrom
saaa99999999:fix/security-vulnerabilities

Conversation

@saaa99999999
Copy link
Copy Markdown

This PR fixes multiple security vulnerabilities in the REST API tutorial reference implementation.

CWE-798: Hardcoded JWT Secret

  • env.config.js contained a hardcoded JWT secret "myS33!!creeeT" in source control. Replaced with environment variable JWT_SECRET with startup validation.

CWE-915: Mass Assignment / Privilege Escalation

  • users.controller.js PATCH endpoint passed the entire request body to Mongoose without field filtering. An authenticated user could set permissionLevel: 2048 to become admin. Added field allowlist to restrict updatable fields to firstName, lastName, email, password.

CWE-347: JWT Refresh Key Embedded in Token

  • authorization.controller.js included the refresh token HMAC salt (refreshKey) inside the JWT payload, allowing anyone with a valid JWT to generate new refresh tokens. Fixed by using a self-contained salt.hash format for refresh tokens and signing only user claims in the JWT.

CWE-942: CORS Wildcard with Credentials

  • index.js used Access-Control-Allow-Origin: * with Access-Control-Allow-Credentials: true, an insecure combination. Fixed to echo the request origin.

- CWE-798: Remove hardcoded JWT secret "myS33!!creeeT", require JWT_SECRET env var
- CWE-915: Add field allowlist to user PATCH to prevent privilege escalation
- CWE-347: Remove refreshKey from JWT payload, use combined salt.hash format
- CWE-942: Fix CORS wildcard with credentials=true misconfiguration

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@saaa99999999
Copy link
Copy Markdown
Author

CVE Request — Action Needed from Maintainer

This PR fixes security vulnerabilities. To assign a CVE number:

GitHub only issues CVEs from the official upstream repository, not from forks.

Please:

  1. Go to this repo → SecurityAdvisoriesNew draft security advisory
  2. Add @saaa99999999 as a collaborator
  3. I will populate the full vulnerability details (CVSS, CWE, data flow, PoC) and submit the CVE request

If you prefer, I can submit the CVE via MITRE (cveform.mitre.org) instead — just let me know.

Thank you for reviewing this PR!

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