简体   繁体   English

如何防止Spring Boot Application中畸形请求的异常日志

[英]How to prevent exception logs of malformed requests in Spring Boot Application

Spring Boot 2.6.x Spring 启动 2.6.x

May 11 14:08:41 ubuntu java[1831]: 2022-05-11 14:08:41.239  INFO 1831 --- [nio-2023-exec-7] o.apache.coyote.http11.Http11Processor   : Error parsing HTTP request header
May 11 14:08:41 ubuntu java[1831]:  Note: further occurrences of HTTP request parsing errors will be logged at DEBUG level.
May 11 14:08:41 ubuntu java[1831]: java.lang.IllegalArgumentException: Invalid character found in method name [0xff0x0a0x00D0x000x080xc10xff...]. HTTP method names must be tokens
May 11 14:08:41 ubuntu java[1831]:         at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:419)
May 11 14:08:41 ubuntu java[1831]:         at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:271)
May 11 14:08:41 ubuntu java[1831]:         at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
May 11 14:08:41 ubuntu java[1831]:         at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:890)
May 11 14:08:41 ubuntu java[1831]:         at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1743)
May 11 14:08:41 ubuntu java[1831]:         at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
May 11 14:08:41 ubuntu java[1831]:         at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
May 11 14:08:41 ubuntu java[1831]:         at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
May 11 14:08:41 ubuntu java[1831]:         at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
May 11 14:08:41 ubuntu java[1831]:         at java.base/java.lang.Thread.run(Thread.java:833)
May 11 14:39:04 ubuntu java[1831]: 2022-05-11 14:39:04.939  INFO 1831 --- [nio-2023-exec-3] o.apache.coyote.http11.Http11Processor   : Error parsing HTTP request header
May 11 14:39:04 ubuntu java[1831]:  Note: further occurrences of HTTP request parsing errors will be logged at DEBUG level.
May 11 14:39:04 ubuntu java[1831]: java.lang.IllegalArgumentException: Invalid character found in the HTTP protocol [RTSP/1.00x0d0x0a0x0d0x0a...]
May 11 14:39:04 ubuntu java[1831]:         at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:570)
May 11 14:39:04 ubuntu java[1831]:         at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:271)
May 11 14:39:04 ubuntu java[1831]:         at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
May 11 14:39:04 ubuntu java[1831]:         at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:890)
May 11 14:39:04 ubuntu java[1831]:         at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1743)
May 11 14:39:04 ubuntu java[1831]:         at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
May 11 14:39:04 ubuntu java[1831]:         at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
May 11 14:39:04 ubuntu java[1831]:         at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
May 11 14:39:04 ubuntu java[1831]:         at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
May 11 14:39:04 ubuntu java[1831]:         at java.base/java.lang.Thread.run(Thread.java:833)

Note the abnormal parts:注意异常部位:

method name [0xff0x0a0x00D0x000x080xc10xff...] , method name [0xff0x0a0x00D0x000x080xc10xff...] ,

HTTP protocol [RTSP/1.00x0d0x0a0x0d0x0a...]

These must be randomly incoming attacking requests.这些必须是随机传入的攻击请求。

Is there any way to prevent these exception logs?有什么办法可以防止这些异常日志吗?

Is this a service that restarts quite often?这是一项经常重新启动的服务吗? Like, you get a request that starts-up Tomcat, then shuts-down, only to restart for another request after that?比如,你收到一个启动 Tomcat 的请求,然后关闭,之后才重新启动另一个请求?

Tomcat will only log the message you see above once per run at the INFO level, and those after that will be logged at the DEBUG level (just like the message says): Tomcat 只会在INFO级别每次运行时记录您在上面看到的消息,之后的消息将在DEBUG级别记录(就像消息说的那样):

Note: further occurrences of HTTP request parsing errors will be logged at DEBUG level.

So it won't log every error... just the first error for each time the HttpProcessor is re-initialized.所以它不会记录每一个错误……只是每次重新初始化 HttpProcessor 时的第一个错误。

If these log messages become a nuisance, you have a few options:如果这些日志消息变得令人讨厌,您有几个选择:

  1. Investigate why you are getting broken requests like this and try to minimize them (fix a broken client? use a firewall?)调查为什么你会收到这样的损坏请求并尽量减少它们(修复损坏的客户端?使用防火墙?)
  2. Keep Tomcat running for longer;让Tomcat运行更长时间; you will get fewer errors on your log您将在日志中收到更少的错误
  3. Set the log level for the org.apache.coyote.http11.Http11Processor logger to ERROR将 org.apache.coyote.http11.Http11Processor 记录器的日志级别设置为ERROR

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM