Excessive Data Exposure in Feathersjs with Hmac Signatures
Excessive Data Exposure in Feathersjs with Hmac Signatures
Excessive Data Exposure occurs when an API returns more data than the client is authorized to view. In Feathersjs applications that use Hmac Signatures for request authentication, this risk can be amplified when service methods return full database records without field-level filtering. Hmac Signatures typically involve a client-side secret used to sign requests; if the server returns sensitive fields such as internal IDs, password hashes, or tokens alongside the intended payload, an attacker who can observe or intercept the response gains unnecessary information that can be reused in downstream attacks.
Consider a Feathersjs service for user profiles that signs requests with Hmac. If the service returns the complete user document—including email, password hash, and internal flags—without explicitly selecting which properties to expose, any authenticated or even unauthenticated endpoint that lacks proper property-level authorization can lead to Excessive Data Exposure. This is especially dangerous when combined with misconfigured hooks where common hooks like before() or after() do not sanitize the data before it is serialized. For example, a client may only need a username and display name, but the service returns the entire record, inadvertently exposing fields that should remain restricted. In a black-box scan, middleBrick would flag this as a Data Exposure finding, noting that the response includes sensitive attributes not required by the operation. Attackers can chain this with other issues such as BOLA/IDOR to escalate access across different user records, harvesting additional sensitive data with minimal additional effort.
Feathersjs relies on adapters such as feathers-sequelize or feathers-mongoose, which by default may return all fields unless explicitly limited. If Hmac Signatures are used for integrity checks but the application does not enforce strict property selection, the signature verification may pass while the payload remains overly permissive. This creates a mismatch between integrity assurance and confidentiality enforcement. An attacker who can forge or replay signed requests might leverage overly broad responses to map the data model, discover hidden endpoints, or infer relationships between entities. Real-world examples include endpoints that return full JWTs, internal database IDs, or debug fields when only a subset of data is necessary for the client. middleBrick’s OpenAPI/Swagger analysis, with full $ref resolution, can detect such mismatches by comparing declared response schemas against actual runtime outputs, highlighting fields that are present but not documented as intended for public use.
To contextualize the risk, consider an endpoint defined as a Feathersjs service with Hmac verification in the transport layer but without proper serialization controls. A request signed with a shared secret may succeed in integrity checks, yet the response could include fields like isAdmin, resetToken, or raw password data if the service method does not apply explicit field masking. This scenario aligns with OWASP API Top 10:2023 A5 (Security Misconfiguration) and can be linked to compliance frameworks such as PCI-DSS and GDPR where data minimization is required. The exposure is not theoretical; tools like middleBrick demonstrate this by scanning unauthenticated attack surfaces and identifying response fields that should be restricted. The fix requires deliberate design in Feathersjs hooks and service methods to ensure that only necessary data is returned, regardless of signature validity.
Hmac Signatures-Specific Remediation in Feathersjs
Remediation focuses on ensuring that Feathersjs services enforce strict data exposure controls while preserving the integrity checks provided by Hmac Signatures. You should apply property-level selection in service methods and hooks, ensuring that responses exclude sensitive fields unless explicitly required. This can be achieved using Feathers hooks such as select or custom serialization logic within the after hook to strip unwanted fields before the response is sent.
Below are concrete code examples for Feathersjs that demonstrate secure handling with Hmac Signatures. The first example shows a service configuration where Hmac verification is applied at the transport or middleware layer, and the second demonstrates how to limit returned fields in an after hook.
// src/hooks/hmac-verify.js
const crypto = require('crypto');
module.exports = function hmacVerify(options) {
return async context => {
const { headers, method, url, body } = context.params;
const secret = process.env.HMAC_SECRET;
const providedSignature = headers['x-hmac-signature'];
const payload = typeof body === 'string' ? body : JSON.stringify(body);
const computedSignature = crypto.createHmac('sha256', secret).update(payload).digest('hex');
if (computedSignature !== providedSignature) {
throw new Error('Invalid Hmac signature');
}
return context;
};
};
This hook validates the Hmac signature before the request proceeds, ensuring that only authenticated clients can invoke the service. However, validation alone does not prevent excessive data exposure; you must also control the response content.
// src/hooks/remove-sensitive-fields.js
module.exports = function removeSensitiveFields() {
return async context => {
if (context.result && context.result.data) {
const records = Array.isArray(context.result.data) ? context.result.data : [context.result.data];
records.forEach(record => {
delete record.passwordHash;
delete record.resetToken;
delete record.isAdmin;
delete record.internalMeta;
});
if (!Array.isArray(context.result.data)) {
const single = { ...context.result.data };
delete single.passwordHash;
delete single.resetToken;
delete single.isAdmin;
delete single.internalMeta;
context.result.data = single;
}
}
return context;
};
};
In this example, the hook runs in the after phase and removes sensitive fields from the response. You should register these hooks in your service definition:
// src/services/user/user.service.js
const hmacVerify = require('../../hooks/hmac-verify');
const removeSensitiveFields = require('../../hooks/remove-sensitive-fields');
module.exports = function (app) {
const options = {
name: 'user',
paginate: { default: 10, max: 50 }
};
app.use('/users', require('feathers-sequelize')(options));
const service = app.service('users');
service.hooks({
before: {
all: [],
find: [],
get: [],
create: [hmacVerify],
update: [hmacVerify],
patch: [hmacVerify],
remove: [hmacVerify]
},
after: {
all: [removeSensitiveFields],
find: [],
get: [],
create: [],
update: [],
patch: [],
remove: []
},
error: {
all: [],
find: [],
get: [],
create: [],
update: [],
patch: [],
remove: []
}
});
};
By combining Hmac signature verification with explicit field removal in hooks, you ensure that integrity is maintained while minimizing the data exposed to clients. This approach aligns with the principle of least privilege and reduces the impact of potential misconfigurations. middleBrick’s CLI can be used to validate these controls by scanning endpoints and confirming that sensitive fields are absent from responses, even when Hmac signatures are valid.
Related CWEs: propertyAuthorization
| CWE ID | Name | Severity |
|---|---|---|
| CWE-915 | Mass Assignment | HIGH |