Skip to content

Commit 6666e8e

Browse files
Make CSP header configurable, and disable images in markdown (#964)
1 parent 96ee697 commit 6666e8e

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ There are two ways to authenticate a user in Stash-box: a session or an API key.
108108
| `postgres.conn_max_lifetime` | (0) | Maximum lifetime in minutes before a connection is released. |
109109
| `require_scene_draft` | false | Whether to allow scene creation outside of draft submissions. |
110110
| `require_tag_role` | false | Whether to require the EditTag role to edit tags. |
111+
| `csp` | (none) | Contents of the `Content-Security-Policy` header |
111112

112113
## SSL (HTTPS)
113114

frontend/src/utils/markdown.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const Markdown: FC<Props> = ({ text, unique }) =>
1919
remarkRehypeOptions={{
2020
clobberPrefix: unique ? `${unique}-` : undefined,
2121
}}
22+
disallowedElements={["img"]}
2223
components={{
2324
input: (props) => (
2425
<input

pkg/api/routes_root.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package api
22

33
import (
44
"embed"
5-
"fmt"
65
"html/template"
76
"io/fs"
87
"net/http"
@@ -49,9 +48,10 @@ func (rr rootRoutes) assets(w http.ResponseWriter, r *http.Request) {
4948
}
5049

5150
func (rr rootRoutes) app(w http.ResponseWriter, r *http.Request) {
52-
// Hash of an empty string, which is the contents of the Emotion CSS style element used by react-select
53-
emotionHash := "sha256-47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU="
54-
w.Header().Add("Content-Security-Policy", fmt.Sprintf("default-src 'self'; style-src 'self' '%s'", emotionHash))
51+
csp := config.GetCSP()
52+
if csp != "" {
53+
w.Header().Add("Content-Security-Policy", csp)
54+
}
5555
w.Header().Add("Strict-Transport-Security", "max-age=31536000; includeSubDomains")
5656
w.Header().Add("X-Frame-Options", "SAMEORIGIN")
5757
w.Header().Add("X-Content-Type-Options", "nosniff")

pkg/manager/config/config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ type config struct {
119119
Title string `mapstructure:"title"`
120120

121121
DraftTimeLimit int `mapstructure:"draft_time_limit"`
122+
123+
CSP string `mapstructure:"csp"`
122124
}
123125

124126
var JWTSignKey = "jwt_secret_key"
@@ -463,3 +465,7 @@ func GetMaxIdleConns() int {
463465
func GetConnMaxLifetime() int {
464466
return C.Postgres.MaxIdleConns
465467
}
468+
469+
func GetCSP() string {
470+
return C.CSP
471+
}

0 commit comments

Comments
 (0)