Skip to content
This repository has been archived by the owner on Jan 27, 2021. It is now read-only.

Commit

Permalink
Set CSP-Nonce #17
Browse files Browse the repository at this point in the history
As we overwrite kopano-index handler to serve index from vfs, we need to do this manually.
  • Loading branch information
IljaN committed Feb 19, 2020
1 parent 104a3fc commit 8ed83a7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ require (
github.com/spf13/viper v1.6.1
go.opencensus.io v0.22.2
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa
stash.kopano.io/kc/konnect v0.28.0
stash.kopano.io/kc/konnect v0.28.1
stash.kopano.io/kgol/rndm v1.1.0
)

replace stash.kopano.io/kc/konnect => github.com/IljaN/konnect v0.29.0-alpha2
5 changes: 4 additions & 1 deletion pkg/service/v0/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"stash.kopano.io/kc/konnect/bootstrap"
kcconfig "stash.kopano.io/kc/konnect/config"
"stash.kopano.io/kc/konnect/server"
"stash.kopano.io/kgol/rndm"
)

// Service defines the extension handlers.
Expand Down Expand Up @@ -212,9 +213,11 @@ func (k Konnectd) Index() http.HandlerFunc {

// TODO add environment variable to make the path prefix configurable
pp := "/signin/v1"

indexHTML := bytes.Replace(template, []byte("__PATH_PREFIX__"), []byte(pp), 1)

nonce := rndm.GenerateRandomString(32)
indexHTML = bytes.Replace(indexHTML, []byte("__CSP_NONCE__"), []byte(nonce), 1)

return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write(indexHTML)
Expand Down

0 comments on commit 8ed83a7

Please sign in to comment.