From f2cd1edc57f6a8ab20da4bb5a9b89516cc336185 Mon Sep 17 00:00:00 2001 From: binwiederhier Date: Thu, 7 Mar 2024 12:44:31 -0500 Subject: [PATCH] Add some helper for base-url --- cmd/serve.go | 16 +++++++++++----- docs/releases.md | 8 ++++++++ util/util_test.go | 2 +- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/cmd/serve.go b/cmd/serve.go index 90f21a0e..ba893872 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -16,6 +16,7 @@ import ( "math" "net" "net/netip" + "net/url" "os" "os/signal" "strings" @@ -126,7 +127,7 @@ func execServe(c *cli.Context) error { // Read all the options config := c.String("config") - baseURL := c.String("base-url") + baseURL := strings.TrimSuffix(c.String("base-url"), "/") listenHTTP := c.String("listen-http") listenHTTPS := c.String("listen-https") listenUnix := c.String("listen-unix") @@ -273,10 +274,15 @@ func execServe(c *cli.Context) error { return errors.New("if smtp-server-listen is set, smtp-server-domain must also be set") } else if attachmentCacheDir != "" && baseURL == "" { return errors.New("if attachment-cache-dir is set, base-url must also be set") - } else if baseURL != "" && !strings.HasPrefix(baseURL, "http://") && !strings.HasPrefix(baseURL, "https://") { - return errors.New("if set, base-url must start with http:// or https://") - } else if baseURL != "" && strings.HasSuffix(baseURL, "/") { - return errors.New("if set, base-url must not end with a slash (/)") + } else if baseURL != "" { + u, err := url.Parse(baseURL) + if err != nil { + return fmt.Errorf("if set, base-url must be a valid URL, e.g. https://ntfy.mydomain.com: %v", err) + } else if u.Scheme != "http" && u.Scheme != "https" { + return errors.New("if set, base-url must be a valid URL starting with http:// or https://, e.g. https://ntfy.mydomain.com") + } else if u.Path != "" { + return fmt.Errorf("if set, base-url must not have a path (%s), as hosting ntfy on a sub-path is not supported, e.g. https://ntfy.mydomain.com", u.Path) + } } else if upstreamBaseURL != "" && !strings.HasPrefix(upstreamBaseURL, "http://") && !strings.HasPrefix(upstreamBaseURL, "https://") { return errors.New("if set, upstream-base-url must start with http:// or https://") } else if upstreamBaseURL != "" && strings.HasSuffix(upstreamBaseURL, "/") { diff --git a/docs/releases.md b/docs/releases.md index 3549330b..654dbf28 100644 --- a/docs/releases.md +++ b/docs/releases.md @@ -1315,6 +1315,11 @@ and the [ntfy Android app](https://github.com/binwiederhier/ntfy-android/release ### ntfy server v2.9.0 +**Features:** + +* Support for larger message delays with `message-delay-limit` (see [message limits](config.md#message-limits), [#1050](https://github.com/binwiederhier/ntfy/pull/1050)/[#1019](https://github.com/binwiederhier/ntfy/issues/1019), thanks to [@MrChadMWood](https://github.com/MrChadMWood) for reporting) +* Support for larger message body sizes with `message-size-limit` (use at your own risk, see [message limits](config.md#message-limits), [#1050](https://github.com/binwiederhier/ntfy/pull/1050), thanks to [@zhzy0077](https://github.com/zhzy0077) for implementing this, and to [@nkjshlsqja7331](https://github.com/nkjshlsqja7331) for reporting) + **Bug fixes + maintenance:** * Remove `Rate-Topics` header due to DoS security issue if `visitor-subscriber-rate-limiting: true` ([#1048](https://github.com/binwiederhier/ntfy/issues/1048)) @@ -1326,6 +1331,9 @@ and the [ntfy Android app](https://github.com/binwiederhier/ntfy-android/release * Update Watchtower example ([#1014](https://github.com/binwiederhier/ntfy/pull/1014), thanks to [@lennart-m](https://github.com/lennart-m)) * Fix dead links ([#1022](https://github.com/binwiederhier/ntfy/pull/1022), thanks to [@DerRockWolf](https://github.com/DerRockWolf)) +!!! warning + **Breaking change**: The `Rate-Topics` header was removed due to a ([DoS issue](https://github.com/binwiederhier/ntfy/issues/1048). This only affects installations with `visitor-subscriber-rate-limiting: true`, which is not the default and likely very rarely used. + ### ntfy Android app v1.16.1 (UNRELEASED) **Features:** diff --git a/util/util_test.go b/util/util_test.go index d539d675..9ddec58d 100644 --- a/util/util_test.go +++ b/util/util_test.go @@ -128,7 +128,7 @@ func TestParseSize_10kLowerCaseSuccess(t *testing.T) { func TestParseSize_FailureInvalid(t *testing.T) { _, err := ParseSize("not a size") - require.Nil(t, err) + require.Error(t, err) } func TestFormatSize(t *testing.T) {