detached 043488f

Integrate Secure middleware for enhanced HTTP security headers.

commit
043488f4679cc02512a2f9ac92e25d875b932672
author
bnema · · 2023-09-05 01:52 UTC
parent
dd1a283
signature
unsigned
7 files · +47 -18
M cmd/main.go +0 -3
@@ -6,7 +6,6 @@ import (
66 "github.com/labstack/echo/v4"
77 "gogs.bnema.dev/gordon-echo/internal/app"
88 "gogs.bnema.dev/gordon-echo/internal/http/routes"
9- "gogs.bnema.dev/gordon-echo/pkg/docker"
109 "gogs.bnema.dev/gordon-echo/pkg/utils"
1110 )
1211
@@ -25,8 +24,6 @@ func main() {
2524 return
2625 }
2726
28- docker.CreateImageFromDockerfile()
29-
3027 e := echo.New()
3128 e.HideBanner = true
3229 e.HidePort = true
@@ -6,7 +6,6 @@ import (
6 "github.com/labstack/echo/v4"6 "github.com/labstack/echo/v4"
7 "gogs.bnema.dev/gordon-echo/internal/app"7 "gogs.bnema.dev/gordon-echo/internal/app"
8 "gogs.bnema.dev/gordon-echo/internal/http/routes"8 "gogs.bnema.dev/gordon-echo/internal/http/routes"
9- "gogs.bnema.dev/gordon-echo/pkg/docker"
10 "gogs.bnema.dev/gordon-echo/pkg/utils"9 "gogs.bnema.dev/gordon-echo/pkg/utils"
11 )10 )
12 11
@@ -25,8 +24,6 @@ func main() {
25 return24 return
26 }25 }
27 26
28- docker.CreateImageFromDockerfile()
29-
30 e := echo.New()27 e := echo.New()
31 e.HideBanner = true28 e.HideBanner = true
32 e.HidePort = true29 e.HidePort = true
M go.mod +9 -6
@@ -4,7 +4,9 @@ go 1.21.0
44
55 require (
66 github.com/PuerkitoBio/goquery v1.8.1
7+ github.com/docker/docker v24.0.5+incompatible
78 github.com/labstack/echo/v4 v4.11.1
9+ github.com/tidwall/gjson v1.16.0
810 gopkg.in/yaml.v3 v3.0.1
911 )
1012
@@ -13,33 +15,34 @@ require (
1315 github.com/andybalholm/cascadia v1.3.1 // indirect
1416 github.com/containerd/containerd v1.7.5 // indirect
1517 github.com/docker/distribution v2.8.2+incompatible // indirect
16- github.com/docker/docker v24.0.5+incompatible // indirect
1718 github.com/docker/go-connections v0.4.0 // indirect
1819 github.com/docker/go-units v0.5.0 // indirect
1920 github.com/gogo/protobuf v1.3.2 // indirect
2021 github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
21- github.com/klauspost/compress v1.16.7 // indirect
22- github.com/moby/patternmatcher v0.6.0 // indirect
23- github.com/moby/sys/sequential v0.5.0 // indirect
2422 github.com/gorilla/context v1.1.1 // indirect
2523 github.com/gorilla/securecookie v1.1.1 // indirect
2624 github.com/gorilla/sessions v1.2.1 // indirect
25+ github.com/klauspost/compress v1.16.7 // indirect
26+ github.com/moby/patternmatcher v0.6.0 // indirect
27+ github.com/moby/sys/sequential v0.5.0 // indirect
28+ github.com/moby/term v0.5.0 // indirect
29+ github.com/morikuni/aec v1.0.0 // indirect
2730 github.com/opencontainers/go-digest v1.0.0 // indirect
2831 github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b // indirect
2932 github.com/opencontainers/runc v1.1.9 // indirect
3033 github.com/pkg/errors v0.9.1 // indirect
3134 github.com/sirupsen/logrus v1.9.0 // indirect
32- github.com/tidwall/gjson v1.16.0 // indirect
3335 github.com/tidwall/match v1.1.1 // indirect
3436 github.com/tidwall/pretty v1.2.1 // indirect
3537 golang.org/x/mod v0.9.0 // indirect
3638 golang.org/x/time v0.3.0 // indirect
3739 golang.org/x/tools v0.7.0 // indirect
40+ gotest.tools/v3 v3.5.0 // indirect
3841 )
3942
4043 require (
4144 github.com/labstack/echo-contrib v0.15.0
42- github.com/labstack/gommon v0.4.0 // indirect
45+ github.com/labstack/gommon v0.4.0
4346 github.com/mattn/go-colorable v0.1.13 // indirect
4447 github.com/mattn/go-isatty v0.0.19 // indirect
4548 github.com/rs/zerolog v1.30.0
@@ -4,7 +4,9 @@ go 1.21.0
4 4
5 require (5 require (
6 github.com/PuerkitoBio/goquery v1.8.16 github.com/PuerkitoBio/goquery v1.8.1
7+ github.com/docker/docker v24.0.5+incompatible
7 github.com/labstack/echo/v4 v4.11.18 github.com/labstack/echo/v4 v4.11.1
9+ github.com/tidwall/gjson v1.16.0
8 gopkg.in/yaml.v3 v3.0.110 gopkg.in/yaml.v3 v3.0.1
9 )11 )
10 12
@@ -13,33 +15,34 @@ require (
13 github.com/andybalholm/cascadia v1.3.1 // indirect15 github.com/andybalholm/cascadia v1.3.1 // indirect
14 github.com/containerd/containerd v1.7.5 // indirect16 github.com/containerd/containerd v1.7.5 // indirect
15 github.com/docker/distribution v2.8.2+incompatible // indirect17 github.com/docker/distribution v2.8.2+incompatible // indirect
16- github.com/docker/docker v24.0.5+incompatible // indirect
17 github.com/docker/go-connections v0.4.0 // indirect18 github.com/docker/go-connections v0.4.0 // indirect
18 github.com/docker/go-units v0.5.0 // indirect19 github.com/docker/go-units v0.5.0 // indirect
19 github.com/gogo/protobuf v1.3.2 // indirect20 github.com/gogo/protobuf v1.3.2 // indirect
20 github.com/golang-jwt/jwt v3.2.2+incompatible // indirect21 github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
21- github.com/klauspost/compress v1.16.7 // indirect
22- github.com/moby/patternmatcher v0.6.0 // indirect
23- github.com/moby/sys/sequential v0.5.0 // indirect
24 github.com/gorilla/context v1.1.1 // indirect22 github.com/gorilla/context v1.1.1 // indirect
25 github.com/gorilla/securecookie v1.1.1 // indirect23 github.com/gorilla/securecookie v1.1.1 // indirect
26 github.com/gorilla/sessions v1.2.1 // indirect24 github.com/gorilla/sessions v1.2.1 // indirect
25+ github.com/klauspost/compress v1.16.7 // indirect
26+ github.com/moby/patternmatcher v0.6.0 // indirect
27+ github.com/moby/sys/sequential v0.5.0 // indirect
28+ github.com/moby/term v0.5.0 // indirect
29+ github.com/morikuni/aec v1.0.0 // indirect
27 github.com/opencontainers/go-digest v1.0.0 // indirect30 github.com/opencontainers/go-digest v1.0.0 // indirect
28 github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b // indirect31 github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b // indirect
29 github.com/opencontainers/runc v1.1.9 // indirect32 github.com/opencontainers/runc v1.1.9 // indirect
30 github.com/pkg/errors v0.9.1 // indirect33 github.com/pkg/errors v0.9.1 // indirect
31 github.com/sirupsen/logrus v1.9.0 // indirect34 github.com/sirupsen/logrus v1.9.0 // indirect
32- github.com/tidwall/gjson v1.16.0 // indirect
33 github.com/tidwall/match v1.1.1 // indirect35 github.com/tidwall/match v1.1.1 // indirect
34 github.com/tidwall/pretty v1.2.1 // indirect36 github.com/tidwall/pretty v1.2.1 // indirect
35 golang.org/x/mod v0.9.0 // indirect37 golang.org/x/mod v0.9.0 // indirect
36 golang.org/x/time v0.3.0 // indirect38 golang.org/x/time v0.3.0 // indirect
37 golang.org/x/tools v0.7.0 // indirect39 golang.org/x/tools v0.7.0 // indirect
40+ gotest.tools/v3 v3.5.0 // indirect
38 )41 )
39 42
40 require (43 require (
41 github.com/labstack/echo-contrib v0.15.044 github.com/labstack/echo-contrib v0.15.0
42- github.com/labstack/gommon v0.4.0 // indirect45+ github.com/labstack/gommon v0.4.0
43 github.com/mattn/go-colorable v0.1.13 // indirect46 github.com/mattn/go-colorable v0.1.13 // indirect
44 github.com/mattn/go-isatty v0.0.19 // indirect47 github.com/mattn/go-isatty v0.0.19 // indirect
45 github.com/rs/zerolog v1.30.048 github.com/rs/zerolog v1.30.0
M go.sum +17 -8 generated file: collapsed
A internal/http/middlewares/secure.go +18 -0
@@ -0,0 +1,18 @@
1+package middlewares
2+
3+import (
4+ "github.com/labstack/echo/v4"
5+ "github.com/labstack/echo/v4/middleware"
6+)
7+
8+func SecureMiddleware() echo.MiddlewareFunc {
9+ return middleware.SecureWithConfig(middleware.SecureConfig{
10+ XSSProtection: "1; mode=block",
11+ ContentTypeNosniff: "nosniff",
12+ XFrameOptions: "SAMEORIGIN",
13+ HSTSMaxAge: 3600,
14+ HSTSExcludeSubdomains: false,
15+ ContentSecurityPolicy: "default-src 'self'",
16+ // Skipper: YourCustomSkipperFunction, // If you have a custom skipper
17+ })
18+}
@@ -0,0 +1,18 @@
1+package middlewares
2+
3+import (
4+ "github.com/labstack/echo/v4"
5+ "github.com/labstack/echo/v4/middleware"
6+)
7+
8+func SecureMiddleware() echo.MiddlewareFunc {
9+ return middleware.SecureWithConfig(middleware.SecureConfig{
10+ XSSProtection: "1; mode=block",
11+ ContentTypeNosniff: "nosniff",
12+ XFrameOptions: "SAMEORIGIN",
13+ HSTSMaxAge: 3600,
14+ HSTSExcludeSubdomains: false,
15+ ContentSecurityPolicy: "default-src 'self'",
16+ // Skipper: YourCustomSkipperFunction, // If you have a custom skipper
17+ })
18+}
M internal/http/routes/router.go +1 -1
@@ -13,7 +13,7 @@ func ConfigureRouter(e *echo.Echo, app *app.App) *echo.Echo {
1313 // Register middlewares
1414 e.Use(middlewares.NewRequestLoggerMiddleware(app.HTTPLogger.Logger))
1515 e.Use(middlewares.LanguageDetectionMiddleware)
16-
16+ // e.Use(middlewares.SecureMiddleware()) // Uncomment this line to enable the secure middleware
1717 // Register routes
1818 e = bindStaticAdminUI(e)
1919
@@ -13,7 +13,7 @@ func ConfigureRouter(e *echo.Echo, app *app.App) *echo.Echo {
13 // Register middlewares13 // Register middlewares
14 e.Use(middlewares.NewRequestLoggerMiddleware(app.HTTPLogger.Logger))14 e.Use(middlewares.NewRequestLoggerMiddleware(app.HTTPLogger.Logger))
15 e.Use(middlewares.LanguageDetectionMiddleware)15 e.Use(middlewares.LanguageDetectionMiddleware)
16-16+ // e.Use(middlewares.SecureMiddleware()) // Uncomment this line to enable the secure middleware
17 // Register routes17 // Register routes
18 e = bindStaticAdminUI(e)18 e = bindStaticAdminUI(e)
19 19
A internal/ui/public/tmp/build-errors.log +1 -0
@@ -0,0 +1,1 @@
1+exit status 1⏎̸
@@ -0,0 +1,1 @@
1+exit status 1⏎̸
M logs/app.log +1 -0
@@ -48,3 +48,4 @@
4848 {"level":"warn","time":"2023-09-04T14:51:10+02:00","message":"Server will shutdown in 5 seconds press ENTER to cancel"}
4949 {"level":"info","time":"2023-09-04T14:51:15+02:00","message":"Server shutdown"}
5050 {"level":"info","time":"2023-09-04T17:18:16+02:00","message":"Server is listening on port 1323"}
51+{"level":"info","time":"2023-09-05T03:50:53+02:00","message":"Server is listening on port 1323"}
@@ -48,3 +48,4 @@
48 {"level":"warn","time":"2023-09-04T14:51:10+02:00","message":"Server will shutdown in 5 seconds press ENTER to cancel"}48 {"level":"warn","time":"2023-09-04T14:51:10+02:00","message":"Server will shutdown in 5 seconds press ENTER to cancel"}
49 {"level":"info","time":"2023-09-04T14:51:15+02:00","message":"Server shutdown"}49 {"level":"info","time":"2023-09-04T14:51:15+02:00","message":"Server shutdown"}
50 {"level":"info","time":"2023-09-04T17:18:16+02:00","message":"Server is listening on port 1323"}50 {"level":"info","time":"2023-09-04T17:18:16+02:00","message":"Server is listening on port 1323"}
51+{"level":"info","time":"2023-09-05T03:50:53+02:00","message":"Server is listening on port 1323"}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 7

Tags 106

↑↓ moveenter openesc close