Adding a tag to a domain that already has tags silently discards it (API returns 200 with empty body)

Author: smpaz7467Created Jul 28, 2026Updated Sep 26, 2026
Labelsstale

Contribution guidelines

Checklist prior issue creation

  • I understand that failure to follow below instructions may cause this issue to be closed.
  • I understand that vague, incomplete or inaccurate information may cause this issue to be closed.
  • I understand that this form is intended solely for reporting software bugs and not for support-related inquiries.
  • I understand that all responses are voluntary and community-driven, and do not constitute commercial support.
  • I confirm that I have reviewed previous issues to ensure this matter has not already been addressed.
  • I confirm that my environment meets all prerequisite requirements as specified in the official documentation.

Description

A tag can only be added to a domain while that domain has no tags yet. Every later tag is silently discarded.

tags_domain has a unique key on (tag_name, domain). The tag widget in the UI keeps the full tag list in a hidden field and submits all tags on save, so saving a domain that already carries a tag re-inserts that tag:

https://github.com/mailcow/mailcow-dockerized/blob/master/data/web/inc/functions.mailbox.inc.php#L2850-L2855

The duplicate INSERT raises a PDO exception. Nothing catches it on the domain paths, so:

  • the remaining (new) tags in the list are never inserted,
  • the function returns without ever adding its domain_modified success message,
  • the API answers HTTP 200 with an empty body, and the UI reports nothing wrong.

The three tags_mailbox inserts already guard against exactly this with a try { ... } catch (Exception $e) {}, so mailbox tags are unaffected. The three tags_domain inserts (domain add, and both domain edit branches) have no such guard.

Steps to reproduce:

  1. Create a domain with no tags.
  2. Add a first tag and save — works.
  3. Add a second tag and save. The UI submits ["existing", "new"].
  4. Observe the new tag is not stored.

Via the API:

bash
# domain has tag "alpha" already
curl -sS -H "X-API-Key: $API_KEY" -H "Content-Type: application/json" -X POST \
  "$MAILCOW_URL/api/v1/edit/domain" \
  --data '{"items":["example.test"],"attr":{"tags":["alpha","beta"]}}' -w '\nHTTP=%{http_code}\n'

Observed:

HTTP=200

with an empty response body, and beta missing from tags_domain.

Expected: an already assigned tag is skipped and beta is stored, as happens for mailbox tags.

A request that combines a description change with a duplicate tag shows the partial-failure clearly: the description is written (it happens before the tag loop) and the tags after the duplicate are not.

Logs:

plain
N/A - the exception is not surfaced; the request ends with HTTP 200 and an empty body.

Which branch are you using?

staging

Which architecture are you using?

x86_64

Operating System:

Debian GNU/Linux

Server/VM specifications:

N/A

Is Apparmor, SELinux or similar active?

no

Virtualization technology:

Docker

Docker version:

29.5.2

docker-compose version or docker compose version:

v2.40.3

mailcow version:

staging (f4961c40)

Reverse proxy:

none

Logs of git diff:

plain
N/A

DNS check:

plain
N/A

Source: mailcow/mailcow-dockerized