-
Notifications
You must be signed in to change notification settings - Fork 68
Feat/api security updates #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
15c53a2
e2ddf05
9ab1330
2caebbe
21e354d
fa0e865
6b23ae0
aeecf4d
84f26bb
0b183af
b001041
50b9b4a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,9 @@ app.set('trust proxy', 1); | |
| const GC = require('./utils/GC'); | ||
| const { getPublicIp } = require('./utils/network'); | ||
|
|
||
| // Initialize Queue Workers | ||
| require('./queues/emailQueue'); | ||
|
|
||
| // Middleware | ||
| app.use(cors()); | ||
| app.use(express.json()); | ||
|
|
@@ -34,7 +37,7 @@ const { authLimiter } = require('./middleware/auth_limiter'); | |
|
|
||
| const adminWhitelist = ['https://urbackend.bitbros.in']; | ||
|
|
||
| // to allow localhost in developmentt | ||
| // DEV LOCALHOST | ||
| if (process.env.NODE_ENV === 'development') { | ||
| adminWhitelist.push('http://localhost:5173'); | ||
| } | ||
|
|
@@ -46,8 +49,6 @@ const adminCorsOptions = { | |
| const allowed = !origin || adminWhitelist.includes(origin); | ||
|
|
||
| const end = process.hrtime.bigint(); | ||
| console.log("Pure CORS check time:", | ||
| Number(end - start) / 1e6, "ms"); | ||
|
|
||
| if (allowed) { | ||
| callback(null, true); | ||
|
|
@@ -65,7 +66,7 @@ if (process.env.NODE_ENV !== 'test') { | |
| } | ||
|
|
||
|
|
||
| // rate limiter and loggerr IMPORTS | ||
| // LOGGING | ||
| const { limiter, logger } = require('./middleware/api_usage'); | ||
|
|
||
| // Route Imports | ||
|
|
@@ -75,6 +76,7 @@ const dataRoute = require('./routes/data'); | |
| const userAuthRoute = require('./routes/userAuth'); | ||
| const storageRoute = require('./routes/storage'); | ||
| const schemaRoute = require('./routes/schemas'); | ||
| const releaseRoute = require('./routes/releases'); | ||
|
|
||
| // ROUTES SETUP | ||
| app.use('/api/auth/login', authLimiter); // Strict limiter on login | ||
|
|
@@ -85,6 +87,7 @@ app.use('/api/userAuth', limiter, logger, userAuthRoute); | |
| app.use('/api/data', limiter, cors(adminCorsOptions), logger, dataRoute); | ||
| app.use('/api/schemas', limiter, cors(adminCorsOptions), logger, schemaRoute); | ||
| app.use('/api/storage', limiter, cors(adminCorsOptions), logger, storageRoute); | ||
| app.use('/api/releases', releaseRoute); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: Missing authentication middleware on release routes causes runtime error and security bypass. The if (req.user.email !== ADMIN_EMAIL)Without auth middleware, 🔒 Proposed fix: Apply auth middleware in the route fileIn // CREATE RELEASE (Admin Only)
-router.post('/', createReleaseLimiter, createRelease);
+router.post('/', createReleaseLimiter, authorization, createRelease);🤖 Prompt for AI Agents |
||
|
|
||
| app.get('/api/server-ip', async (req, res) => { | ||
| const ip = await getPublicIp(); | ||
|
|
@@ -111,8 +114,7 @@ app.use((err, req, res, next) => { | |
| message: err.message | ||
| }); | ||
| }); | ||
| // DB and server initialization | ||
| // (Only connect if NOT in Test Mode) | ||
| // INITIALIZATION | ||
| if (process.env.NODE_ENV !== 'test') { | ||
|
|
||
| const PORT = process.env.PORT || 1234; | ||
|
|
@@ -145,7 +147,7 @@ if (process.env.NODE_ENV !== 'test') { | |
| console.log(`Server running on port ${PORT}`); | ||
| }); | ||
|
|
||
| // handle gracefll shutdwn | ||
| // SHUTDOWN | ||
| const gracefulShutdown = async () => { | ||
| console.log('🛑 SIGTERM/SIGINT received. Shutting down gracefully...'); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing error handling for Redis connection at startup.
The synchronous
require('./queues/emailQueue')initializes an IORedis connection immediately. If Redis is unavailable when the server starts, the connection will throw synchronously and crash the Express process before it can bind to a port.Consider adding connection error handlers or lazy initialization to allow the app to start gracefully and degrade when Redis is down.
🛡️ Suggested approach: wrap initialization with error handling
Alternatively, add
.on('error')handlers inemailQueue.jsto the IORedis connection to prevent unhandled exceptions.📝 Committable suggestion
🤖 Prompt for AI Agents