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): pharmacare.contactus@gmail.com / 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):pharmacare.contactus@gmail.com/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