Skip to content
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

[server] Strip trailing slash from public-endpoint, disallow trailing slash #877

Merged
merged 4 commits into from
Jun 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ Changelog for Isso
- Add ``/config`` endpoint for fetching server configuration options that
affect the client
- Remove ``/count`` GET endpoint (use POST instead)
- Strip trailing slash from public-endpoint, allow trailing slashes for routes.
A trailing slash in ``[server] public-endpoint`` is now discouraged and
throws a warning (#876, ix5)

- Replace ``contenteditable`` ``div`` with ``textarea`` to fix issues when
editing messages that contain indented code
Expand Down
12 changes: 9 additions & 3 deletions docs/docs/reference/server-config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,18 @@ listen

public-endpoint
Public URL that Isso is accessed from by end users. Should always be
a http:// or https:// absolute address. If left blank, automatic
detection is attempted. Normally only needs to be specified if
different than the ``listen`` setting.
a ``http://`` or ``https://`` absolute address. If left blank, automatic
detection is attempted. Normally only needs to be specified if different
than the ``listen`` setting.

This URL must not end in a ``/`` slash, i.e. ``http://foo.bar:8080/`` is
forbidden but ``http://foo/bar:8080`` is fine.

Default: (empty)

.. versionchanged:: 0.13
Trailing slash now forbidden.

reload
Reload application, when the source code has changed. Useful for
development. Only works with the internal webserver.
Expand Down
14 changes: 14 additions & 0 deletions isso/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ def getiter(self, section, key):
if item:
yield item

def set(self, section, key, value):
super(IssoParser, self).set(section, key, value)

def section(self, section):
return Section(self, section)

Expand Down Expand Up @@ -171,4 +174,15 @@ def setify(cp):
parser.set("smtp", "from",
formataddr(("Ich schrei sonst!", fromaddr)))

# Warn on trailing slash which can result in malformed double-slashed URLs
if parser.get("server", "public-endpoint").endswith("/"):
public_endpoint = parser.get("server", "public-endpoint")
logger.warn("In your config file, '[server] public-endpoint' has a slash at the end, "
"please remove it: '%s' -> '%s'",
public_endpoint, public_endpoint.rstrip("/"))
# XXX Actually fail here in a future version
logger.warn("A future version of Isso might quit with an error if 'public-endpoint' is set incorrectly")
# Remove trailing slash
parser.set("server", "public-endpoint", public_endpoint.rstrip("/"))

return parser
7 changes: 0 additions & 7 deletions isso/tests/test_guard.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import tempfile
import unittest

from werkzeug import __version__
from werkzeug.test import Client
from werkzeug.wrappers import Response

Expand All @@ -14,12 +13,6 @@
from fixtures import curl, FakeIP
http.curl = curl

if __version__.startswith("0.8"):
class Response(Response):

def get_data(self, as_text=False):
return self.data.decode("utf-8")


class TestGuard(unittest.TestCase):

Expand Down