Commit d80b355
Eric Bower
·
2025-08-28 23:15:53 -0400 EDT
parent c9bd793
chore(feeds): limit message body size to 5mb This is in an effort to prevent abuse or having insanely massive RSS feed digests. The actual limit is subject to change.
2 files changed,
+16,
-3
+12,
-0
| ... | ... | @@ -21,6 +21,7 @@ import ( | |
| 21 | 21 | "github.com/mmcdole/gofeed" | |
| 22 | 22 | "github.com/picosh/pico/pkg/db" | |
| 23 | 23 | "github.com/picosh/pico/pkg/shared" | |
| 24 | + | "github.com/picosh/utils" | |
| 24 | 25 | ) | |
| 25 | 26 | ||
| 26 | 27 | var ErrNoRecentArticles = errors.New("no recent articles") |
| ... | ... | @@ -68,6 +69,7 @@ type DigestFeed struct { | |
| 68 | 69 | UnsubURL string | |
| 69 | 70 | DaysLeft string | |
| 70 | 71 | ShowBanner bool | |
| 72 | + | SizeWarning bool | |
| 71 | 73 | } | |
| 72 | 74 | ||
| 73 | 75 | type DigestOptions struct { |
| ... | ... | @@ -541,6 +543,16 @@ func (f *Fetcher) FetchAll(logger *slog.Logger, urls []string, inlineContent boo | |
| 541 | 543 | return nil, err | |
| 542 | 544 | } | |
| 543 | 545 | ||
| 546 | + | // cap body size to prevent abuse | |
| 547 | + | if len(html)+len(text) > 5*utils.MB { | |
| 548 | + | feeds.Options.InlineContent = false | |
| 549 | + | feeds.SizeWarning = true | |
| 550 | + | html, err = f.PrintHtml(feeds) | |
| 551 | + | if err != nil { | |
| 552 | + | return nil, err | |
| 553 | + | } | |
| 554 | + | } | |
| 555 | + | ||
| 544 | 556 | if allErrors != nil { | |
| 545 | 557 | text = fmt.Sprintf("> %s\n\n%s", allErrors, text) | |
| 546 | 558 | html = fmt.Sprintf("<blockquote>%s</blockquote><br /><br/>%s", allErrors, html) |
+4,
-3
| ... | ... | @@ -10,14 +10,15 @@ img { | |
| 10 | 10 | </style> | |
| 11 | 11 | ||
| 12 | 12 | {{if .SizeWarning}} | |
| 13 | - | <blockquote style="color: #ff0000; background-color: #ffe6e6; padding: 10px; border-left: 3px solid #ff0000;"> | |
| 14 | - | WARNING: This email is over the size limit. Inline content has been enabled to avoid email delivery issues. | |
| 13 | + | <blockquote> | |
| 14 | + | <strong>NOTICE:</strong> This email is over the size limit (5MB). Inline content has been enabled to avoid email delivery issues. | |
| 15 | + | We recommend splitting your RSS feeds into multiple digests. | |
| 15 | 16 | </blockquote> | |
| 16 | 17 | {{end}} | |
| 17 | 18 | ||
| 18 | 19 | {{if .ShowBanner}} | |
| 19 | 20 | <blockquote> | |
| 20 | - | In order to keep this digest email active you must <a href="{{.KeepAliveURL}}">click this link</a>. | |
| 21 | + | <strong>NOTICE:</strong> In order to keep this digest email active you must <a href="{{.KeepAliveURL}}">click this link</a>. | |
| 21 | 22 | You have {{.DaysLeft}} days left. | |
| 22 | 23 | </blockquote> | |
| 23 | 24 | {{end}} |