Skip to content

Commit f9d6790

Browse files
committed
address review and add option
1 parent e62e675 commit f9d6790

File tree

5 files changed

+16
-6
lines changed

5 files changed

+16
-6
lines changed

custom/conf/app.example.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,8 @@ INTERNAL_TOKEN=
428428
;CAMO_SERVER_URL =
429429
;; HMAC to encode urls with
430430
;CAMO_HMAC_KEY =
431+
;; Set to true to use camo for https too lese only non https urls are proxyed
432+
;CAMO_ALLWAYS = false
431433

432434
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
433435
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,7 @@ Certain queues have defaults that override the defaults set in `[queue]` (this o
516516
- `SUCCESSFUL_TOKENS_CACHE_SIZE`: **20**: Cache successful token hashes. API tokens are stored in the DB as pbkdf2 hashes however, this means that there is a potentially significant hashing load when there are multiple API operations. This cache will store the successfully hashed tokens in a LRU cache as a balance between performance and security.
517517
- `CAMO_SERVER_URL`: **<empty>**: If you would like to use a camo proxy to proxy images from rendered content, set the camo server url here
518518
- `CAMO_HMAC_KEY`: **<empty>**: Provide the HMAC key for encoding urls
519+
- `CAMO_ALLWAYS`: **false**: Set to true to use camo for https too lese only non https urls are proxyed
519520

520521
## OpenID (`openid`)
521522

modules/markup/camo.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2020 The Gitea Authors. All rights reserved.
1+
// Copyright 2022 The Gitea Authors. All rights reserved.
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

@@ -16,7 +16,7 @@ import (
1616

1717
// CamoEncode encodes a lnk to fit with the go-camo and camo proxy links
1818
func CamoEncode(link string) string {
19-
if strings.HasPrefix(link, setting.CamoServerURL) || len(setting.CamoHMACKey) == 0 {
19+
if strings.HasPrefix(link, setting.CamoServerURL) {
2020
return link
2121
}
2222

modules/markup/html.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -387,9 +387,9 @@ func visitNode(ctx *RenderContext, procs, textProcs []processor, node *html.Node
387387
attr.Val = util.URLJoin(prefix, attr.Val)
388388
}
389389
if setting.CamoServerURL != "" {
390-
lnkURL, _ := url.Parse(attr.Val)
391-
if lnkURL.IsAbs() && !strings.HasPrefix(attr.Val, setting.AppURL) {
392-
// We should camo this url
390+
lnkURL, err := url.Parse(attr.Val)
391+
if err != nil && lnkURL.IsAbs() && !strings.HasPrefix(attr.Val, setting.AppURL) &&
392+
(setting.CamoAllways || lnkURL.Scheme != "https") {
393393
attr.Val = CamoEncode(attr.Val)
394394
}
395395
}

modules/setting/setting.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ var (
198198
SuccessfulTokensCacheSize int
199199
CamoServerURL string
200200
CamoHMACKey string
201+
CamoAllways bool
201202

202203
// UI settings
203204
UI = struct {
@@ -914,9 +915,15 @@ func loadFromConf(allowEmpty bool, extraConfig string) {
914915
PasswordHashAlgo = sec.Key("PASSWORD_HASH_ALGO").MustString("pbkdf2")
915916
CSRFCookieHTTPOnly = sec.Key("CSRF_COOKIE_HTTP_ONLY").MustBool(true)
916917
PasswordCheckPwn = sec.Key("PASSWORD_CHECK_PWN").MustBool(false)
918+
SuccessfulTokensCacheSize = sec.Key("SUCCESSFUL_TOKENS_CACHE_SIZE").MustInt(20)
919+
917920
CamoServerURL = sec.Key("CAMO_SERVER_URL").MustString("")
918921
CamoHMACKey = sec.Key("CAMO_HMAC_KEY").MustString("")
919-
SuccessfulTokensCacheSize = sec.Key("SUCCESSFUL_TOKENS_CACHE_SIZE").MustInt(20)
922+
CamoAllways = sec.Key("CAMO_ALLWAYS").MustBool(false)
923+
if CamoServerURL != "" && CamoHMACKey == "" {
924+
log.Error("CAMO_SERVER_URL is set but CAMO_HMAC_KEY is empty, skip media proxy settings")
925+
CamoServerURL = ""
926+
}
920927

921928
InternalToken = loadInternalToken(sec)
922929
if InstallLock && InternalToken == "" {

0 commit comments

Comments
 (0)