Repository navigation
fix: split security labels on the first = only - #10808
Conversation
|
No actionable comments were generated in the recent review. WalkthroughA shared utility now parses database security labels by splitting at the first equals sign. Sequence, column, table, and tablespace formatters use it. Tests cover labels that contain equals signs and other parsing cases. ChangesSecurity label parsing
Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix · Severity of issue fixed: Medium Suggested reviewers: Merge Risk:
|
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues block approval of the security-label parsing change.
No open issues 🎉
What changed in this PR
Fixes #10807 by preserving = characters within security labels, preventing parsing errors that block pgAdmin’s Properties dialogs.
Changes:
- Adds a shared parser that splits
provider=labelstrings only at the first=. - Uses the parser in column, table, sequence, and tablespace formatters.
- Adds database-free unit tests for parsing edge cases and the column formatter regression.
| File | Description |
|---|---|
web/pgadmin/browser/server_groups/servers/utils.py |
Adds the shared security-label parser. |
web/pgadmin/browser/server_groups/servers/tests/test_parse_seclabels_from_db.py |
Tests parser behavior and the column formatter regression. |
web/pgadmin/browser/server_groups/servers/tablespaces/__init__.py |
Uses the shared parser for tablespace labels. |
web/pgadmin/browser/server_groups/servers/databases/schemas/tables/utils.py |
Uses the shared parser for table labels. |
web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/utils.py |
Uses the shared parser for column labels. |
web/pgadmin/browser/server_groups/servers/databases/schemas/sequences/__init__.py |
Uses the shared parser for sequence labels. |
Review effort: Balanced
dpage
left a comment
There was a problem hiding this comment.
Thanks for this. The fix is right: the four copies of the loop in the column, table, sequence and tablespace formatters used a bare split('='), which fails as soon as the label contains an =, and splitting on the first = only is correct because the label is the free-text half. I ran the new tests locally against PG18 and they pass, and pycodestyle is clean on the changed files.
🟢 Suggestion
There is already a helper for this with an almost identical name. parse_sec_labels_from_db() in web/pgadmin/browser/server_groups/servers/databases/utils.py does the same job for domains, functions and foreign tables (it returns {'seclabels': [...]} rather than the bare list, and treats None as empty). Having parse_sec_labels_from_db and parse_seclabels_from_db side by side is an easy trap for the next person. It's not a blocker, but if you're happy to, either reuse the existing one, or (better, see the note below) switch the existing one over to your split('=', 1) and have it call yours, so that there is one implementation.
ℹ️ Note
The description says the other nodes are fine because they use the ([^=]+)=(.*$) regex. They are fine for an = in the label, but not for a newline: . doesn't match \n, so for a multi-line label (which an Anonymizer rule can easily be) re.search returns None and sec.group(1) raises AttributeError. Your split('=', 1) handles that case correctly, which is another reason to make it the single implementation. I'm happy for that to be a follow-up rather than part of this PR.
- Correctness: logic is sound
- Security: no vulnerabilities introduced
- Error handling: failures are handled gracefully
- Tests: changes are adequately tested
- Documentation: docs updated if needed
Fixes #10807
Security labels are free text, but four formatters rebuilt them with
provider, label = seclbls.split('='). A label that contains=(for example a PostgreSQL Anonymizer rule such asMASKED WITH VALUE $$a=b$$) raisedtoo many values to unpack (expected 2, got 3)and the Properties dialog would not open.parse_seclabels_from_db()toservers/utils.py. It splits on the first=only (a provider name never contains one) and returns the{provider, label}list the client expects.=regex, so they are unchanged.Tests: new
servers/tests/test_parse_seclabels_from_db.pycovers plain labels, labels with one and several=, an empty label, ordering, no labels, andcolumn_formatterwith the label from the issue. Without the change in the callers thecolumn_formattercase fails with the reportedValueError; with it all 6 pass. I ran them without a PostgreSQL server (the class skips the server connection insetUp).pycodestyleis clean for the changed lines. I did not run the full regression suite or the UI against a live server.Written with AI assistance (Claude); I reviewed the diff and ran the tests above.
Summary by CodeRabbit
=. Labels continue to show their provider and full label text.