HIGH jwt misconfigurationfeathersjsbasic auth

Jwt Misconfiguration in Feathersjs with Basic Auth

Jwt Misconfiguration in Feathersjs with Basic Auth — how this specific combination creates or exposes the vulnerability

FeathersJS is a framework for real-time applications that can use multiple authentication strategies. When Basic Auth is used alongside JWT handling, misconfigurations can expose authentication bypass or token confusion risks. A JWT misconfiguration in this context often involves weak token validation, missing or permissive CORS settings, or an authentication chain that does not properly enforce scope and issuer checks. If an application exposes a JWT verification endpoint or relies on loosely configured secret/key material, an unauthenticated attacker may be able to influence token issuance or validation behavior.

In a FeathersJS service, if the JWT strategy is enabled but the application does not enforce strict origin checks and does not require proper authorization before issuing or accepting tokens, an attacker can exploit the unauthenticated attack surface. For example, an endpoint that returns a JWT when called without valid credentials can be leveraged to obtain a valid token. Combined with Basic Auth misconfigurations—such as accepting credentials in headers without enforcing HTTPS or without validating the Authorization header format—an attacker can capture or replay credentials and gain unauthorized access.

Another common pattern is when FeathersJS applications accept JWTs from query parameters or headers without verifying the audience (aud) and issuer (iss). This becomes critical when Basic Auth is used as a fallback or during migration phases. If the application does not reject tokens with missing or invalid claims, an attacker can supply a tampered token and potentially impersonate users. The interplay between permissive CORS rules, missing rate limiting, and weak token validation increases the likelihood of successful token replay or privilege escalation.

Real-world attack patterns include token leakage via logs or error messages, where JWTs are inadvertently exposed in server responses or stack traces. If FeathersJS is configured to trust all origins or does not validate the Host header, an attacker can craft requests that cause the server to issue tokens or reveal sensitive information embedded in JWT payloads. These issues align with the OWASP API Top 10 categories such as Broken Object Level Authorization (BOLA) and Security Misconfiguration, and can be mapped to findings in authentication and authorization checks.

middleBrick scans test these conditions by running checks such as Authentication, BOLA/IDOR, and Input Validation in parallel. It inspects OpenAPI specifications for $ref resolution and runtime behavior to identify whether JWT validation is consistently enforced and whether Basic Auth flows leak credentials or tokens. The scanner looks for missing HTTPS enforcement, weak token handling, and missing audience/issuer validation, providing prioritized findings with severity and remediation guidance.

Basic Auth-Specific Remediation in Feathersjs — concrete code fixes

To secure a FeathersJS application using Basic Auth, enforce strict validation of credentials, require HTTPS, and avoid exposing tokens in logs or error messages. Below are concrete code examples that demonstrate secure configuration.

First, ensure your FeathersJS application uses the authentication module with a custom Basic Auth hook that validates credentials against a secure store and rejects malformed Authorization headers.

const authentication = require('@feathersjs/authentication');
const jwt = require('@feathersjs/authentication-jwt');
const basic = require('@feathersjs/authentication-local').authentication;

app.configure(authentication({
  secret: process.env.AUTH_SECRET,
  entity: 'user',
  service: 'users',
  multi: true
}));

app.configure(jwt());
app.configure(basic());

// Custom Basic Auth hook to validate credentials securely
app.hooks({
  before: {
    all: [],
    find: [],
    get: [],
    create: [ authenticate('local') ],
    update: [],
    patch: [],
    remove: []
  },
  after: {
    all: [],
    find: [],
    get: [],
    create: [],
    update: [],
    patch: [],
    remove: []
  },
  error: {
    all: [],
    find: [],
    get: [],
    create: [],
    update: [],
    patch: [],
    remove: []
  }
});

Second, configure CORS to restrict origins and ensure that credentials are only accepted over HTTPS. Do not use wildcard origins when Basic Auth is enabled.

const cors = require('@koa/cors');

app.use(cors({
  origin: ['https://app.example.com', 'https://api.example.com'],
  methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'],
  allowedHeaders: ['Content-Type', 'Authorization'],
  credentials: true,
  maxAge: 86400
}));

Third, enforce strict validation of the Authorization header in your services to prevent token confusion. Reject requests that include malformed or missing credentials, and ensure JWT verification is applied consistently.

// Example validation hook for a FeathersJS service
const { iff, isProvider } = require('feathers-hooks-common');

function validateAuthorization(context) {
  if (isProvider('external')) {
    const authHeader = context.headers.authorization || '';
    if (!authHeader.startsWith('Basic ')) {
      throw new Error('Unauthorized: Invalid Authorization header');
    }
    // Perform secure credential verification here
  }
  return context;
}

app.service('api/data').hooks({
  before: {
    all: [ validateAuthorization ],
    find: [],
    get: [],
    create: [],
    update: [],
    patch: [],
    remove: []
  }
});

Finally, apply rate limiting and monitoring to reduce the risk of credential brute-forcing. Use middleware or service hooks to track failed attempts and enforce exponential backoff. middleBrick’s checks for Rate Limiting and Authentication help identify gaps in these controls.

Related CWEs: authentication

CWE IDNameSeverity
CWE-287Improper Authentication CRITICAL
CWE-306Missing Authentication for Critical Function CRITICAL
CWE-307Brute Force HIGH
CWE-308Single-Factor Authentication MEDIUM
CWE-309Use of Password System for Primary Authentication MEDIUM
CWE-347Improper Verification of Cryptographic Signature HIGH
CWE-384Session Fixation HIGH
CWE-521Weak Password Requirements MEDIUM
CWE-613Insufficient Session Expiration MEDIUM
CWE-640Weak Password Recovery HIGH

Frequently Asked Questions

What should I do if my FeathersJS Basic Auth flow exposes a JWT in error responses?
Ensure error messages do not include stack traces or tokens. Use generic error responses, validate and sanitize all outputs, and audit logging to prevent credential or token leakage.
How can I verify that JWT validation is properly enforced alongside Basic Auth in FeathersJS?
Review your authentication hooks and service hooks to confirm that JWT verification runs for external requests. Use an API security scanner to test unauthenticated endpoints for token issuance and validate audience and issuer claims in token validation logic.