Skip to main content

Access Middleware

Access middleware provides route-level access control by blocking requests to specified paths. This security feature helps protect sensitive endpoints from unauthorized access.

Configuration

Access middleware uses a path-based blocking system where you define which routes should be restricted.

Basic Configuration

middlewares:
- name: api-blocked-paths
type: access
paths:
- /docs # Blocks /docs and all subpaths
- /admin # Blocks /admin and all subpaths
- /internal/api # Blocks specific internal endpoints
- "^/api/v[0-9]+/temp.*" # Regex: blocks versioned temp endpoints
rule: # Optional configuration
statusCode: 404 # Custom HTTP status code (default: 403)

Configuration Options

ParameterTypeRequiredDefaultDescription
namestringYes-Unique identifier for the middleware
typestringYes-Must be set to access
pathsarrayYes-List of paths to block
rule.statusCodeintegerNo403HTTP status code returned for blocked requests

Path Matching Behavior

  • Exact and prefix matching: /docs blocks both /docs and /docs/swagger
  • Root path: / blocks all requests to the application
  • Nested paths: /api/v1/internal blocks only that specific path and its subpaths
  • Regex patterns: Use regular expressions for advanced path matching with complex patterns

Applying Middleware to Routes

Attach the access middleware to routes by referencing its name in the route configuration:

routes:
- path: /api
name: api-route
rewrite: /
backends:
- endpoint: https://api.example.com
methods: [GET, POST, PUT, DELETE]
middlewares:
- api-blocked-paths # Reference to middleware defined above

Advanced Path Patterns with Regex

For complex path matching requirements, use regular expressions:

middlewares:
- name: advanced-blocking
type: access
paths:
# Block all temporary endpoints across API versions
- "^/api/v[0-9]+/temp.*"

# Block endpoints with sensitive parameters
- "^/users/[0-9]+/(delete|remove)$"

# Block debug endpoints with optional trailing slashes
- "^/debug(/.*)?/?$"

# Block file extensions that might expose sensitive data
- ".*\\.(log|bak|tmp)$"

# Block dynamic admin paths
- "^/admin-[a-zA-Z0-9]+/.*"
rule:
statusCode: 404

Regex Pattern Examples

PatternMatchesDescription
^/api/v[0-9]+/temp.*/api/v1/temp, /api/v2/temp/dataVersioned temporary endpoints
`^/users/[0-9]+/delete# Access Middleware

Access middleware provides route-level access control by blocking requests to specified paths. This security feature helps protect sensitive endpoints from unauthorized access.

Configuration

Access middleware uses a path-based blocking system where you define which routes should be restricted.

Basic Configuration

middlewares:
- name: api-blocked-paths
type: access
paths:
- /docs # Blocks /docs and all subpaths
- /admin # Blocks /admin and all subpaths
- /internal/api # Blocks specific internal endpoints
- "^/api/v[0-9]+/temp.*" # Regex: blocks versioned temp endpoints
rule: # Optional configuration
statusCode: 404 # Custom HTTP status code (default: 403)