Skip to content

Commit afd88a2

Browse files
zeripathjolheiser
andauthored
Allow setting X-FRAME-OPTIONS (#16643)
* Allow setting X-FRAME-OPTIONS This PR provides a mechanism to set the X-FRAME-OPTIONS header. Fix #7951 Signed-off-by: Andrew Thornton <[email protected]> * Update docs/content/doc/advanced/config-cheat-sheet.en-us.md Co-authored-by: John Olheiser <[email protected]> Co-authored-by: John Olheiser <[email protected]>
1 parent 067d82b commit afd88a2

File tree

7 files changed

+12
-6
lines changed

7 files changed

+12
-6
lines changed

custom/conf/app.example.ini

+3
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,9 @@ PATH =
993993
;;
994994
;; allow request with credentials
995995
;ALLOW_CREDENTIALS = false
996+
;;
997+
;; set X-FRAME-OPTIONS header
998+
;X_FRAME_OPTIONS = SAMEORIGIN
996999

9971000
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9981001
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

docs/content/doc/advanced/config-cheat-sheet.en-us.md

+1
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ The following configuration set `Content-Type: application/vnd.android.package-a
162162
- `METHODS`: **GET,HEAD,POST,PUT,PATCH,DELETE,OPTIONS**: list of methods allowed to request
163163
- `MAX_AGE`: **10m**: max time to cache response
164164
- `ALLOW_CREDENTIALS`: **false**: allow request with credentials
165+
- `X_FRAME_OPTIONS`: **SAMEORIGIN**: Set the `X-Frame-Options` header value.
165166

166167
## UI (`ui`)
167168

modules/context/api.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ func APIContexter() func(http.Handler) http.Handler {
270270
}
271271
}
272272

273-
ctx.Resp.Header().Set(`X-Frame-Options`, `SAMEORIGIN`)
273+
ctx.Resp.Header().Set(`X-Frame-Options`, setting.CORSConfig.XFrameOptions)
274274

275275
ctx.Data["CsrfToken"] = html.EscapeString(ctx.csrf.GetToken())
276276

modules/context/context.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ func Contexter() func(next http.Handler) http.Handler {
729729
}
730730
}
731731

732-
ctx.Resp.Header().Set(`X-Frame-Options`, `SAMEORIGIN`)
732+
ctx.Resp.Header().Set(`X-Frame-Options`, setting.CORSConfig.XFrameOptions)
733733

734734
ctx.Data["CsrfToken"] = html.EscapeString(ctx.csrf.GetToken())
735735
ctx.Data["CsrfTokenHtml"] = template.HTML(`<input type="hidden" name="_csrf" value="` + ctx.Data["CsrfToken"].(string) + `">`)

modules/setting/cors.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ var (
2020
Methods []string
2121
MaxAge time.Duration
2222
AllowCredentials bool
23+
XFrameOptions string
2324
}{
24-
Enabled: false,
25-
MaxAge: 10 * time.Minute,
25+
Enabled: false,
26+
MaxAge: 10 * time.Minute,
27+
XFrameOptions: "SAMEORIGIN",
2628
}
2729
)
2830

routers/install/routes.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func installRecovery() func(next http.Handler) http.Handler {
6161
"SignedUserName": "",
6262
}
6363

64-
w.Header().Set(`X-Frame-Options`, `SAMEORIGIN`)
64+
w.Header().Set(`X-Frame-Options`, setting.CORSConfig.XFrameOptions)
6565

6666
if !setting.IsProd() {
6767
store["ErrorMsg"] = combinedErr

routers/web/base.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func Recovery() func(next http.Handler) http.Handler {
171171
store["SignedUserName"] = ""
172172
}
173173

174-
w.Header().Set(`X-Frame-Options`, `SAMEORIGIN`)
174+
w.Header().Set(`X-Frame-Options`, setting.CORSConfig.XFrameOptions)
175175

176176
if !setting.IsProd() {
177177
store["ErrorMsg"] = combinedErr

0 commit comments

Comments
 (0)