19831 Commits

Author SHA1 Message Date
Alex Vandiver
cb8dc451a8 compilemessages: Weblate's Language-Team uses <>.
(cherry picked from commit 4c2cf4dca8)
2025-07-25 23:49:32 +00:00
Anders Kaseorg
175ec1f365 CVE-2025-52559: Generate HTML for digest new channels safely.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2025-07-02 11:40:30 -07:00
Anders Kaseorg
1a8429e338 CVE-2025-52559: Generate HTML for digest message sender safely.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2025-07-02 11:40:26 -07:00
Anders Kaseorg
6608c87772 CVE-2025-52559: Generate HTML for digest recipient header safely.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2025-07-02 11:40:20 -07:00
Alex Vandiver
9002cf750f thumbnail: Add flag for when thumbnail files are missing.
(cherry picked from commit de67d37884)
2025-07-01 16:37:03 -07:00
Anders Kaseorg
ea27b848fc mypy: Add types-requests-oauthlib, types-uwsgi.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit 0b776e2c15)
2025-06-26 17:40:12 -07:00
Tim Abbott
8cff227ecf api docs: Clarify how the various presence APIs relate.
Co-authored-by: Greg Price <greg@zulip.com>
(cherry picked from commit ea68b7320a)
2025-06-26 10:02:57 -07:00
Tim Abbott
fdea941046 docs: Delete legacy presence subsystem page.
Everything on this page is now better explained in the API
documentation for presence.

(cherry picked from commit 8179a31dc7)
2025-06-26 10:02:57 -07:00
Alex Vandiver
77da214e3c send_email: Only attempt suppression list removal with credentials.
Servers without any configured credentials raise a NoCredentialsError,
which is not a subclass of botocore.exceptions.ClientError, and hence
abort the password reset attempt.

Check for if we have any credentials at all before we attempt the API
call.

(cherry picked from commit 66c123dd43)
2025-06-26 10:02:57 -07:00
Sérgio Glórias
358a9a5fbe email_mirror: Also strip "SV:" from subject.
Observed in emails from Nordic countries, the prefix SV: is used instead of RE:.

(cherry picked from commit d817bd5faf)
2025-06-26 10:02:57 -07:00
Niklas Fiekas
e29bcff2fb email_mirror: Also strip "Re[123]:" from subject.
Observed consecutively numbered replies from Outlook.

(cherry picked from commit e4d366d159)
2025-06-26 10:02:57 -07:00
Niloth P
1462fe7bb2 integrations: Add OpenSearch incoming webhook integration.
Co-authored-by: merlinz01 <158784988+merlinz01@users.noreply.github.com>
(cherry picked from commit 22c80117f5)
2025-06-26 10:02:57 -07:00
PieterCK
6b9365f616 mattermost_import: Except error when converting messages HTML.
This adds a try-except block when running html2text when processing raw
messages from HTML to markdown.

convert_html_to_text is added mainly for testing convinience. We don't
have any sample of Mattermosts' problematic content that could trigger
this sort of error yet, so the test mocks convert_html_to_text to raise
error instead.

(cherry picked from commit 201a71b575)
2025-05-21 17:03:59 -07:00
PieterCK
a5ee0e913e mattermost_import: Log when processing messages.
This logs a line for every batch of messages processed by
process_list_in_batches.

(cherry picked from commit 45b396393f)
2025-05-21 17:03:59 -07:00
Anders Kaseorg
f388030e85 requirements: Upgrade Python requirements.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit acd7353538)
2025-05-16 13:06:58 -07:00
Anders Kaseorg
c657b6cc72 test_auth_backends: Fix AuthException construction.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit 7566e6549e)
2025-05-16 13:06:58 -07:00
Sahil Batra
c0cd582f0c streams: Check creation permission when updating channel privacy.
User who did not have permission to create public channels
could create them by first creating a private or web-public
channel, if they had the permission to create them, and then
changing privacy of that stream to be a public stream.

Similarly user without permission to create private channels
could also create them.

This commit fixes both these bugs.
2025-05-15 14:11:47 -07:00
Sahil Batra
53f885fa15 streams: Fix events send when archiving and unarchiving streams.
(cherry picked from commit 7c470f0161)
2025-05-07 15:38:22 -07:00
Sahil Batra
43c6e3d47f register: Include archived channels in "streams" field.
(cherry picked from commit ae579aa25a)
2025-05-07 15:38:22 -07:00
Sahil Batra
7911ca0cee events: Do not compute first_message_id unnecessarily.
"first_message_id" field for subscription objects needs
to be updated when archiving a stream as we send a
notification message, but first_message_id will only
change if the stream did not have any messages previously.

This commit updates the code to update first_message_id
only when required.

(cherry picked from commit a6cc33f478)
2025-05-07 15:38:22 -07:00
Prakhar Pratyush
859cc29657 unread_data: Ensure deterministic ordering of unread message rows.
Earlier, in `get_raw_unread_data` the ordering was applied inside
the CTE.

Once we leave the CTE scope and do a join, SQL makes no promise
about preserving the row order unless we re-specify ORDER BY in
the outer query.

Since, there was no ORDER BY clause in the outer query it was
resulting in a random ordering of the entries. This bug was caught
by `test_unreads_case_insensitive_topics` failing in a flaky way.

This commit fixes the bug.

(cherry picked from commit ccc82976dc)
2025-05-07 15:38:22 -07:00
Alex Vandiver
7ee999917f thumbnail: Add a tool to re-thumbnail spinners, or process old images.
(cherry picked from commit 49d2c1010a)
2025-05-07 15:38:22 -07:00
Shubham Padia
d6fadeec77 attachments: Allow seeing attachments to users with content access.
Fixes https://chat.zulip.org/#narrow/channel/9-issues/topic/Can't.20view.20images.20in.20private.20channel.2E

(cherry picked from commit 700da670cf)
2025-05-07 15:38:22 -07:00
Shubham Padia
9bb9c20c88 test_subs: Add check_subscription_exists helper.
Fetching a subscription and then checking if it exists was taking too
much space in a test and making it feel convoluted. We're planning to
check it more in future commits.

(cherry picked from commit 6baa106460)
2025-05-07 15:38:22 -07:00
Shubham Padia
69ac1c0724 attachments: Do not fetch complete owner object.
We just need to compare the user profile id and the owner id, we will
save 1 query call this way.

(cherry picked from commit ca50b5dac7)
2025-05-07 15:38:22 -07:00
Mateusz Mandera
fea421b54d ldap: Add migration to fix incorrect system group memberships.
In #34510 we fixed the underlying bug in the ldap integration, which
would cause users to end up with their system group memberships not
matching their .role value. However, users who may already be in that
state still need to be fixed through a migration. We implement that
here.

There are two things we fix here:
1. Group memberships. The user should have a direct group membership
   for the specific system group implied by their .role.
2. We want to also add the missing RealmAuditLog entry.
2025-05-07 12:56:53 -07:00
Mateusz Mandera
6ea67a7df2 ldap: Fix the syncing of user role via AUTH_LDAP_USER_FLAGS_BY_GROUP.
This was broken, due the mechanism simply using our
is_guest/is_realm_admin/etc. role setters, but failing to adjust system
group memberships - resulting in corrupted database state.
We need to ensure that change_user_role is called for setting user role.

There are two relevant codepaths that run the sync based on
AUTH_LDAP_USER_FLAGS_BY_GROUP and thus need to get this right:
1. manage.py sync_ldap_user_data
2. Just-in-time user creation when a user without a Zulip account logs
   in for the first using their ldap credentials. After
   get_or_build_user returns, django-auth-ldap sees that the user
   account has just been created, and proceeds to run ._populate_user().

Now that both user.save() and do_change_user_realm will be getting
called together, we need to ensure this always happens atomically.

This imposes the need to override _get_or_create_user to put it in a
transaction. The troublesome consequence is that this new
`atomic(savepoint=False)` causes the usual type of issue, where tests
testing error get their transaction rolled back and cannot continue
executing.

To get around that, we add a test helper
`artificial_transaction_savepoint` which allows these tests to wrap
their problematic blocks in an artificial transaction which provides a
savepoint, thus preventing the full test transaction rollback derailing
the rest of the test.
2025-05-07 12:56:53 -07:00
Mateusz Mandera
33f4cd1ad4 realm_creation: Disable open realm creation if no password backend. 2025-04-15 11:19:23 -07:00
Mateusz Mandera
b5ab90aaa4 signup: Prevent unauthorized signup for realms without EmailAuthBackend.
Zulip supports a configuration where account creation is limited solely
by being able to authenticate with a single-sign on authentication
backend, such as Google Authentication, SAML, or LDAP (i.e., the
organization places no restrictions on email address domains or
invitations being required to join, but has disabled the
EmailAuthBackend that is used for email/password authentication).

A bug in the Zulip server meant that Zulip allowed users to create an
account in such organizations by confirming their email address, without
having an account with the SSO authentication backend.

Co-authored-by: Tim Abbott <tabbott@zulip.com>
2025-04-15 11:19:23 -07:00
Alex Vandiver
ed5fc4cc19 tusd: Use GCS upload backend when the endpoint matches.
This works around tus/tusd#322, which in turn is caused by
aws/aws-sdk-go-v2#1816.  This requires separate authentication via
service account key.

Fixes: #34186.
(cherry picked from commit e1aa8b1cb0)
2025-04-14 16:02:26 -07:00
Alex Vandiver
4a35e00d1c tusd: Reject tusd terminations after we insert them into our database.
The tusd protocol allows DELETE requests ("terminations") at any
point, including after a file has successfully been uploaded.  This
can allow tusd to remove a file from the bucket, out from under Zulip.

We use the new-in-2.7.0 pre-terminate hook to look up the file which
the client is requesting to terminate, and reject the termination if
it is a file that the Zulip database is already aware of.

(cherry picked from commit cf51013bb7)
2025-04-14 16:02:26 -07:00
Sanchit Sharma
bcd88fdb68 streams: Return archived web-public channels.
(cherry picked from commit d5c83e02c3)
2025-04-14 16:02:26 -07:00
Anders Kaseorg
e6291a540c narrow: Fix get_base_query_for_search access restrictions.
The type_id is the id of a UserProfile, Stream, or DirectMessageGroup,
not the id of a type.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit ad31ef22f2)
2025-04-14 16:02:26 -07:00
Alex Vandiver
9ef4649406 tusd: Use default already set in computed_settings.
Having an additional fallback here is not necessary.

(cherry picked from commit 33339f89c3)
2025-04-10 17:42:48 -07:00
Alex Vandiver
b7e38f4dd6 s3: Support non-AWS S3 providers which do not support request checksums.
(cherry picked from commit aeed907c50)
2025-04-10 17:42:48 -07:00
Mateusz Mandera
4f86630faa do_change_user_email: Store old and new email in the audit log.
We forgot to store the actual values in the audit log, making these logs
not very helpful in actually auditing a user's email change history.

(cherry picked from commit 5814ac559f)
2025-04-10 17:42:48 -07:00
Anders Kaseorg
e916abf31e worker: Check if Sentry is initialized before calling add_breadcrumb.
Otherwise we get spammed with “Dropped breadcrumb because no client
bound” log messages.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit e8faa4a029)
2025-04-10 17:07:44 -07:00
Alex Vandiver
c3401557b7 runtusd: Respect application_server.nginx_listen_port.
In deploys `nginx_listen_port` set, tusd would fail to send its hook
requests, as it assumed that nginx would always be listening on
127.0.0.1:80.

Set the `nginx_listen_port` on the hook URL, if necessary.

(cherry picked from commit bee3c6eb59)
2025-04-01 09:29:32 -07:00
Tim Abbott
b22f514bb7 test_import_export: Fix typos. 2025-03-28 17:29:45 -07:00
Anders Kaseorg
744b7c7382 custom_profile_fields: Restrict access to users in the same realm.
This fixes CVE-2025-30369.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2025-03-28 16:56:11 -07:00
Anders Kaseorg
cce3c7ebb1 realm_export: Restrict deletion to users in the same realm.
This fixes CVE-2025-30368.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2025-03-28 16:56:00 -07:00
Mateusz Mandera
9b33e3bb14 export: Also add guardrail to the management command. 2025-03-28 16:52:44 -07:00
Mateusz Mandera
d0cdbab1c0 export: Add guardrails against generating a dysfunctional export via UI.
As explained in the comments, if in an export with consent there are no
consenting owners or in a public export there are no owners with email
visibility set to at least ADMINS, the exported data will, upon import,
create an organization without usable owner accounts.
2025-03-28 16:52:44 -07:00
Mateusz Mandera
28fee7aab8 export: Add detailed tests for export of public vs private data.
Adds detailed tests for the work in the prior commits fixing the
treatment of private data in various tables in exports with consent and
public exports.
2025-03-28 16:52:44 -07:00
Mateusz Mandera
38de0ce7af export: Don't export DirectMessageGroup info of non-consented users.
This is private information, as by inspecting the DirectMessageGroup
objects and their associated Subscription objects, you could determine
which users conversed with each other in a DM group.

This did *not* leak any actual message - only the fact that at least one
of the users in the group sent a group DM.
2025-03-28 16:52:44 -07:00
Mateusz Mandera
ffd7e4a426 export: Fix public exports.
The prior significantly restricted what data gets exported from
non-consented users. The last thing we're missing is to fix the logic
to work correctly for public exports.

Prior commits focused on addressing exports with consent. This commit
adapts it to work with public exports.:
- Do not turn user accounts into mirror dummies in the public export - or
  after export->import you'll end up with a realm with no functional
  accounts; as every user is non-consented and the original logic added in
  the prior commits will turn them into mirror dummies.
- Some of the custom fetch/process functions were changed without
  considering public exports - now they work correctly, by setting
  consenting_user_ids to an empty set.
2025-03-28 16:52:44 -07:00
Mateusz Mandera
29a05bb16f export: Scrub Subscriptions to defaults for non-consented users.
The Subscription Config is constructed in a bit of a strange way, that's
not compatible with defining a custom_fetch function.
Instead we have to extend the system to support passing a custom
function for processing just the final list of rows right before it's
returned for writing to export files.
2025-03-28 16:52:44 -07:00
Mateusz Mandera
39f1e1951b export: Don't turn non-consented deactivated users into mirror dummies.
As explained in the comment, if we turn a non-consented deactivated user
into a mirror dummy, this will violate the rule that a deactivated user
cannot restore their account by themselves after an export->import
cycle.
2025-03-28 16:52:44 -07:00
Mateusz Mandera
ff876d2df4 export: Treat is_mirror_dummy=True users as consenting.
As explained in the comment added to the function, in terms of privacy
concerns, it is fine to export all data for these accounts. And it is
important to do - so that exporting an organization which was originally
imported e.g. from Slack doesn't result in excessively limited data for
accounts that were mirror dummies and never "activated" themselves.
2025-03-28 16:52:44 -07:00
Mateusz Mandera
3c43603607 export: Treat deactivated user with consent enabled as consenting.
Prior to this, deactivated user were presumed to be non-consenting to
private data export, regardless of their setting.
2025-03-28 16:52:44 -07:00