traefik_block_regex_urls

package module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 17, 2025 License: MIT Imports: 6 Imported by: 0

README

Traefik Block Regex Urls

A Traefik plugin to block access to certain paths using a list of regex values and return a defined status code.

Configuration

Sample configuration in Traefik.

Configuration as local plugin

static.yml (development)

experimental:
  localPlugins:
    block-regex-urls:
      moduleName: 'github.com/blueshift-labs/traefik-block-regex-urls'

static.yml (production)

  plugins:
    block-regex-urls:
      moduleName: 'github.com/blueshift-labs/traefik-block-regex-urls'
      version: 'v0.0.1'

dynamic-configuration.yml

http:
  middlewares:
    block-scan-paths:
      plugin:
        block-regex-urls:
          exact_match:
            - "some_exact_string_with_regex_chars_?/._to_block"
          regex:
            - "^something.mydomain.tld\\/scan\\?uid=12345(.*)&gid=6789(.*)"
            - "^something.mydomain.tld\\/scan\\?uid=345$"
          statusCode: 404

docker-compose.yml

services:
  traefik:
    image: traefik
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /docker/config/traefik/traefik.yml:/etc/traefik/traefik.yml
      - /docker/config/traefik/dynamic-configuration.yml:/etc/traefik/dynamic-configuration.yml
      - /plugin/traefik-block-regex-urls:/plugins-local/src/github.com/blueshift-labs/traefik-block-regex-urls/
    ports:
      - "80:80"
  hello:
    image: traefik/whoami
    labels:
      - traefik.enable=true
      - traefik.http.routers.hello.entrypoints=http
      - traefik.http.routers.hello.rule=Host(`hello.localhost`)
      - traefik.http.services.hello.loadbalancer.server.port=80
      - traefik.http.routers.hello.middlewares=my-plugin@file

Sample configuration

  • regex: List of regex values to use for url blocking.
  • exact_match: List of exact matching strings to use for url blocking.
  • statusCode: Return value of the status code.
my-block-regex-urls:
  plugin:
    block-regex-urls:
      exact_match:
        - "some_string_to_block"
      regex:
        - "^something.mydomain.tld\\/scan\\?uid=12345(.*)&gid=6789(.*)"
        - "^something.mydomain.tld\\/scan\\?uid=345$"
      statusCode: 418

Documentation

Overview

Package "block regex urls" is a Traefik plugin to block access to certain urls using a list of regex values and return a defined status code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(ctx context.Context, next http.Handler, config *Config, name string) (http.Handler, error)

New creates a new plugin. Returns the configured BlockUrls plugin object.

Types

type Config

type Config struct {
	Regex         []string `mapstructure:"regex,omitempty"`
	ExactMatch    []string `mapstructure:"exact_match,omitempty"`
	SilentStartUp bool     `mapstructure:"silentStartUp"`
	StatusCode    int      `mapstructure:"statusCode"`
}

func CreateConfig

func CreateConfig() *Config

CreateConfig creates the default plugin configuration.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL