Waf Plugin
Description
Wafis the core implementation of gateway to realize firewall function for network traffic.
Plugin Setting
Please refer to the deployment document, choose a way to start shenyu-admin. For example, through Local Deployment to start the Apache ShenYu management system.
-
In
shenyu-adminBasicConfig --> plugin ->wafset to enable.If you don't want to use this function, please disable this plugin in theshenyu-admin.
-
Add configuration mode in plugin editing.
{"model":"black"}
# model can be 'black' or 'mixed'
# The default mode is blacklist mode; If setting is mixed, it will be mixed mode. We will explain it specifically below.
Add Dependency
- Introducing
wafdependency in the pom.xml of the gateway.
<!-- apache shenyu waf plugin start-->
<dependency>
<groupId>org.apache.shenyu</groupId>
<artifactId>shenyu-spring-boot-starter-plugin-waf</artifactId>
<version>${project.version}</version>
</dependency>
<!-- apache shenyu waf plugin end-->
Waf Plugin Configuration
For more instructions on selector and rule configuration, please refer to: Selector And Rule Config, here only some fields are introduced.
Waf plugin rule configuration page:
For requests that are denied access by Waf , the response header status code is: 403.
Black Model
- When
modelis set toblackmode, only the matched traffic will execute the rejection policy, and the unmatched traffic will be skipped directly. - The
Handlerfeild in the rule configuration is invalid and can be configured to be empty.
Mixed Model
-
When
modelis set tomixedmode, all traffic will pass through waf plugin. For different matching traffic, users can set whether to reject or pass. -
The
Handlerfeild in the rule configuration must be configured:-
permission: The handle logic that matches the rule.reject: deny access,allow: allow access. -
statusCode: When access is denied, the value of the code field in the response body.Will not modify the status code of the response header.e.g.:
statusCode=10001,The rejected response body is :{"code":10001,"message":"You are forbidden to visit"}
-
Situation
Wafis also the pre-plugin ofShenYu, which is mainly used to intercept illegal requests or exception requests and give relevant rejection policies.- When faced with replay attacks, you can intercept illegal
ipandhost, and set reject strategy according to matchediporhost. - How to determine
ipandhost, please refer to: parsing-ip-and-host