/Check Body Request

Check Body Request

2
v1.1.2

Check Body Request

This check body request plugin for Traefik which checks the incoming request for specific body and their values to be present and matching the configuration. If the request does not validate against the configured body, the middleware will return a 400 Bad Request status code.

Limitations

  • JSON request are not working and it's will be make your traefik crash (We are fixing)

Configuration

Static

pilot:
token: xxxx
experimental:
plugins:
traefik-check-body:
modulename: github.com/soulbalz/traefik-check-body
version: v1.1.2

Dynamic configuration

http:
routers:
my-router:
rule: Path(`/whoami`)
service: service-whoami
entryPoints:
- http
middlewares:
- traefik-check-body
services:
service-whoami:
loadBalancer:
servers:
- url: http://127.0.0.1:5000
middlewares:
traefik-check-body:
plugin:
traefik-check-body:
response:
code: '1234'
message: 'test'
status: 401
raw: |
{
"error": "example error"
}
body:
- name: "BODY_1"
matchtype: one
values:
- "VALUE_1"
- "VALUE_99"
- name: "BODY_2"
matchtype: one
values:
- "VALUE_2"
- name: "BODY_3"
matchtype: one
values:
- "VALUE_3"
required: false
- name: "BODY_4"
matchtype: all
values:
- "LUE_4"
- "VALUE_5"
contains: true
required: true

Configuration documentation

Supported configurations per body

SettingAllowed valuesRequiredDescription
namestringYesName of the request body
matchtypeone, allYesMatch on all values or one of the values specified. The value 'all' is only allowed in combination with the 'contains' setting.
values[]stringYesA list of allowed values which are matched against the request header value
containsbooleanNoIf set to true (default false), the request is allowed if the request body value contains the value specified in the configuration
requiredbooleanNoIf set to false (default true), the request is allowed if the body is absent or the value is empty

response

SettingAllowed valuesRequiredDescription
codestringNoResponse error message code (default: 400)
messagestringNoResponse error message (default: "Invalid Request.")
statusintegerNoResponse error status code (default: 400)
rawstringNoCustom your response message whatever you want