Security Misconfiguration
Default credentials, exposed debug endpoints, verbose error messages, and production hardening checklist
Skills taught: websecurity.misconfiguration, websecurity.default-credentials, websecurity.debug-endpoints, websecurity.error-handling, websecurity.cloud-iam
Common misconfiguration patterns
DEFAULT CREDENTIALS:
Database installed with root/admin + no password (MySQL, MongoDB, Redis)
Admin panels with admin/admin or admin/password (Jenkins, Grafana, phpMyAdmin)
Cloud services with default IAM policies (wide-open S3 buckets)
Fix: change all defaults before connecting to any network
EXPOSED DEBUG ENDPOINTS:
/debug, /status, /metrics — internal endpoints publicly accessible
Spring Boot Actuator /actuator/env exposing environment variables
Rails /rails/info/properties in production
GraphQL introspection enabled in production (reveals full schema)
Fix: disable in production, restrict to internal network / VPN IP ranges
VERBOSE ERROR MESSAGES:
Stack traces with file paths, library versions, internal IPs in production
SQL errors exposing table/column names: 'column password_hash does not exist'
Fix: catch all errors, log internally, return generic messages to clients
DIRECTORY LISTING:
Web server configured to show file lists for directories without index.html
Exposes source files, config files, uploaded documents
Fix: disable in nginx (autoindex off;) and Apache (Options -Indexes)
UNNECESSARY OPEN PORTS:
Database port 5432 (PostgreSQL) exposed to public internet
Redis port 6379 open — Redis has no auth by default
Fix: firewall rules to allow database access only from app servers
Cloud: security groups should only allow necessary traffic
Error handling — don't leak internals
// VULNERABLE — sends stack trace and internal details to client
app.get('/user/:id', async (req, res) => {
const user = await db.query(`SELECT * FROM users WHERE id = ${req.params.id}`);
res.json(user);
// If this fails: stack trace including file paths, DB schema, library versions
// goes directly to the client — a goldmine for attackers
});
// SECURE — catch errors, log internally, return generic message
app.get('/user/:id', async (req, res) => {
try {
const user = await db.users.findById(req.params.id);
res.json(user);
} catch (error) {
// Log the full error internally for debugging
logger.error({ err: error, userId: req.params.id }, 'Failed to fetch user');
// Return nothing useful to the client
res.status(500).json({ error: 'Internal server error' });
}
});
// Global error handler — catches any unhandled errors
app.use((err: Error, req: Request, res: Response, next: NextFunction) => {
// Log full error (including stack trace) to your logging service
logger.error({ err, url: req.url, method: req.method }, 'Unhandled error');
// In development: show the error (useful for debugging)
if (process.env.NODE_ENV === 'development') {
return res.status(500).json({ error: err.message, stack: err.stack });
}
// In production: generic message only
res.status(500).json({ error: 'Something went wrong' });
});
// Disable framework fingerprinting headers
app.disable('x-powered-by'); // Remove 'X-Powered-By: Express' header
// Attackers use this to identify your framework and look for version-specific exploits
// GraphQL — disable introspection in production
import { ApolloServer } from '@apollo/server';
const server = new ApolloServer({
typeDefs,
resolvers,
// Introspection lets anyone query your entire schema
// Useful in development, a recon tool in production
introspection: process.env.NODE_ENV !== 'production',
});
// Express — disable development-only middleware in production
if (process.env.NODE_ENV !== 'production') {
app.use('/debug/config', (req, res) => {
res.json({
env: process.env.NODE_ENV,
dbHost: process.env.DB_HOST,
// ... other debug info
});
});
}
// This endpoint ONLY exists in development — never in production
// Environment check middleware for admin/monitoring endpoints
function internalOnly(req: Request, res: Response, next: NextFunction) {
const internalIPs = ['127.0.0.1', '10.0.0.0/8']; // Localhost + internal network
const clientIP = req.ip || req.socket.remoteAddress;
// Simple check — in production use a proper IP range library (ip-range-check)
if (clientIP === '127.0.0.1' || clientIP?.startsWith('10.')) {
return next();
}
res.status(404).json({ error: 'Not found' });
}
app.use('/metrics', internalOnly, metricsHandler);
app.use('/health', internalOnly, healthHandler); // Or make /health public for load balancers
Frequently Asked Questions
How do I make sure debug configuration is never accidentally deployed to production?
Gate all debug behavior on NODE_ENV checks, and enforce that NODE_ENV=production in your deployment environment via your hosting platform's environment variable config (Railway, Render, Vercel, etc.). Never hardcode NODE_ENV in your committed code — set it in the deployment environment. For extra safety, use a separate startup script for production that validates required env vars and fails fast if debug flags are set. Many teams also run configuration audits as part of their CI pipeline.