Missing Authentication in Feathersjs with Hmac Signatures
Missing Authentication in Feathersjs with Hmac Signatures — how this specific combination creates or exposes the vulnerability
FeathersJS is a framework for real-time applications that can expose service endpoints over HTTP and WebSocket. When Hmac Signatures are used for request authentication, missing or weak authentication enforcement at the FeathersJS service layer can allow unauthenticated actors to invoke protected methods. This specific combination—FeathersJS services configured with Hmac Signatures but without proper middleware-level authentication—creates a BOLA/IDOR and authentication bypass risk.
Hmac Signatures typically involve a client generating a signature from a shared secret combined with request metadata (timestamp, nonce, method, and payload). If the FeathersJS service does not validate the signature on every request or skips validation for certain routes, an attacker can replay or forge requests using known or guessed parameters. For example, a DELETE /users/:id endpoint protected only by query parameters but lacking a signature check will allow direct manipulation of other users’ records when IDOR is present.
In practice, missing authentication manifests when developers rely solely on transport security (HTTPS) or assume client-side signing is sufficient without server-side validation in each FeathersJS hook or service method. Attackers can probe unauthenticated attack surfaces using tools like middleBrick, which runs 12 security checks in parallel including Authentication, BOLA/IDOR, and Unsafe Consumption. These checks detect whether endpoints require valid Hmac Signatures and whether signature validation is consistently enforced across service hooks, routes, and custom methods.
Real-world attack patterns include replaying a captured request with a valid Hmac Signature but altered resource identifiers, exploiting missing ownership checks to escalate privileges (BFLA/Privilege Escalation), or consuming excessive API calls due to absent rate limiting. middleBrick’s LLM/AI Security checks are unique in detecting whether endpoints leak system prompts or allow prompt injection, though in this context they highlight insecure API design rather than language model misuse.
An insecure FeathersJS service might accept a request like DELETE /api/users/123 without verifying that the Hmac Signature corresponds to the authenticated user or that the requesting actor has permission to delete that specific resource. The framework’s flexibility with hooks means that without a global before hook validating the signature and binding the request to a user identity, the service operates as if authentication is unnecessary. This misconfiguration aligns with OWASP API Top 10:2023 broken object level authorization and can be mapped to compliance frameworks such as PCI-DSS and SOC2.
Hmac Signatures-Specific Remediation in Feathersjs — concrete code fixes
To remediate missing authentication with Hmac Signatures in FeathersJS, enforce signature validation in a global before hook so that every request is authenticated before reaching any service. Below is a syntactically correct example of how to implement Hmac validation and bind the request identity in a FeathersJS before hook.
const crypto = require('crypto');
function verifyHmacSignature(secret) {
return (context) => {
const { headers } = context;
const receivedSignature = headers['x-hmac-signature'];
const timestamp = headers['x-timestamp'];
const nonce = headers['x-nonce'];
if (!receivedSignature || !timestamp || !nonce) {
throw new Error('Missing Hmac headers');
}
// Prevent replay attacks by checking timestamp window (e.g., 5 minutes)
const now = Date.now();
const requestTime = parseInt(timestamp, 10);
if (Math.abs(now - requestTime) > 5 * 60 * 1000) {
throw new Error('Request expired');
}
const payload = context.method === 'GET'
? timestamp + nonce
: timestamp + nonce + JSON.stringify(context.data || context.body);
const computedSignature = crypto
.createHmac('sha256', secret)
.update(payload)
.digest('hex');
if (!crypto.timingSafeEqual(Buffer.from(receivedSignature), Buffer.from(computedSignature))) {
throw new Error('Invalid Hmac signature');
}
// Bind identity to the context for downstream authorization
context.params.user = {
role: 'authenticated',
scope: 'hmac'
};
return context;
};
}
module.exports = function (app) {
const secret = process.env.HMAC_SECRET;
app.hooks.before.push(verifyHmacSignature(secret));
// Ensure services check permissions; example for a users service
app.service('users').hooks({
before: {
async get(context) {
const { user, params } = context;
const requestedId = context.id;
// BOLA/IDOR protection: users can only access their own data unless admin
if (user.role !== 'admin' && requestedId !== user.id) {
throw new Error('Unauthorized');
}
return context;
},
async create(context) {
// Example: enforce property-level authorization on email uniqueness
const existing = await context.app.service('users').Model.findOne({ email: context.data.email });
if (existing) {
throw new Error('Email already registered');
}
return context;
}
}
});
};
The example includes timestamp and nonce checks to mitigate replay attacks, uses crypto.timingSafeEqual to prevent timing attacks, and binds user identity into context.params.user for downstream authorization in service hooks. This approach ensures that Hmac Signatures are validated consistently, addressing Authentication and BOLA/IDOR risks.
Additionally, enforce rate limiting and property-level authorization for sensitive operations (e.g., DELETE /users/:id) to prevent privilege escalation and data exposure. middleBrick’s Pro plan supports continuous monitoring and CI/CD integration, allowing you to fail builds if risk scores exceed your threshold and to scan staging APIs before deploy.
When using the CLI, run middlebrick scan <url> to validate your endpoints, or integrate the GitHub Action to automate security checks in your pipeline. The MCP Server enables scanning APIs directly from AI coding assistants within your IDE, helping you detect insecure patterns early.
Related CWEs: authentication
| CWE ID | Name | Severity |
|---|---|---|
| CWE-287 | Improper Authentication | CRITICAL |
| CWE-306 | Missing Authentication for Critical Function | CRITICAL |
| CWE-307 | Brute Force | HIGH |
| CWE-308 | Single-Factor Authentication | MEDIUM |
| CWE-309 | Use of Password System for Primary Authentication | MEDIUM |
| CWE-347 | Improper Verification of Cryptographic Signature | HIGH |
| CWE-384 | Session Fixation | HIGH |
| CWE-521 | Weak Password Requirements | MEDIUM |
| CWE-613 | Insufficient Session Expiration | MEDIUM |
| CWE-640 | Weak Password Recovery | HIGH |