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

Commit 73d60e7

Browse files
author
Julio Guerra
committed
v1.0.0
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).
2 parents c005080 + 31ce2bb commit 73d60e7

File tree

112 files changed

+9642
-4369
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+9642
-4369
lines changed

.github/workflows/agent-tests.yaml

+6-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ jobs:
99
matrix:
1010
runs-on: [ macos-latest, ubuntu-latest, windows-latest ]
1111
go-version: [ 1, 1.15, 1.14, 1.13, 1.12 ]
12+
go-test-options:
13+
- ""
14+
- "-tags sqassert -race"
1215
fail-fast: false
1316
runs-on: ${{ matrix.runs-on }}
1417
steps:
@@ -17,7 +20,7 @@ jobs:
1720
uses: actions/setup-go@v2
1821
with:
1922
go-version: ${{ matrix.go-version }}
20-
- run: go test ./...
23+
- run: go test ./... # note: do not support large number of goroutines for -race
2124

2225
# Same tests but on the official golang container for linux
2326
# Docker for Windows is not yet available on Github Actions.
@@ -35,7 +38,7 @@ jobs:
3538
# Install gcc and the libc headers on alpine images
3639
- if: ${{ matrix.distribution == 'alpine' }}
3740
run: apk add gcc musl-dev libc6-compat git
38-
- run: go test ./...
41+
- run: go test ${{ matrix.go-test-options }} ./...
3942

4043
# debian stretch doesn't have the latest go versions
4144
golang-debian-stretch-container:
@@ -48,4 +51,4 @@ jobs:
4851
image: golang:${{ matrix.go-version }}-stretch
4952
steps:
5053
- uses: actions/checkout@v2
51-
- run: go test ./...
54+
- run: go test ${{ matrix.go-test-options }} ./...

.github/workflows/codeql-analysis.yml

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
name: "CodeQL"
7+
8+
on:
9+
push:
10+
branches: [master, dev]
11+
pull_request:
12+
# The branches below must be a subset of the branches above
13+
branches: [feature/*, fix/*, hotfix/*, release/*]
14+
15+
jobs:
16+
analyze:
17+
name: Analyze
18+
runs-on: ubuntu-latest
19+
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
# Override automatic language detection by changing the below list
24+
# Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python']
25+
language: ['go']
26+
# Learn more...
27+
# https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection
28+
29+
steps:
30+
- name: Checkout repository
31+
uses: actions/checkout@v2
32+
with:
33+
# We must fetch at least the immediate parents so that if this is
34+
# a pull request then we can checkout the head.
35+
fetch-depth: 2
36+
37+
# If this run was triggered by a pull request event, then checkout
38+
# the head of the pull request instead of the merge commit.
39+
- run: git checkout HEAD^2
40+
if: ${{ github.event_name == 'pull_request' }}
41+
42+
# Initializes the CodeQL tools for scanning.
43+
- name: Initialize CodeQL
44+
uses: github/codeql-action/init@v1
45+
with:
46+
languages: ${{ matrix.language }}
47+
# If you wish to specify custom queries, you can do so here or in a config file.
48+
# By default, queries listed here will override any specified in a config file.
49+
# Prefix the list here with "+" to use these queries and those in the config file.
50+
# queries: ./path/to/local/query, your-org/your-repo/queries@main
51+
52+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
53+
# If this step fails, then you should remove it and run the build manually (see below)
54+
- name: Autobuild
55+
uses: github/codeql-action/autobuild@v1
56+
57+
# ℹ️ Command-line programs to run using the OS shell.
58+
# 📚 https://git.io/JvXDl
59+
60+
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
61+
# and modify them (or add more) to build your code if your project
62+
# uses a compiled language
63+
64+
#- run: |
65+
# make bootstrap
66+
# make release
67+
68+
- name: Perform CodeQL Analysis
69+
uses: github/codeql-action/analyze@v1

CHANGELOG.md

+319-185
Large diffs are not rendered by default.

Makefile

-145
This file was deleted.

README.md

+41-39
Original file line numberDiff line numberDiff line change
@@ -18,64 +18,66 @@ Sqreen provides automatic defense against attacks:
1818
- Protect with security modules: RASP (Runtime Application Self-Protection),
1919
in-app WAF (Web Application Firewall), Account takeovers and more.
2020

21-
- Sqreen’s modules adapt to your application stack with no need of configuration.
21+
- Sqreen’s modules adapt to your application stack with no need of
22+
configuration.
2223

23-
- Prevent attacks from the OWASP Top 10 (Injections, XSS and more), 0-days,
24-
data Leaks, and more.
25-
26-
- Create security automation playbooks that automatically react against
27-
your advanced business-logic threats.
24+
- Prevent attacks from the OWASP Top 10 (Injections, XSS and more), 0-days, data
25+
Leaks, and more.
26+
27+
- Create security automation playbooks that automatically react against your
28+
advanced business-logic threats.
2829

2930
For more details, visit [sqreen.com](https://www.sqreen.com/)
3031

3132
# Quick start
3233

3334
1. Use the middleware function for the Go web framework you use:
34-
- [net/http](https://godoc.org/github.com/sqreen/go-agent/sdk/middleware/sqhttp)
35-
- [Gin](https://godoc.org/github.com/sqreen/go-agent/sdk/middleware/sqgin)
36-
- [Echo](https://godoc.org/github.com/sqreen/go-agent/sdk/middleware/sqecho/v4)
35+
- [net/http](https://godoc.org/github.com/sqreen/go-agent/sdk/middleware/sqhttp)
36+
- [Gin](https://godoc.org/github.com/sqreen/go-agent/sdk/middleware/sqgin)
37+
- [Echo](https://godoc.org/github.com/sqreen/go-agent/sdk/middleware/sqecho/v4)
3738

3839
If your framework is not listed, it is usually possible to use instead the
39-
standard `net/http` middleware. If not, please, let us know by [creating an
40-
issue](http://github.com/sqreen/go-agent/issues/new).
40+
standard `net/http` middleware. If not, please, let us know
41+
by [creating an issue](http://github.com/sqreen/go-agent/issues/new).
4142

4243
1. Compile your program with Sqreen
4344

4445
Sqreen's dynamic configuration of your protection is made possible thanks to
45-
Go instrumentation. It is safely performed at compilation time by the following
46-
instrumentation tool.
46+
Go instrumentation. It is safely performed at compilation time by the
47+
following instrumentation tool.
4748

4849
Install the following instrumentation tool and compile your program using it
4950
in order to enable Sqreen.
5051

51-
1. Use `go build` to download and compile the instrumentation tool:
52-
53-
```console
54-
$ go build github.com/sqreen/go-agent/sdk/sqreen-instrumentation
55-
```
56-
57-
1. Configure the Go toolchain to use it:
58-
59-
Use the instrumentation tool using the go options
60-
`-a -toolexec /path/to/sqreen-instrumentation`.
61-
62-
It can be done either in your Go compilation command lines or by setting the
63-
`GOFLAGS` environment variable.
64-
65-
For example, the following two commands are equivalent:
66-
```console
67-
$ go build -a -toolexec $PWD/sqreen-instrumentation-tool my-project
68-
$ env GOFLAGS="-a -toolexec $PWD/sqreen-instrumentation-tool" go build my-project
69-
```
70-
71-
1. [Signup to Sqreen](https://my.sqreen.io/signup) to get a token for your app,
72-
and store it in the agent's configuration file `sqreen.yaml`:
73-
52+
1. Use `go install` to compile the instrumentation tool:
53+
```console
54+
$ go install github.com/sqreen/go-agent/sdk/sqreen-instrumentation-tool
55+
```
56+
57+
By default, the resulting `sqreen-instrumentation-tool` tool is installed
58+
in the
59+
`bin` directory of the `GOPATH`. You can find it using `go env GOPATH`.
60+
61+
1. Configure the Go toolchain to use it:
62+
63+
Use the instrumentation tool using the go options
64+
`-a -toolexec /path/to/sqreen-instrumentation-tool`.
65+
66+
It can be done either in your Go compilation command lines or by setting
67+
the `GOFLAGS` environment variable.
68+
69+
For example, the following two commands are equivalent:
70+
```console
71+
$ go build -a -toolexec $(go env GOPATH)/bin/sqreen-instrumentation-tool my-project
72+
$ env GOFLAGS="-a -toolexec $(go env GOPATH)/bin/sqreen-instrumentation-tool" go build my-project
73+
```
74+
75+
1. [Signup to Sqreen](https://my.sqreen.io/signup) to get your app credentials:
7476
```sh
7577
app_name: Your Go app name
7678
token: your token
7779
```
78-
80+
7981
This file can be stored in your current working directory when starting the
8082
executable, the same directory as your app's executable file, or in any other
8183
path by defining the configuration file location into the environment
@@ -87,9 +89,9 @@ Congratulations, your Go web application is now protected by Sqreen!
8789
<img width="60%" src="./doc/images/blocking-page-with-gopher.png" alt="Sqreen for Go" title="Sqreen for Go" />
8890
</p>
8991

90-
9192
# Advanced integration
9293

93-
Optionally, use the SDK to perform [user monitoring](https://docs.sqreen.com/go/user-monitoring/)
94+
Optionally, use the SDK to
95+
perform [user monitoring](https://docs.sqreen.com/go/user-monitoring/)
9496
or [custom security events](https://docs.sqreen.com/go/custom-events/) you would
9597
like to track and possibly block.

0 commit comments

Comments
 (0)