Skip to content

Commit 513b962

Browse files
zeripathsilverwindlafrikslunnyguillep2k
authored
Add max-file-size to LFS (#10463)
* Add max-file-size to LFS * Update modules/lfs/server.go * As per @silverwind Co-Authored-By: silverwind <[email protected]> Co-authored-by: silverwind <[email protected]> Co-authored-by: Lauris BH <[email protected]> Co-authored-by: Lunny Xiao <[email protected]> Co-authored-by: guillep2k <[email protected]>
1 parent 9ad2aa8 commit 513b962

File tree

4 files changed

+10
-0
lines changed

4 files changed

+10
-0
lines changed

custom/conf/app.ini.sample

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,8 @@ LFS_CONTENT_PATH = data/lfs
311311
LFS_JWT_SECRET =
312312
; LFS authentication validity period (in time.Duration), pushes taking longer than this may fail.
313313
LFS_HTTP_AUTH_EXPIRY = 20m
314+
; Maximum allowed LFS file size in bytes (Set to 0 for no limit).
315+
LFS_MAX_FILE_SIZE = 0
314316
; Allow graceful restarts using SIGHUP to fork
315317
ALLOW_GRACEFUL_RESTARTS = true
316318
; After a restart the parent will finish ongoing requests before

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
192192
- `LFS_CONTENT_PATH`: **./data/lfs**: Where to store LFS files.
193193
- `LFS_JWT_SECRET`: **\<empty\>**: LFS authentication secret, change this a unique string.
194194
- `LFS_HTTP_AUTH_EXPIRY`: **20m**: LFS authentication validity period in time.Duration, pushes taking longer than this may fail.
195+
- `LFS_MAX_FILE_SIZE`: **0**: Maximum allowed LFS file size in bytes (Set to 0 for no limit).
195196
- `REDIRECT_OTHER_PORT`: **false**: If true and `PROTOCOL` is https, allows redirecting http requests on `PORT_TO_REDIRECT` to the https port Gitea listens on.
196197
- `PORT_TO_REDIRECT`: **80**: Port for the http redirection service to listen on. Used when `REDIRECT_OTHER_PORT` is true.
197198
- `ENABLE_LETSENCRYPT`: **false**: If enabled you must set `DOMAIN` to valid internet facing domain (ensure DNS is set and port 80 is accessible by letsencrypt validation server).

modules/lfs/server.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,12 @@ func PostHandler(ctx *context.Context) {
233233
return
234234
}
235235

236+
if setting.LFS.MaxFileSize > 0 && rv.Size > setting.LFS.MaxFileSize {
237+
log.Info("Denied LFS upload of size %d to %s/%s because of LFS_MAX_FILE_SIZE=%d", rv.Size, rv.User, rv.Repo, setting.LFS.MaxFileSize)
238+
writeStatus(ctx, 413)
239+
return
240+
}
241+
236242
meta, err := models.NewLFSMetaObject(&models.LFSMetaObject{Oid: rv.Oid, Size: rv.Size, RepositoryID: repository.ID})
237243
if err != nil {
238244
writeStatus(ctx, 404)

modules/setting/setting.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ var (
140140
JWTSecretBase64 string `ini:"LFS_JWT_SECRET"`
141141
JWTSecretBytes []byte `ini:"-"`
142142
HTTPAuthExpiry time.Duration `ini:"LFS_HTTP_AUTH_EXPIRY"`
143+
MaxFileSize int64 `ini:"LFS_MAX_FILE_SIZE"`
143144
}
144145

145146
// Security settings

0 commit comments

Comments
 (0)