Summary
This pharmacy management system has zero authentication on 31 of 34 backend API endpoints. Only 3 supplier endpoints (POST/PUT/DELETE) use checkAuth middleware. All other endpoints β inventory, sales, doctor orders, user management β are fully accessible without login. Additionally, MongoDB Atlas credentials, Gmail SMTP credentials, and JWT signing keys are hardcoded in the source code of this public repository.
Critical: Hardcoded Credentials (3 findings)
- MongoDB Atlas (
app.js:18): mongodb+srv://lalana:OJx2X4IllVNl9up4@... β anyone can connect directly to the database
- SMTP (
inventory.js:224): [email protected] / lalana1011294
- JWT Secret (
user.js:63): 'this_is_the_webToken_secret_key' β anyone can forge valid tokens
Immediate action needed: Rotate all credentials. These are exposed in a public GitHub repository.
Critical: Zero Authentication (7 finding groups)
- All 10 inventory endpoints (
inventory.js) β full CRUD on drug inventory without auth
- All 3 sales endpoints (
sales.js) β financial data readable/writable
- All 3 doctor order endpoints (
doctorOders.js) β create/view/delete orders
- All 3 verified order endpoints (
verifiedDoctorOder.js) β verify/delete orders
- All 2 picked-up order endpoints (
pickedUpOders.js) β complete order flow
- All 5 user management endpoints (
user.js:80-126) β list/update/delete users (returns password hashes!)
- All 5 doctor management endpoints (
doctorUser.js:78-122) β same as above for doctors
Critical: Self-Registration with Arbitrary Role
POST /api/user/signup (user.js:7-34): Accepts role from request body β anyone self-registers as admin.
High Findings
- Supplier GET endpoints unauthenticated (
supplier.js:41,51) β 1-of-N: POST/PUT/DELETE have auth, GET does not
- NoSQL injection in login (
user.js:40) β findOne({email: req.body.email}) without type validation
- Unauthenticated email relay (4
/sendmail endpoints) β SMTP abuse
- HTML injection in email templates β user input interpolated into HTML emails
- JWT secret mismatch (
check-docAuth.js:6) β doctor auth middleware permanently broken (verifies with '..._keys' vs signed with '..._key')
- Password hashes in API responses β no
.select('-password') on queries
Medium
- Frontend-only AuthGuard β Angular guard on 2 of ~20 routes
Impact
This is a pharmacy system handling controlled substances. An attacker can:
- Access all drug inventory and modify quantities/prices
- Create fraudulent doctor orders for controlled substances
- Self-verify and mark orders as picked up
- Read all user/doctor PII including password hashes
- Register as admin
- Send emails via the pharmacy's SMTP account
Recommended Fixes
- Rotate all hardcoded credentials immediately β MongoDB password, Gmail password, JWT secret
- Move secrets to environment variables β use
.env file with dotenv, add .env to .gitignore
- Apply
checkAuth middleware globally β add to all route files, not just supplier
- Validate
role on signup β reject or ignore role from request body, default to lowest privilege
- Add
.select('-password') to all user/doctor queries
- Fix JWT secret mismatch in
check-docAuth.js
- Add input validation β use a library like
express-validator or joi to validate request bodies before passing to MongoDB
Summary
This pharmacy management system has zero authentication on 31 of 34 backend API endpoints. Only 3 supplier endpoints (POST/PUT/DELETE) use
checkAuthmiddleware. All other endpoints β inventory, sales, doctor orders, user management β are fully accessible without login. Additionally, MongoDB Atlas credentials, Gmail SMTP credentials, and JWT signing keys are hardcoded in the source code of this public repository.Critical: Hardcoded Credentials (3 findings)
app.js:18):mongodb+srv://lalana:OJx2X4IllVNl9up4@...β anyone can connect directly to the databaseinventory.js:224):[email protected]/lalana1011294user.js:63):'this_is_the_webToken_secret_key'β anyone can forge valid tokensImmediate action needed: Rotate all credentials. These are exposed in a public GitHub repository.
Critical: Zero Authentication (7 finding groups)
inventory.js) β full CRUD on drug inventory without authsales.js) β financial data readable/writabledoctorOders.js) β create/view/delete ordersverifiedDoctorOder.js) β verify/delete orderspickedUpOders.js) β complete order flowuser.js:80-126) β list/update/delete users (returns password hashes!)doctorUser.js:78-122) β same as above for doctorsCritical: Self-Registration with Arbitrary Role
POST /api/user/signup(user.js:7-34): Acceptsrolefrom request body β anyone self-registers as admin.High Findings
supplier.js:41,51) β 1-of-N: POST/PUT/DELETE have auth, GET does notuser.js:40) βfindOne({email: req.body.email})without type validation/sendmailendpoints) β SMTP abusecheck-docAuth.js:6) β doctor auth middleware permanently broken (verifies with'..._keys'vs signed with'..._key').select('-password')on queriesMedium
Impact
This is a pharmacy system handling controlled substances. An attacker can:
Recommended Fixes
.envfile withdotenv, add.envto.gitignorecheckAuthmiddleware globally β add to all route files, not just supplierroleon signup β reject or ignore role from request body, default to lowest privilege.select('-password')to all user/doctor queriescheck-docAuth.jsexpress-validatororjoito validate request bodies before passing to MongoDB