This repository has been archived by the owner on Nov 2, 2023. It is now read-only.
sdk/middleware/sqhttp: transparent http response writer wrapper #170
Merged
Julio-Guerra
merged 3 commits into
dev
from
feature/transparent-http-response-writer-wrapper
Nov 17, 2020
Merged
sdk/middleware/sqhttp: transparent http response writer wrapper #170
Julio-Guerra
merged 3 commits into
dev
from
feature/transparent-http-response-writer-wrapper
Nov 17, 2020
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Make the HTTP response writer wrapper transparent by implementing the same *known* interfaces as the underlying HTTP response writer it implements. The list of interfaces is currently every optional `net/http` interfaces, and some from `io` when relevant: - `http.Flusher`: to allow flushing any buffered to the client. This enables support for streaming handlers. - `http.Hijacker`: to allow handlers to takeover the HTTP connection. This should enable the support for websocket servers, which are not officially supported by Sqreen, but is now experimentally allowed. - `http.Pusher`: for HTTP2 server push. - `http.CloseNotifier`: the deprecated closed connection notifier. - `io.ReaderFrom`: for optimized copies (eg. `io.Copy(file, w)`) - `io.WriteString`: for optimized string write (which avoids a temporary string copy into a byte slice) The transparent wrapper implementation has been generated from a tool that will be released in the Go agent repository in the future. Fixes #162 and #134
Remove the useless response writer wrapper as Echo and Gin already monitor them. Note that Gin actually doesn't allow changing the writter and all its helpers use the internal in-memory writer. Therefore, we are for now accepting multiple responses to keep the original response writer behaviour.
Julio-Guerra
deleted the
feature/transparent-http-response-writer-wrapper
branch
November 17, 2020 10:02
This was referenced Nov 17, 2020
Merged
Julio-Guerra
added a commit
that referenced
this pull request
Nov 19, 2020
New Features: - **(#172) New SDK convenience function:** Add a new helper function `sdk.FromRequest()` allowing to retrieve Sqreen's request context and perform SDK calls. It is equivalent to `sdk.FromContext(r.Context())`. - **(#156) Performance monitoring:** Monitor the execution time of requests protected by Sqreen. Optionally, it is possible to enforce the maximum amount of time Sqreen is allowed to run per request: Sqreen's monitoring and protections will only run for the given amount of time. This option is disabled by default and should be used with caution as it can lead to partially protected requests. The resulting performance monitoring diagrams and setting are available at <https://my.sqreen.com/application/goto/settings/performance>. Note that the execution time diagram cannot be used as a strict Application Performance Monitoring diagram as it is based on a lossy representation. It gives rough estimates of the actual execution time. - **(#170) Transparent response writer instrumentation:** Make the HTTP response writer instrumentation transparent by providing the same set of interfaces as the instrumented HTTP response writer. The set of interfaces is currently every optional `net/http` response writer interface, along with some relevant `io` interfaces, among which: - `http.Flusher`: for HTTP streaming support (multipart, chunked...). - `http.Pusher`: for HTTP2 server push support. - `http.Hijacker`: for websocket server support (experimental). - `io.ReaderFrom`: for optimized copies (eg. file copies) - `io.WriteString`: for optimized string copies. - **(#163) HTTP status code 404 (not found) monitoring:** Automatically log a security event when the response status code is 404. This event is used by an internal Sqreen backend playbook to detect security scans. - **(#163) Scalable security event throughput:** To be able to handle a higher throughput of security events, the agent can now scale its number of goroutines. An extra goroutine is created every time the internal event queue is full, up to the number of available CPUs. Note that the agent still drops security events when the event queue is full in order to avoid slowing down the host application. - **(#165) Agent errors in the request hot-path:** To avoid slowing down request handlers, agent errors happening in the request hot path are now logged based on an exponential backoff algorithm. This is disabled when the agent log level is `debug`. Breaking Change: - **(#168) SDK return values:** The SDK function and method return values are no longer pointer values but Go interface values. This may break integrations using explicit SDK return types, and we recommend to instead use type-inference when possible. This change will allow us to transparently change the actual return values without involving any further breaking change. As of today, the actual return value is a structure small enough to be returned by value in order to save memory-allocation and garbage-collection time. Returning an interface value allows to hide such implementation detail. Fixes: - **(#167) Playbook security response events:** Fix playbook security response events (blocking or redirecting a user or ip) so that Sqreen's dashboard can properly display them and link them to their source playbook. - **(#169) SQL-injection protection with Elastic APM:** Fix the detection of the SQL dialect when the SQL driver is instrumented by Elastic's APM tracer. This requires Elastic's Go agent version greater than `v1.9.0`. - **(#164) Echo middleware:** Fix the response status code monitoring when Echo's request handlers return an error. - **(#166) Gin middleware:** Fix the response content-length monitoring of default responses (ie. when the handler does nothing).
Julio-Guerra
added a commit
that referenced
this pull request
Nov 19, 2020
New Features: - **(#172) New SDK convenience function:** Add a new helper function `sdk.FromRequest()` allowing to retrieve Sqreen's request context and perform SDK calls. It is equivalent to `sdk.FromContext(r.Context())`. - **(#156) Performance monitoring:** Monitor the execution time of requests protected by Sqreen. Optionally, it is possible to enforce the maximum amount of time Sqreen is allowed to run per request: Sqreen's monitoring and protections will only run for the given amount of time. This option is disabled by default and should be used with caution as it can lead to partially protected requests. The resulting performance monitoring diagrams and setting are available at <https://my.sqreen.com/application/goto/settings/performance>. Note that the execution time diagram cannot be used as a strict Application Performance Monitoring diagram as it is based on a lossy representation. It gives rough estimates of the actual execution time. - **(#170) Transparent response writer instrumentation:** Make the HTTP response writer instrumentation transparent by providing the same set of interfaces as the instrumented HTTP response writer. The set of interfaces is currently every optional `net/http` response writer interface, along with some relevant `io` interfaces, among which: - `http.Flusher`: for HTTP streaming support (multipart, chunked...). - `http.Pusher`: for HTTP2 server push support. - `http.Hijacker`: for websocket server support (experimental). - `io.ReaderFrom`: for optimized copies (eg. file copies) - `io.WriteString`: for optimized string copies. - **(#163) HTTP status code 404 (not found) monitoring:** Automatically log a security event when the response status code is 404. This event is used by an internal Sqreen backend playbook to detect security scans. - **(#163) Scalable security event throughput:** To be able to handle a higher throughput of security events, the agent can now scale its number of goroutines. An extra goroutine is created every time the internal event queue is full, up to the number of available CPUs. Note that the agent still drops security events when the event queue is full in order to avoid slowing down the host application. - **(#165) Agent errors in the request hot-path:** To avoid slowing down request handlers, agent errors happening in the request hot path are now logged based on an exponential backoff algorithm. This is disabled when the agent log level is `debug`. Breaking Change: - **(#168) SDK return values:** The SDK function and method return values are no longer pointer values but Go interface values. This may break integrations using explicit SDK return types, and we recommend to instead use type-inference when possible. This change will allow us to transparently change the actual return values without involving any further breaking change. As of today, the actual return value is a structure small enough to be returned by value in order to save memory-allocation and garbage-collection time. Returning an interface value allows to hide such implementation detail. Fixes: - **(#167) Playbook security response events:** Fix playbook security response events (blocking or redirecting a user or ip) so that Sqreen's dashboard can properly display them and link them to their source playbook. - **(#169) SQL-injection protection with Elastic APM:** Fix the detection of the SQL dialect when the SQL driver is instrumented by Elastic's APM tracer. This requires Elastic's Go agent version greater than `v1.9.0`. - **(#164) Echo middleware:** Fix the response status code monitoring when Echo's request handlers return an error. - **(#166) Gin middleware:** Fix the response content-length monitoring of default responses (ie. when the handler does nothing).
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Make the HTTP response writer wrapper transparent by implementing the same
known interfaces as the underlying HTTP response writer. The
list of interfaces is currently every optional
net/http
interfaces, and somefrom
io
when relevant:http.Flusher
: to allow flushing any buffered to the client. This enablessupport for streaming handlers.
http.Hijacker
: to allow handlers to takeover the HTTP connection. Thisshould enable the support for websocket servers, which are not officially
supported by Sqreen, but is now experimentally allowed.
http.Pusher
: for HTTP2 server push.http.CloseNotifier
: the deprecated closed connection notifier.io.ReaderFrom
: for optimized copies (eg.io.Copy(file, w)
)io.WriteString
: for optimized string write (which avoids a temporary string copy into a byte slice)The transparent wrapper implementation has been generated from a tool that will
be released in the Go agent repository in the future.
Fixes #162 and #134