Limit size of AI domain allow and deny lists

What does this MR do and why?

The Owner of a free top-level group can store megabytes in one namespace_ai_settings row through aiDomainSettingsNamespaceUpdate. Domains have no length limit and the allow and deny lists keep growing across calls, so every later save rewrites the whole row. The issue reproduced 10.1 MB in one row.

This MR caps each list at 500 domains, and each domain at 253 characters (the DNS limit for a full domain name). The validation is in Ai::NormalizesDomainLists, so it covers both the group-level lists (Ai::NamespaceSetting) and the instance-level lists (Ai::Setting). It is behind the ai_domain_settings_list_limits feature flag (gitlab_com_derisk, off by default).

The validation only checks growth and newly added domains:

  • Lists saved before the limits can still shrink.
  • Other settings on a row that is already over a limit still save.
  • Saves that change neither list skip the check, including the flag lookup.

The settings pages already show the errors the mutations return, so a rejected save shows the message to the user.

Threshold

Through the mutations, which only accept ASCII domains, each list now holds at most about 127 KB (500 × 253 characters), or about 253 KB for both lists in one row.

Rollout and rollback

  • Rollout: https://gitlab.com/gitlab-org/gitlab/-/work_items/637097. Staging first, then a test group on GitLab.com, then everyone.
  • The flag is checked against the group for group-level lists and against the organization for instance-level lists.
  • Rollback: turn the flag off. Nothing is written to the database, so the previous behaviour comes back straight away.

Not in this MR

The issue also suggests a database CHECK constraint. It is left for a follow-up, once the flag is fully on and existing rows have been checked:

  • A new CHECK would reject every save to a row already over the limit, including unrelated settings changes.
  • It can't be turned off with the feature flag.
  • A CHECK can't test each element's length without a custom function.

References

Screenshots or screen recordings

No UI changes.

How to set up and validate locally

  1. In a Rails console, turn on the flag for a top-level group and fill its allowlist to the limit:

    group = Group.find_by_full_path('flightjs')
    Feature.enable(:ai_domain_settings_list_limits, group)
    group.ai_settings.update!(allowed_domains: Array.new(500) { |i| "domain-#{i}.com" })
    group.to_global_id.to_s
  2. As an Owner of the group, run this in GraphiQL at /-/graphql-explorer, using the global ID from step 1:

    mutation {
      aiDomainSettingsNamespaceUpdate(input: {
        namespaceId: "gid://gitlab/Group/<id>"
        action: ADD
        domainSettingType: ALLOWED
        domains: ["example.com"]
      }) {
        addedDomains
        errors
      }
    }

    errors contains Each domain list can contain at most 500 domains., and the list is unchanged.

  3. Run Feature.disable(:ai_domain_settings_list_limits) in the console, then repeat step 2. example.com is added, so the list now has 501 domains.

  4. Run Feature.enable(:ai_domain_settings_list_limits, group) again, then run the mutation with action: REMOVE and domains: ["domain-0.com"]. It succeeds even though the list was over the limit.

Testing notes

Tested on 2026-10-29 in GDK at efc2b52a897e. A Rails runner script called both mutations through GitlabSchema.execute:

  • aiDomainSettingsNamespaceUpdate: as an Owner (root) of the flightjs group
  • aiDomainSettingsInstanceUpdate: as an administrator

Each call ran with a fresh request store. Row size is pg_column_size of the namespace_ai_settings row. All test data and the flag were removed afterwards.

# Flag Action Result
1 On for flightjs Add 1 domain to a 500-domain allowlist Rejected: Each domain list can contain at most 500 domains. List unchanged.
2 On for flightjs Add a 254-character domain to the denylist Rejected: Each domain can be at most 253 characters long.
3 On for flightjs Replay: add 1,000 random 1,004-character domains to the denylist in one call Rejected with both errors. Row stays at 2,228 bytes.
4 Off Add 1 domain to the 500-domain allowlist Added (501 domains).
5 Off Replay as in 3 Accepted. Row grows to 1,010,256 bytes (about 1 MB from one call).
6 On for flightjs Remove 1 domain from the 501-domain allowlist Removed.
7 On for flightjs Remove 1 long domain from the 1,000-domain denylist Removed.
8 On for flightjs Change another AI setting on the row while both lists are over the limits Saved.
9 On for flightjs Add 1 domain to the allowlist, back at 500 Rejected: Each domain list can contain at most 500 domains.
10 On for a different group only Add 1 domain to the flightjs allowlist Added, so the limits apply only where the flag is on.
11 On for the organization Instance mutation: add 1 domain to a 500-domain instance allowlist Rejected: Each domain list can contain at most 500 domains.

Automated: the MR pipeline passed. Locally, 173 examples in the model, mutation and request specs pass.

Not covered: the HTTP layer and the settings pages, because the local GDK server runs a different branch. The request spec covers the HTTP path, and the settings pages already show the errors the mutations return.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Related to https://gitlab.com/gitlab-org/gitlab/-/work_items/636069

Edited by Charlie Linacre

Merge request reports

Loading
Loading