filterjsonbody

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2026 License: MIT Imports: 8 Imported by: 0

README

traefik-plugin-filter-json-body

JSONのbodyの内容を元にフィルタリングを行うプラグイン

概要

リクエストのJSONボディの内容を検査し、指定した条件に一致する場合にリクエストを拒否する。

設定

パラメータ
  • rules: フィルタリングルールの配列
    • path: リクエストパス(完全一致)
    • method: HTTPメソッド(完全一致)
    • bodyPath: JSONボディ内の検査対象パス(XPath形式)
    • bodyValueCondition: 値の一致条件(正規表現)
動作
  • すべての条件に一致するリクエストは403 Forbiddenを返す
  • 条件に一致しないリクエストは次のハンドラに渡される
  • Content-Typeがapplication/jsonまたはapplication/*+json以外の場合は検査をスキップする
  • ボディサイズの上限は10MB

設定例

例1: 特定の文字列値を拒否
rules:
  - path: /api/test
    method: POST
    bodyPath: key
    bodyValueCondition: ^value$
例2: ネストされたオブジェクトの値を検査
rules:
  - path: /api/test
    method: POST
    bodyPath: //nestedObject/innerString
    bodyValueCondition: ^inner$
例3: 配列内のオブジェクトの値を検査
rules:
  - path: /api/test
    method: POST
    bodyPath: //arrayOfObjects/*/objString[text()='obj2']
    bodyValueCondition: ^obj2$

Documentation

Index

Constants

View Source
const MAX_BODY_SIZE = 10 * 1024 * 1024 // 10 MB

Variables

This section is empty.

Functions

func New

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

Types

type Config

type Config struct {
	Rules []Rule `json:"rules,omitempty"`
}

Config the plugin configuration.

func CreateConfig

func CreateConfig() *Config

CreateConfig creates the default plugin configuration.

type FilterJsonBody

type FilterJsonBody struct {
	// contains filtered or unexported fields
}

FilterJsonBody a FilterJsonBody plugin.

func (*FilterJsonBody) ServeHTTP

func (a *FilterJsonBody) ServeHTTP(rw http.ResponseWriter, req *http.Request)

type Rule

type Rule struct {
	Path               string `json:"path,omitempty"`               // only exact match
	Method             string `json:"method,omitempty"`             // only exact match
	BodyPath           string `json:"bodyPath,omitempty"`           // JSON XPath
	BodyValueCondition string `json:"bodyValueCondition,omitempty"` // regex match
}

Jump to

Keyboard shortcuts

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