-
Notifications
You must be signed in to change notification settings - Fork 176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add CSP and other security related headers in the oCIS proxy service #8777
Merged
+2,357
−36
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
51bdbc3
feat: add CSP and other security related headers in the oCIS proxy se…
DeepDiver1975 55d1ca7
fix: consolidate security related headers - drop middleware.Secure
DeepDiver1975 67ad717
fix: use github.com/DeepDiver1975/secure
DeepDiver1975 eeecd5d
fix: acceptance tests
DeepDiver1975 395e510
feat: support env var replacements in csp.yaml
DeepDiver1975 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Enhancement: Add CSP and other security related headers to oCIS | ||
|
||
General hardening of oCIS | ||
|
||
https://github.com/owncloud/ocis/pull/8777 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
directives: | ||
child-src: | ||
- '''self''' | ||
connect-src: | ||
- '''self''' | ||
default-src: | ||
- '''none''' | ||
font-src: | ||
- '''self''' | ||
frame-ancestors: | ||
- '''none''' | ||
frame-src: | ||
- '''self''' | ||
- 'https://embed.diagrams.net/' | ||
- 'https://onlyoffice.owncloud.test/' | ||
- 'https://collabora.owncloud.test/' | ||
img-src: | ||
- '''self''' | ||
- 'data:' | ||
- 'blob:' | ||
- 'https://onlyoffice.owncloud.test/' | ||
- 'https://collabora.owncloud.test/' | ||
manifest-src: | ||
- '''self''' | ||
media-src: | ||
- '''self''' | ||
object-src: | ||
- '''self''' | ||
- 'blob:' | ||
script-src: | ||
- '''self''' | ||
- '''unsafe-inline''' | ||
style-src: | ||
- '''self''' | ||
- '''unsafe-inline''' |
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
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
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
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
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package config | ||
|
||
import ( | ||
_ "embed" | ||
) | ||
|
||
// CSP defines CSP header directives | ||
type CSP struct { | ||
DeepDiver1975 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Directives map[string][]string `yaml:"directives"` | ||
} | ||
|
||
//go:embed csp.yaml | ||
var DefaultCSPConfig string |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
directives: | ||
child-src: | ||
- '''self''' | ||
connect-src: | ||
- '''self''' | ||
default-src: | ||
- '''none''' | ||
font-src: | ||
- '''self''' | ||
frame-ancestors: | ||
- '''none''' | ||
frame-src: | ||
- '''self''' | ||
- 'https://embed.diagrams.net/' | ||
img-src: | ||
- '''self''' | ||
- 'data:' | ||
- 'blob:' | ||
manifest-src: | ||
- '''self''' | ||
media-src: | ||
- '''self''' | ||
object-src: | ||
- '''self''' | ||
- 'blob:' | ||
script-src: | ||
- '''self''' | ||
- '''unsafe-inline''' | ||
style-src: | ||
- '''self''' | ||
- '''unsafe-inline''' |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package middleware | ||
|
||
import ( | ||
"github.com/owncloud/ocis/v2/services/proxy/pkg/config" | ||
"github.com/unrolled/secure" | ||
"github.com/unrolled/secure/cspbuilder" | ||
"gopkg.in/yaml.v2" | ||
"net/http" | ||
"os" | ||
) | ||
|
||
// LoadCSPConfig loads CSP header configuration from a yaml file. | ||
func LoadCSPConfig(proxyCfg *config.Config) (*config.CSP, error) { | ||
DeepDiver1975 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
yamlContent, err := loadCSPYaml(proxyCfg) | ||
if err != nil { | ||
return nil, err | ||
} | ||
cspConfig := config.CSP{} | ||
err = yaml.Unmarshal(yamlContent, &cspConfig) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &cspConfig, nil | ||
} | ||
|
||
func loadCSPYaml(proxyCfg *config.Config) ([]byte, error) { | ||
if proxyCfg.CSPConfigFileLocation == "" { | ||
return []byte(config.DefaultCSPConfig), nil | ||
} | ||
return os.ReadFile(proxyCfg.CSPConfigFileLocation) | ||
} | ||
|
||
// Security is a middleware to apply security relevant http headers like CSP. | ||
func Security(cspConfig *config.CSP) func(h http.Handler) http.Handler { | ||
cspBuilder := cspbuilder.Builder{ | ||
Directives: cspConfig.Directives, | ||
} | ||
|
||
secureMiddleware := secure.New(secure.Options{ | ||
BrowserXssFilter: true, | ||
ContentSecurityPolicy: cspBuilder.MustBuild(), | ||
ContentTypeNosniff: true, | ||
CustomFrameOptionsValue: "SAMEORIGIN", | ||
FrameDeny: true, | ||
ReferrerPolicy: "strict-origin-when-cross-origin", | ||
STSSeconds: 315360000, | ||
STSPreload: true, | ||
}) | ||
return func(next http.Handler) http.Handler { | ||
return secureMiddleware.Handler(next) | ||
} | ||
} |
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
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
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
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
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
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
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
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DeepDiver1975
Shouldn't
ONLYOFFICE_DOMAIN
andCOLLABORA_DOMAIN
be set here as well in order for the substitution inetc/ocis/csp.yaml
to take effect?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see https://github.com/owncloud/ocis/pull/8777/files#diff-bfedf12f7818c318b754f308bff1d6139afd701f2fc7bb43f07fd865a0d85039R15
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DeepDiver1975 Yes, I mean the
csp.yaml
is being loaded inside the containers environment, so if theONLYOFFICE_DOMAIN
andCOLLABORA_DOMAIN
are not set in thedocker-compose.yml
file they will be empty during runtime and the default values are used. (This is at least what happened when I tried it.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah. I see your point now.let me have a look .....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two variables need to be set in the
.env
file.https://github.com/owncloud/ocis/blob/master/deployments/examples/ocis_wopi/.env#L46
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes - but the env vars are not forwarded into the ocis container and will always be set to the default.
pr coming ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, right
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#9007 @micbar @kjeldahl
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
THX a lot @kjeldahl for bringing this to our attention! 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DeepDiver1975 You are most welcome. And thanks a lot for solving the CSP issue 4 hours before I ran into it 👍