Mass Assignment with Mutual Tls
How Mass Assignment Manifests in Mutual Tls
Mass assignment vulnerabilities in Mutual Tls environments exploit the trust established through certificate-based authentication. When Mutual Tls verifies client certificates, developers often assume this authentication layer provides sufficient authorization, leading to permissive object binding patterns.
In Mutual Tls APIs, mass assignment typically occurs when certificate-authenticated requests bind client-provided JSON directly to server-side objects. Consider a banking API where Mutual Tls authenticates a client with certificate CN="bank-user-123". The server trusts this authentication and maps request payloads directly to account objects:
const express = require('express');
const app = express();
app.use(express.json());
app.post('/api/accounts/:id', (req, res) => {
const clientId = req.clientCert.subject.CN;
const accountId = req.params.id;
// Trust established via Mutual Tls
// BUT: direct object binding creates vulnerability
const updatedAccount = { ...req.body, id: accountId };
// Database update with potentially dangerous fields
db.accounts.update(accountId, updatedAccount);
});The critical flaw: a client authenticated via Mutual Tls can modify fields they shouldn't control, such as account.balance, account.status, or account.ownerId. Since Mutual Tls only verifies identity (who you are), not authorization (what you're allowed to do), this creates a privilege escalation vector.
Mutual Tls-specific attack patterns include:
- Certificate-bound privilege escalation: Attackers with valid certificates for one role exploit mass assignment to modify objects associated with higher-privilege accounts
- Cross-tenant data manipulation: In multi-tenant Mutual Tls deployments, authenticated clients modify objects belonging to other tenants
- Administrative field injection: Clients inject administrative properties like isAdmin, role, or permissions through mass assignment
- Audit bypass: Attackers modify audit fields like lastModifiedBy or modifiedAt to cover tracks
The vulnerability intensifies in Mutual Tls environments because developers often implement less granular authorization checks, assuming certificate authentication provides sufficient security boundaries.
Mutual Tls-Specific Detection
Detecting mass assignment in Mutual Tls APIs requires examining both the authentication layer and object binding patterns. The detection process focuses on identifying where certificate-authenticated endpoints perform unsafe object mapping.
Static analysis for Mutual Tls mass assignment includes:
// Vulnerable pattern - direct object spread
app.post('/api/orders/:id', (req, res) => {
const clientCert = req.clientCert.subject.CN;
const orderId = req.params.id;
// DANGEROUS: spreads all request properties
const orderUpdate = { ...req.body, id: orderId };
db.orders.update(orderId, orderUpdate);
});
// Safer pattern - explicit field whitelisting
app.post('/api/orders/:id', (req, res) => {
const clientCert = req.clientCert.subject.CN;
const orderId = req.params.id;
// SAFE: only allows specific fields
const allowedFields = ['shippingAddress', 'items', 'notes'];
const orderUpdate = { id: orderId };
for (const field of allowedFields) {
if (req.body[field] !== undefined) {
orderUpdate[field] = req.body[field];
}
}
db.orders.update(orderId, orderUpdate);
});Dynamic scanning with middleBrick specifically targets Mutual Tls mass assignment vulnerabilities by:
- Testing certificate-authenticated endpoints with payloads containing unexpected fields
- Verifying whether administrative or sensitive fields can be modified through object binding
- Checking for proper field validation and sanitization in Mutual Tls contexts
- Mapping authenticated attack surfaces to identify privilege escalation opportunities
middleBrick's Mutual Tls-aware scanning includes property authorization checks that specifically test whether authenticated clients can modify fields beyond their authorization scope. The scanner tests for patterns like:
// Test payload for mass assignment
{
"id": "target-account-456",
"balance": 999999.99,
"status": "ACTIVE",
"ownerId": "attacker-account-123",
"isAdmin": true,
"permissions": ["admin", "superuser"]
}The scanner verifies whether these fields are properly rejected or if they successfully modify the target object, providing severity ratings based on the sensitivity of modified properties.
Mutual Tls-Specific Remediation
Remediating mass assignment in Mutual Tls APIs requires combining proper object binding practices with authorization controls that respect the certificate authentication layer. The goal is to ensure that Mutual Tls identity verification is complemented by robust authorization checks.
Effective remediation patterns for Mutual Tls environments:
// 1. Explicit field whitelisting with authorization checks
app.post('/api/accounts/:id', async (req, res) => {
const clientCert = req.clientCert.subject;
const accountId = req.params.id;
// Verify client has permission to modify this account
const hasPermission = await canModifyAccount(
clientCert.CN,
accountId
);
if (!hasPermission) {
return res.status(403).json({ error: 'Forbidden' });
}
// Whitelist only allowed fields
const allowedFields = ['shippingAddress', 'billingAddress', 'preferences'];
const updateData = { id: accountId };
for (const field of allowedFields) {
if (req.body[field] !== undefined) {
updateData[field] = req.body[field];
}
}
await db.accounts.update(accountId, updateData);
res.json({ success: true });
});
// 2. Model-based protection with schema validation
const accountSchema = {
type: 'object',
properties: {
id: { type: 'string' },
balance: { type: 'number' },
status: { type: 'string' },
ownerId: { type: 'string' },
shippingAddress: { type: 'object' },
billingAddress: { type: 'object' }
},
required: ['id']
};
app.post('/api/accounts/:id', async (req, res) => {
const clientCert = req.clientCert.subject;
const accountId = req.params.id;
// Validate against schema first
const { error, value } = validate(req.body, accountSchema);
if (error) {
return res.status(400).json({ error: error.details });
}
// Check if client can modify specific fields
const canModify = await getModifiableFields(clientCert.CN, accountId);
// Filter value to only allowed fields
const updateData = { id: accountId };
for (const field of canModify) {
if (value[field] !== undefined) {
updateData[field] = value[field];
}
}
await db.accounts.update(accountId, updateData);
res.json({ success: true });
});Additional Mutual Tls-specific remediation strategies:
- Certificate-based field restrictions: Map certificate attributes to allowed modification scopes
- Role-based object binding: Associate Mutual Tls client certificates with specific data access patterns
- Audit field protection: Ensure audit trails cannot be modified through mass assignment
- Immutable field enforcement: Mark critical fields as read-only regardless of authentication
For comprehensive protection, combine these patterns with middleBrick's continuous monitoring to detect when new endpoints introduce unsafe object binding patterns in your Mutual Tls API ecosystem.
Related CWEs: propertyAuthorization
| CWE ID | Name | Severity |
|---|---|---|
| CWE-915 | Mass Assignment | HIGH |