-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Email option to embed images as base64 instead of link #32061
base: main
Are you sure you want to change the base?
Conversation
6bfebf7
to
17439b9
Compare
Please have a look at this and let me know if I did some structural things wrong, as I have zero experience with Go but came across the mentioned issues myself and tried to add the optional setting to fix them. |
cc35853
to
37428d3
Compare
37428d3
to
d76e949
Compare
Could you have some tests? |
I'll have a look. But I'm not quite sure as to what the focus of these test should be, as outgoing emails aren't tested anywhere. I could simply test my own additions whithout any actual email integration (the parsing of the html and replacement of the img tags and whether other image tags stay the same). Sounds fine? |
Yes. Thank you. |
d76e949
to
49c1522
Compare
49c1522
to
d072c3e
Compare
I added test to this. however I can't integrate them into services/mailer/mail_test.go because I need the testing environment which would form an import cycle. Now I exported the MailCommentContext and my newly added functions. Let me know if there is a way around this, but I see this as nothing big as these functions are not context specific. I'll squash the commits after you reviewed it |
763b655
to
6814a96
Compare
Still fails because I didn't account for using minio. Will rework... |
… image attachments + tests
cd3fea1
to
1665cba
Compare
https://github.blog/changelog/2023-05-09-more-secure-private-attachments/ |
I see your/their point. Even though it is not the exact same situation, the motivation for doing this is what our issue (that we are trying to resolve) is. For Github I see this as a more sensitive issue, as it is one instance that is publically hosted. With this change we are not allowing any urls to access attachments on gitea repos without authentification (no chance that this change will open any possibility of brute-forcing attachments), but instead we are "trusting" the email chain. (and for images only) |
Should I add an info to the documentation of the implication of email trust with this feature? |
Before reviewing some nits, actually there are some more important problems in my mind.
|
I think this PR is based on your comment here: #15081 (comment) And as #32061 (comment) explained, by default, this feature will be turn off, and only for these internal instances with special needs. So from my side, by default, this feature will not work, so it will not break the security of existing instances. We can just mention the risk in docs and |
I addressed both your points:
|
i will address the docu and Sounds good to me so far. |
;BASE64_EMBED_IMAGES = false | ||
;; | ||
;; The maximum size of an image attachment to be embedded in the email. | ||
;BASE64_EMBED_IMAGES_MAX_SIZE = 5242880 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we do not need to introduce a new option here. There are already too many config options.
A default value like 5M should be good enough for all users (update: it should limit the whole size, see below). If there would be some special requirements, it won't be late to introduce an option then.
And one more thing, limiting a single file seems not enough. There could be 100 files * 5M , I guess nobody would really like to receive an email with 500M size.
According to AI:
Gmail: The maximum size for sending and receiving emails is 25 MB.
Outlook: The maximum size for sending and receiving emails is 20 MB, but 10 MB for Exchange accounts. In Office 365, the maximum size is up to 150 MB.
GMX: The maximum size for sending and receiving emails is 50 MB.
ProtonMail: The maximum size for sending and receiving emails is 25 MB.
Yahoo: The maximum size for sending and receiving emails is 25 MB.
AOL: The maximum size for sending and receiving emails is 25 MB.
Hotmail: The maximum size for sending and receiving emails is 10 MB.
So limiting the whole size to 10MB or 25MB seems reasonable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you can just resize the bigger images to fixed width/height before base64 encode so they will take up much less space?
} | ||
defer fr.Close() | ||
|
||
content, err := io.ReadAll(fr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should avoid using ReadAll
when the size is not under control.
There are some limited readers for this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need the 1.4KB size to test?
- A valid JPEG can be as small as 107 bytes
- The smallest PNG file is 67 bytes
Since the image file is only used by this single test, I think a sample image file (and database fixture) could be generated on the fly?
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestEmailEmbedBase64Images(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand correctly, this test could be a "unit test" (in services/mailer/mail_xxx_test.go
), but not a "integration test"? Then no need to expose mailCommentContext
?
ref: #15081
ref: #14037
Documentation: https://gitea.com/gitea/docs/pulls/69
Example
Content:
Result in Email:
Result with source code:
(first image is external image, 2nd is now embedded)