Vulnerable Components in Feathersjs
How Vulnerable Components Manifests in Feathersjs
Vulnerable Components in Feathersjs applications typically stem from outdated dependencies in the node_modules directory. Feathersjs, being built on Express and leveraging numerous npm packages, inherits the same dependency management risks as any Node.js application. The most common attack vectors include:
- Exploitation of known vulnerabilities in Express middleware versions
- Prototype pollution through unsafe object merging in Feathersjs services
- Deserialization attacks via outdated body-parser or similar middleware
- Server-side request forgery through vulnerable HTTP client libraries
A particularly Feathersjs-specific manifestation occurs in service hooks. Consider this vulnerable pattern:
const { authenticate } = require('feathers-authentication');
module.exports = {
before: {
all: [ authenticate('jwt') ]
},
after: {
all: [
async context => {
// Vulnerable: unsafely merging user input
const unsafeMerge = require('merge');
context.result = unsafeMerge(context.result, context.params.query);
}
]
}
};
This hook uses an outdated 'merge' package that's vulnerable to prototype pollution. An attacker could manipulate the query parameters to overwrite Object.prototype properties, potentially leading to information disclosure or denial of service.
Another Feathersjs-specific vulnerability appears in real-time socket connections. The feathers-socketio adapter uses socket.io under the hood, which has had its own share of vulnerabilities:
const socketio = require('socket.io');
const io = socketio(server);
io.on('connection', socket => {
socket.on('join-room', room => {
// Vulnerable: no validation of room parameter
socket.join(room);
});
});
If the socket.io version is outdated, an attacker could exploit known vulnerabilities to execute arbitrary code or perform denial of service attacks on the real-time connection layer.
Feathersjs-Specific Detection
Detecting vulnerable components in Feathersjs requires a multi-layered approach. Start with npm audit, which checks your package.json and package-lock.json against the npm security database:
npm audit
For Feathersjs applications, pay special attention to these commonly vulnerable packages:
- express (the foundation of Feathersjs)
- feathers-* family packages (authentication, socketio, primus, etc.)
- body-parser and related middleware
- mongoose or other database adapters
- socket.io and socket.io-client
- Analyzing HTTP response headers for server information disclosure
- Testing for known vulnerable endpoint patterns
- Checking for deprecated API endpoints that might indicate outdated versions
- Scanning for common attack vectors like prototype pollution and deserialization
middleBrick's black-box scanning approach is particularly effective for Feathersjs applications because it tests the actual running API without requiring source code access. The scanner identifies vulnerable components by:
Here's how to scan a Feathersjs API with middleBrick CLI:
npm install -g middlebrick
middlebrick scan https://api.yourservice.com
The scan will test for vulnerable components across all 12 security categories, with special attention to the Input Validation and Encryption categories that often reveal dependency-related issues in Feathersjs applications.
For continuous monitoring, the middleBrick GitHub Action can be added to your CI/CD pipeline:
- name: middleBrick API Security Scan
uses: middlebrick/middlebrick-action@v1
with:
target: 'https://staging.yourservice.com'
fail-on-severity: 'high'
token: ${{ secrets.MIDDLEBRICK_TOKEN }}
This ensures that any vulnerable components introduced in new deployments are caught before production release.
Feathersjs-Specific Remediation
Remediating vulnerable components in Feathersjs requires both dependency updates and secure coding practices. Start with the most critical step: updating all dependencies to their latest secure versions:
npm update
npm audit fix
For Feathersjs-specific vulnerabilities, implement these secure patterns:
Secure Service Hooks
Replace unsafe merging with explicit property assignment:
const { BadRequest } = require('@feathersjs/errors');
module.exports = {
after: {
all: [
async context => {
if (context.params.query && Object.keys(context.params.query).length > 0) {
throw new BadRequest('Query parameters not allowed in response');
}
return context;
}
]
}
};
Input Validation with Feathersjs Schemas
Use Feathersjs's built-in schema validation to prevent prototype pollution:
const { BadRequest } = require('@feathersjs/errors');
const secureHook = context => {
const data = context.data || context.params.query;
// Prevent prototype pollution
if (data && (data.__proto__ || data.constructor.prototype)) {
throw new BadRequest('Unsafe object properties detected');
}
// Validate against known schema
const allowedProperties = ['name', 'email', 'age'];
Object.keys(data).forEach(key => {
if (!allowedProperties.includes(key)) {
throw new BadRequest(`Invalid property: ${key}`);
}
});
return context;
};
Secure Real-time Connections
Update socket.io and implement room validation:
const io = require('socket.io')(server, {
cors: {
origin: process.env.ALLOWED_ORIGINS?.split(',') || ['http://localhost:3000'],
methods: ['GET', 'POST']
}
});
io.on('connection', socket => {
socket.on('join-room', room => {
// Validate room name format
if (!/^[a-zA-Z0-9_-]+$/.test(room)) {
socket.emit('error', 'Invalid room format');
return;
}
socket.join(room);
});
});
Regular Security Scanning
Integrate middleBrick's continuous monitoring into your Feathersjs application:
// In your main app file
const middleBrick = require('middlebrick');
const app = express(feathers());
// Schedule regular security scans
setInterval(async () => {
try {
const result = await middleBrick.scan({
url: process.env.API_URL,
apiKey: process.env.MIDDLEBRICK_API_KEY
});
if (result.score < 80) {
console.warn('Security score dropped:', result.score);
// Send alert or trigger remediation workflow
}
} catch (error) {
console.error('Security scan failed:', error);
}
}, 24 * 60 * 60 * 1000); // Daily scan
By combining dependency updates, secure coding patterns, and continuous monitoring, you can effectively mitigate vulnerable components in your Feathersjs application. The middleBrick scanner provides the ongoing assurance that new vulnerabilities won't slip through undetected.