HIGH missing authenticationfiberjwt tokens

Missing Authentication in Fiber with Jwt Tokens

Missing Authentication in Fiber with Jwt Tokens

Missing Authentication in a Fiber application that uses JWT tokens typically occurs when routes intended to be protected are accessible without validating the presence or correctness of a token. This specific combination creates a vulnerability because developers may rely on middleware but fail to enforce checks on every handler, or they misconfigure token validation, allowing requests without valid credentials to proceed.

In practice, this can happen if the authentication middleware is applied selectively instead of to all sensitive endpoints, or if the middleware only checks token presence and does not validate signature, expiration, or claims. An attacker can send requests directly to these unprotected routes, bypassing the intended access controls. Since the scan tests unauthenticated attack surfaces, middleBrick will flag endpoints that do not require a valid JWT as a BOLA/IDOR or Authentication risk, depending on whether the missing check leads to unauthorized data access.

JWT tokens rely on signature verification to ensure integrity and origin. If verification is skipped or done incorrectly (for example, using an insecure algorithm like none or accepting unsigned tokens), an attacker can inject arbitrary tokens or omit them entirely. This is compounded in Fiber because handlers may assume the token has been verified by middleware, but if the middleware is not chained correctly, the handler executes without the required context. The scanner will detect missing Authentication checks by observing that protected endpoints return successful responses or data without a valid Authorization header, indicating that the unauthenticated attack surface is larger than intended.

Real-world attack patterns include enumeration of user data via IDOR when endpoints rely on token presence but skip ownership checks, or privilege escalation when administrative routes lack strict token validation. These behaviors align with OWASP API Top 10 categories such as Broken Object Level Authorization and Missing Authentication. middleBrick runs parallel checks that compare the runtime behavior of endpoints against the OpenAPI specification, and if the spec requires security schemes but the endpoint responds without authentication, a finding is generated with severity and remediation guidance.

Using the CLI, you can quickly verify whether your Fiber endpoints require valid JWT tokens by running a scan from the terminal. This helps identify gaps before deployment, especially when combined with the GitHub Action to fail builds if security scores drop below your chosen threshold. Remember, middleBrick detects and reports these issues; it does not automatically fix them, so developers must apply correct authentication patterns in code.

Jwt Tokens-Specific Remediation in Fiber

To remediate missing Authentication in Fiber when using JWT tokens, ensure that every protected route validates the token before processing the request. This involves configuring middleware that verifies the signature, checks expiration, and validates required claims, and ensuring the middleware is applied consistently across all sensitive handlers. Below are concrete code examples for a secure setup.

First, define a verification function that uses a strong signing method and rejects unsigned or malformed tokens:

import { verify } from 'jsonwebtoken';
import { FiberError } from '@gofiber/error';

const jwtSecret = process.env.JWT_SECRET;

export const verifyToken = (token: string): any => {
  if (!token) {
    throw new FiberError(401, { message: 'Authorization token required' });
  }
  try {
    const decoded = verify(token, jwtSecret, { algorithms: ['HS256'] });
    return decoded;
  } catch (err) {
    throw new FiberError(401, { message: 'Invalid or expired token' });
  }
};

Next, create middleware that extracts the token from the Authorization header and validates it before reaching the handler:

import { Middleware } from '..';
import { verifyToken } from './jwtUtils';

export const authMiddleware: Middleware = (c) => {
  const authHeader = c.req.header('Authorization');
  const token = authHeader && authHeader.startsWith('Bearer ') ? authHeader.slice(7) : null;
  const payload = verifyToken(token);
  c.set('user', payload);
  return c.next();
};

Apply this middleware to all routes that require authentication, ensuring no endpoint bypasses the check:

import { app } from '..';
import { authMiddleware } from './middleware/auth';

app.get('/api/profile', authMiddleware, (c) => {
  const user = c.get('user');
  return c.json({ profile: user });
});

app.post('/api/admin/settings', authMiddleware, (c) => {
  const user = c.get('user');
  if (user.role !== 'admin') {
    throw new FiberError(403, { message: 'Insufficient permissions' });
  }
  // admin logic
  return c.json({ message: 'Settings updated' });
});

For additional safety, validate token claims such as issuer and audience to prevent token misuse across services:

import { verify } from 'jsonwebtoken';

export const verifyTokenStrict = (token: string): any => {
  return verify(token, jwtSecret, {
    algorithms: ['HS256'],
    issuer: 'myapp-backend',
    audience: 'myapp-users',
  });
};

These patterns ensure that JWT validation is performed consistently and that missing Authentication is not exposed. The middleware approach integrates cleanly with Fiber’s context model and can be extended with role-based checks as needed.

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

How does middleBrick detect missing Authentication in Fiber endpoints using JWT?
middleBrick sends unauthenticated requests to endpoints and checks whether they return sensitive data or success responses without a valid JWT. If an endpoint requires authentication according to the OpenAPI spec but responds without token validation, it is flagged as a risk.
Can the GitHub Action enforce JWT Authentication requirements in CI/CD for Fiber APIs?
Yes, the GitHub Action can fail builds when the security score drops below your configured threshold or when findings related to missing Authentication are detected, helping to prevent deployments with weak access controls.