Skip to content
This repository has been archived by the owner on Nov 2, 2023. It is now read-only.

agent/protection/http: lazy access to post form values #148

Merged
merged 2 commits into from
Sep 8, 2020

Conversation

Julio-Guerra
Copy link
Collaborator

Remove the current call to ParseForm() in the middlewares in favor of a direct
access to the cached value in the Request structure. This value is not nil
when the request handler has called ParseForm() itself. Meaning that the
In-WAF and RASP protections will now only consider the POST form values of the
request when actually parsed by the request handler.

Note that the In-App WAF is now dynamically attached to ParseForm() which
returns a non-nil error of type *SqreenError when blocked by the In-App WAF
(cf. https://docs.sqreen.com/go/integration for more details).

This fixes the usage of the Go agent in a reverse proxy server where the agent
was consuming the body because of the call to ParseForm(), making later reads
to Request.Body return EOF. A server can now correctly copy the request body.

Julio Guerra added 2 commits September 8, 2020 12:03
Remove the current call to `ParseForm()` in the middlewares in favor of a direct
access to the cached value in the `Request` structure. This value is not nil
when the request handler has called `ParseForm()` itself. Meaning that the
In-WAF and RASP protections will now only consider the POST form values of the
request when actually parsed by the request handler.

Note that the In-App WAF is now dynamically attached to `ParseForm()` which
returns a non-nil error of type `*SqreenError` when blocked by the In-App WAF
(cf. https://docs.sqreen.com/go/integration for more details).

This fixes the usage of the Go agent in a reverse proxy server where the agent
was consuming the body because of the call to `ParseForm()`, making later reads
to `Request.Body` return EOF. A server can now correctly copy the request body.
@Julio-Guerra Julio-Guerra added the bug Something isn't working label Sep 8, 2020
@Julio-Guerra Julio-Guerra added this to the v0.15.0 milestone Sep 8, 2020
@Julio-Guerra Julio-Guerra self-assigned this Sep 8, 2020
@Julio-Guerra
Copy link
Collaborator Author

System Tests will fail until the new rule gets merged and the reported agent version is bumped in this repo.
They should succeed again in the upcoming release branch.

@Julio-Guerra Julio-Guerra merged commit f762f8e into dev Sep 8, 2020
@Julio-Guerra Julio-Guerra deleted the fix/waf-lazy-post-params branch September 8, 2020 11:16
@Julio-Guerra Julio-Guerra mentioned this pull request Sep 9, 2020
Julio-Guerra pushed a commit that referenced this pull request Sep 10, 2020
New Feature:

- (#149) Add activity monitoring of RASP protections. The number of times a
  protection has been used in the application is now displayed on the `Activity`
  tab of each RASP protection dashboard page.

Fixes:

- (#148) Fix the usage of the Go agent in a reverse proxy server: avoid
  automatically reading a POST request's body because of the former usage of
  `Request.ParseForm()` in Sqreen's middleware functions, and rather get POST
  form values from `Request.PostForm`, and URL query values from
  `Request.URL.Query()`. Note that since `Request.PostForm`'s value is assigned
  by `Request.ParseForm()`, the In-WAF and RASP protections will now consider
  POST form values when the request handler will have called
  `Request.ParseForm()` itself for its own needs. Therefore, the In-App WAF is
  now also attached to `ParseForm()` to monitor the resulting POST form values,
  which can return a non-nil error when an attack is detected (cf.
  <https://docs.sqreen.com/go/integration> for more Go integration details).

- (ef81fc2) Enforce a request body reader to ignore it when blocked by the
  In-App WAF by returning it 0 bytes read along with the current non-nil error.
  This allows for example `io.LimitReader` not to copy the body buffer despite
  the non-nil error returned by the In-App WAF protection.
Julio-Guerra pushed a commit that referenced this pull request Sep 10, 2020
New Feature:

- (#149) Add activity monitoring of RASP protections. The number of times a
  protection has been used in the application is now displayed on the `Activity`
  tab of each RASP protection dashboard page.

Fixes:

- (#148) Fix the usage of the Go agent in a reverse proxy server: avoid
  automatically reading a POST request's body because of the former usage of
  `Request.ParseForm()` in Sqreen's middleware functions, and rather get POST
  form values from `Request.PostForm`, and URL query values from
  `Request.URL.Query()`. Note that since `Request.PostForm`'s value is assigned
  by `Request.ParseForm()`, the In-WAF and RASP protections will now consider
  POST form values when the request handler will have called
  `Request.ParseForm()` itself for its own needs. Therefore, the In-App WAF is
  now also attached to `ParseForm()` to monitor the resulting POST form values,
  which can return a non-nil error when an attack is detected (cf.
  <https://docs.sqreen.com/go/integration> for more Go integration details).

- (ef81fc2) Enforce a request body reader to ignore it when blocked by the
  In-App WAF by returning it 0 bytes read along with the current non-nil error.
  This allows for example `io.LimitReader` not to copy the body buffer despite
  the non-nil error returned by the In-App WAF protection.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant