@@ -21,7 +21,9 @@ import (
2121
2222	activities_model "code.gitea.io/gitea/models/activities" 
2323	issues_model "code.gitea.io/gitea/models/issues" 
24+ 	access_model "code.gitea.io/gitea/models/perm/access" 
2425	repo_model "code.gitea.io/gitea/models/repo" 
26+ 	"code.gitea.io/gitea/models/unit" 
2527	user_model "code.gitea.io/gitea/models/user" 
2628	"code.gitea.io/gitea/modules/base" 
2729	"code.gitea.io/gitea/modules/emoji" 
@@ -421,6 +423,7 @@ func Base64InlineImages(body string, ctx *MailCommentContext) (string, error) {
421423}
422424
423425func  AttachmentSrcToBase64DataURI (attachmentPath  string , ctx  * MailCommentContext ) (string , error ) {
426+ 	maxSizePerImageAttachment  :=  setting .MailService .Base64EmbedImagesMaxSizePerAttachment 
424427	if  ! strings .HasPrefix (attachmentPath , setting .AppURL ) { // external image 
425428		return  "" , fmt .Errorf ("external image" )
426429	}
@@ -435,6 +438,16 @@ func AttachmentSrcToBase64DataURI(attachmentPath string, ctx *MailCommentContext
435438		return  "" , err 
436439	}
437440
441+ 	// "Doer" is theoretically not the correct permission check (as Doer created the action on which to send), but as this is batch processed the receipants can't be accessed. 
442+ 	// Therefore we check the Doer, with which we counter leaking information as a Doer brute force attack on attachments would be possible. 
443+ 	perm , err  :=  access_model .GetUserRepoPermission (ctx , ctx .Issue .Repo , ctx .Doer )
444+ 	if  err  !=  nil  {
445+ 		return  "" , err 
446+ 	}
447+ 	if  ! perm .CanRead (unit .TypeIssues ) {
448+ 		return  "" , fmt .Errorf ("no permission" )
449+ 	}
450+ 
438451	fr , err  :=  storage .Attachments .Open (attachment .RelativePath ())
439452	if  err  !=  nil  {
440453		return  "" , err 
@@ -446,7 +459,16 @@ func AttachmentSrcToBase64DataURI(attachmentPath string, ctx *MailCommentContext
446459		return  "" , err 
447460	}
448461
462+ 	if  len (content ) >  int (maxSizePerImageAttachment ) {
463+ 		return  "" , fmt .Errorf ("image too large (%d bytes) of max %d bytes" , len (content ), maxSizePerImageAttachment )
464+ 	}
465+ 
449466	mimeType  :=  http .DetectContentType (content )
467+ 
468+ 	if  ! strings .HasPrefix (mimeType , "image/" ) {
469+ 		return  "" , fmt .Errorf ("not an image" )
470+ 	}
471+ 
450472	encoded  :=  base64 .StdEncoding .EncodeToString (content )
451473	dataURI  :=  fmt .Sprintf ("data:%s;base64,%s" , mimeType , encoded )
452474
0 commit comments