Commit Graph

52024 Commits

Author SHA1 Message Date
Sahil Batra
ee6ab3d15b streams: Send stream deletion events on unsubscribing users.
This commit adds code to send stream deletion events when
unsubscribing non-admin users from private streams and
when unsubscribing guests from public streams since
non-admins cannot access unsubscribed private streams
and guests cannot access unsubscribed public streams.
2023-11-16 16:38:47 +00:00
Sahil Batra
6336322d2f CVE-2023-47642: Invalid metadata access for formerly subscribed streams.
It was discovered by the Zulip development team that active users who
had previously been subscribed to a stream incorrectly continued being
able to use the Zulip API to access metadata for that stream. As a
result, users who had been removed from a stream, but still had an
account in the organization, could still view metadata for that
stream (including the stream name, description, settings, and an email
address used to send emails into the stream via the incoming email
integration). This potentially allowed users to see changes to a
stream’s metadata after they had lost access to the stream.

This bug was present in all Zulip releases prior to today's Zulip
Server 7.5.
2023-11-16 16:38:30 +00:00
Sahil Batra
6e119842bd streams: Add API endpoint to get stream email.
This commit adds new API endpoint to get stream email which is
used by the web-app as well to get the email when a user tries
to open the stream email modal.

The stream email is returned only to the users who have access
to it. Specifically for private streams only subscribed users
have access to its email. And for public streams, all non-guest
users and only subscribed guests have access to its email.
All users can access email of web-public streams.
2023-11-16 16:28:14 +00:00
Sahil Batra
0a3800332f streams: Remove "email_address" field from Subscription objects.
This commit removes "email_address" field from Subscription objects
and we would instead a new endpoint in next commit to get email
address for stream with proper access check.

This change also fixes the bug where we would include email address
for the unsubscribed private stream as well when user did not have
permission to send message to the stream, and having email allowed
the unsubscribed user to send message to the stream.

Note that the unsubscribed user can still send message to the stream
if the user had noted down the email before being unsubscribed
and the stream token is not changed after unsubscribing the user.
2023-11-16 11:11:26 -05:00
Sahil Batra
9636362cbd events: Fix applying stream creation events in apply_event.
There was a bug in apply_event code where only a stream which
is not private is added to the "never_subscribed" data after
a stream creation event. Instead, it should be added to the
"never_subscribed" data irrespective of permission policy of
the stream as we already send stream creation events only to
those users who can access the stream. Due to the current
bug, private streams were not being added to "never_subscribed"
data in apply_event for admins as well. This commit fixes it
and also makes sure the "never_subscribed" list is sorted
which was not done before and was also a bug.

The bugs mentioned above were unnoticed as the tests did not
cover these cases and this commit also adds tests for those
cases.
2023-11-16 11:11:26 -05:00
Sahil Batra
c90fd388c8 register: Include web-public streams in "streams" field of response.
The "streams" field in "/register" response did not include web-public
streams for non-admin users but the data for those are eventually
included in the subscriptions data sent using "subscriptions",
"unsubscribed" and "never_subscribed" fields.

This commit adds code to include the web-public streams in "streams"
field as well as everyone can access those and will make the "streams"
data complete.
2023-11-16 11:11:26 -05:00
Alex Vandiver
edf1de5416 i18n: Update translation data from Transifex. 2023-11-15 22:11:06 +00:00
Karl Stolley
a4c2f27bd5 tests: Disable flaky test_edit_bot_form test. 2023-11-15 10:50:00 -08:00
Anders Kaseorg
019d922917 requirements: Upgrade Python requirements.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit 7807bff526)
2023-11-15 10:13:24 -08:00
Anders Kaseorg
64cb7b5bed rate_limiter: Fix PIE790 Unnecessary pass statement.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit f338c3af07)
2023-11-15 10:13:24 -08:00
Anders Kaseorg
41a6511924 typos: Fix typos caught by typos.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit 4cb2eded68)
2023-11-15 10:13:24 -08:00
Anders Kaseorg
3a2a217fa0 codespell: Fix typos caught by codespell.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit 7b4a74cc4d)
2023-11-15 10:13:24 -08:00
Anders Kaseorg
8e1ebede1b ruff: Fix C416 Unnecessary list comprehension.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit dd7b09d71a)
2023-11-15 10:13:24 -08:00
Alex Vandiver
a7b8e4795d backup: Only pass --host and --port if non-empty.
This works around the `/usr/bin/pg_dump` failure described in the
previous commit.  Since we are now calling the appropriately-versioned
`pg_dump` binary directly, it is no longer "necessary", but is added
as a defense-in-depth.
2023-11-14 12:11:40 -08:00
Alex Vandiver
9167b3efd7 backup: Call the pg_dump binary whose version we are running.
`/usr/bin/pg_dump` on Ubuntu and Debian is actually a tool which
attempts to choose which `pg_dump` binary from all of the
`postgresql-client-*` packages that are installed to run.  However,
its logic is confused by passing empty `--host` and `--port` options
-- instead of looking at the running server instance on the server, it
instead assumes some remote host and chooses the highest versioned
`pg_dump` which is installed.

Because Zulip writes binary database backups, they are sensitive to
the version of the client `pg_dump` binary is used -- and the output
may not be backwards compatible.  Using a PostgreSQL 16 `pg_dump`
writes archive format 1.15, which cannot be read by a PostgreSQL 15
`pg_restore`.

Zulip does not currently support PostgreSQL 16 as a server.  This
means that backups on servers with `postgresql-client-16` installed
did not successfully round-trip Zulip backups -- their backups are
written using PostgreSQL 16's client, and the `pg_restore` chosen on
restore was correctly chosen as the one whose version matched the
server (PostgreSQL 15 or below), and thus did not understand the new
archive format.

Existing `./manage.py backups` taken since `postgresql-client-16` were
installed are thus not directly usable by the `restore-backup` script.
They are not useless, however, since they can theoretically be
converted into a format readable by PostgreSQL 15 -- by importing into
a PostgreSQL 16 instance, and re-dumping with a PostgreSQL 15
`pg_dump`.

Fix this issue by hard-coding path to the binary whose version matches
the version of the server we are connected to.  This may theoretically
fail if we are connected to a remote PostgreSQL instance and we do not
have a `postgresql-client` package locally installed which matches the
remote PostgreSQL server's version.  However, choosing a matching
version is the only way to ensure that it will be able to be imported
cleanly -- and it is preferable that we fail the backup process rather
than write backups that we cannot easily restore from.

Fixes: #27160.
2023-11-14 12:11:40 -08:00
Alex Vandiver
e84c289c0d backup: Use simpler api for server version. 2023-11-14 12:11:40 -08:00
David Rosa
5a9452f3e6 help: Document unarchive_stream management command.
- Adds "Unarchiving archived streams" section to "Archive a stream".
- Adds `./manage.py unarchive_stream` to contributor docs.
2023-10-02 12:52:25 -07:00
David Rosa
d68b27e39a help: Update "Archive a stream".
- Updates page to follow current help center documentation patterns.
2023-10-02 12:52:25 -07:00
David Rosa
60334f7ccf management: Rename command reactivate_stream -> unarchive_stream. 2023-10-02 12:52:25 -07:00
Alex Vandiver
acaf5b835c realm: Differentiate reserved realms from in-use realms.
Fixes: #23896.
2023-10-02 12:52:25 -07:00
Mateusz Mandera
6ef745675c ldap: Improve doc on AUTH_LDAP_ADVANCED_REALM_ACCESS_CONTROL.
This fixes the explanation of the setting's syntax to be more precise
(which doesn't mean "easily understandable" - because the setting is
a bit tricky) as well as an example to illustrate it.
2023-10-02 12:52:25 -07:00
Alex Vandiver
be179b2b6b delete_old_unclaimed_attachments: Update docs on default max age.
42f1cb3444 updated the default up, from 1 week to 5 weeks, but did
not adjust the documentation.
2023-10-02 12:52:25 -07:00
Tim Abbott
79945622bc i18n: Fix default language for users created via API/LDAP.
This fixes a regression introduced in
9954db4b59, where the realm's default
language would be ignored for users created via API/LDAP/SAML,
resulting in all such users having English as their default language.

The API/LDAP/SAML account creation code paths don't have a request,
and thus cannot pull default language from the user's browser.

We have the `realm.default_language` field intended for this use case,
but it was not being passed through the system.

Rather than pass `realm.default_language` through from each caller, we
make the low-level user creation code set this field, as that seems
more robust to the creation of future callers.
2023-10-02 12:52:25 -07:00
Mateusz Mandera
092ecbacc6 i18n: Tweak args/kwargs for get_default_language_for_new_user.
Making request a mandatory kwarg avoids confusion about the meaning of
parameters, especially with `request` acquiring the ability to be None
in the upcoming next commit.
2023-10-02 12:52:25 -07:00
Tim Abbott
a802f0f339 version: Update version after 7.4 release. 2023-09-15 18:02:00 -07:00
Tim Abbott
d5b8d4b17d Release Zulip Server 7.4. 7.4 2023-09-15 17:27:53 -07:00
Tim Abbott
4de73f823c i18n: Update translation data from Transifex. 2023-09-15 17:20:41 -07:00
Anders Kaseorg
39a908d350 ci: Restore commented clean_unused_caches.py invocation.
The comment logic doesn’t make sense.  Every build gets to write to
the caches; some builds do in fact add new items, and without
clean_unused_caches.py there’s no way for them to remove items.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit 124c5d02e5)
2023-09-15 13:12:36 -07:00
Anders Kaseorg
94af282460 requirements: Upgrade Python requirements.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit 9a53baea93)
2023-09-15 12:22:42 -07:00
Anders Kaseorg
547ac31ee6 requirements: Upgrade Python requirements.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit 1905df2342)
2023-09-15 12:21:28 -07:00
Anders Kaseorg
7c50e1a40e ruff: Fix PIE808 Unnecessary start argument in range.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit 81bd63cb46)
2023-09-15 12:21:28 -07:00
Alex Vandiver
e2dcea1664 requirements: Use greenlet>=3.0.0a1 to fix uwsgi segfault.
Pull in the fix for python-greenlet/greenlet#330.

(cherry picked from commit 2e760f18ac)
2023-09-15 12:12:34 -07:00
Tim Abbott
839c86ead5 css: Fix backporting error of back-to-login button.
In 7.x, this was invalid syntax with our postcss-preset-env configuration.

See the following for context:

https://chat.zulip.org/#narrow/stream/49-development-help/topic/webpack.20exception.20running.207.2Ex/near/1641309
https://chat.zulip.org/#narrow/stream/2-general/topic/CSS.20nesting.20syntax/near/1528649
2023-09-15 12:04:38 -07:00
Alex Vandiver
48995f8218 ci: Temporarily upgrade postgresql-client-common before upgrading.
This works around a failure in the current postgresql-client-common
and postgresql-client-15 packages; it exists primarily to improve
the signal on our CI builds, as the failure is a real failure caused
by the package upgrade process.
2023-09-15 10:22:55 -07:00
Daniil Fadeev
276830b275 left_sidebar: Fix the layout for filter names that are long. 2023-09-15 10:22:55 -07:00
Alex Vandiver
f43736bef5 nginx: Do not forward X-amz-cf-id header to S3.
All `X-amz-*` headers must be included in the signed request to S3;
since Django did not take those headers into account (it constructed a
request from scratch, while nginx's request inherits them from the
end-user's request), the proxied request fails to be signed correctly.

Strip off the `X-amz-cf-id` header added by CloudFront.  While we
would ideally strip off all `X-amz-*` headers, this requires a
third-party module[^1].

[^1]: https://github.com/openresty/headers-more-nginx-module#more_clear_input_headers
2023-09-15 10:22:55 -07:00
Karl Stolley
49d7830886 compose: Render Mac-specific Cmd, Return at compose bottom. 2023-09-15 10:22:55 -07:00
Alex Vandiver
761dae7571 nginx: Suppress proxy warnings when the proxy itself sent the request.
This is common in cases where the reverse proxy itself is making
health-check requests to the Zulip server; these requests have no
X-Forwarded-* headers, so would normally hit the error case of
"request through the proxy, but no X-Forwarded-Proto header".

Add an additional special-case for when the request's originating IP
address is resolved to be the reverse proxy itself; in these cases,
HTTP requests with no X-Forwarded-Proto are acceptable.
2023-09-15 10:22:55 -07:00
Mateusz Mandera
d9c94944e0 docs: Add a warning about restarting individual services.
restart-server is almost always the way to go, so we can be clearer
about it.
2023-09-15 10:22:55 -07:00
Anders Kaseorg
3780ee2fc6 middleware: Fix exception logging format on JSON views.
Previously (with ERROR_REPORTING = True), we’d stuff the entire
traceback of the initial exception into the subject line of an error
email, and then also send a separate email for the JSON 500 response.
Instead, log one error with the standard Django format.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2023-09-15 10:22:55 -07:00
Alex Vandiver
ff520a3d52 requirements: Downgrade orjson to 3.9.2.
orjson 3.9.3 introduced a crash (ijl/orjson#415) -- revert to the last
version before the bug.

(cherry picked from commit 2612a3b657)
2023-08-31 19:06:29 +00:00
Alex Vandiver
170f8dabd4 version: Update version after 7.3 release. 2023-08-25 18:19:21 +00:00
Alex Vandiver
b85046eb08 Release Zulip Server 7.3. 7.3 2023-08-25 17:57:18 +00:00
Mateusz Mandera
ee9a450f4e bulk_access_messages_expect_usermessage: Fix function name and comments.
The name and docstring were just wrong, having a UserMessage row isn't
sufficient for having message access and is actually only relevant in a
private stream with private history. The function is only used in a
single place anyway, in bulk_access_messages.

The comment mentioning this function in handle_remove_push_notification
can be tweaked to just not mention any function specifically and just
say why we're not checking message access.
2023-08-25 17:57:09 +00:00
Mateusz Mandera
26f0695b94 delete_in_topic: Add comment explaining the access logic. 2023-08-25 17:57:09 +00:00
Mateusz Mandera
a30cd12433 CVE-2023-32678: Prevent unauthorized editing/deletion in priv streams.
Users who used to be subscribed to a private stream and have been
removed from it since retain the ability to edit messages/topics, and
delete messages that they used to have access to, if other relevant
organization permissions allow these actions. For example, a user may be
able to edit or delete their old messages they posted in such a private
stream. An administrator will be able to delete old messages (that they
had access to) from the private stream.

We fix this by fixing the logic in has_message_access (which lies at the
core of our message access checks - access_message() and
bulk_access_messages())
to not rely on only a UserMessage row for checking access but also
verify stream type and subscription status.
2023-08-25 17:56:57 +00:00
Anders Kaseorg
ea0b8cc011 requirements: Fix transitively replaced two_factor migrations.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit 4300ec3293)
2023-08-24 21:22:12 +00:00
Anders Kaseorg
6b016eb5bf check-database-compatibility: Ignore twofactor typo.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit ead7b9177a)
2023-08-24 21:21:38 +00:00
Satyam Bansal
35b0b2fb6a integrations: Add support for "Test plugin" in Sentry integration.
Previously, if a user tried to create a webhook using the Webhooks
plugin in Sentry and used the "Test plugin" to test the webhook,
the server would send a 500 error, even though the integration
worked perfectly. This led users to believe that the integration
was not working.

Fixes #26173.

(cherry picked from commit eb8714c9dc)
2023-08-23 03:06:07 +00:00
Satyam Bansal
05c2269571 integrations: Add Raven SDK test to Sentry Integration.
(cherry picked from commit 6898667fa4)
2023-08-23 03:06:07 +00:00