Skip to content

Security hardening: connection permissions, duplicate merge, input escaping - #2947

Merged
corsacca merged 14 commits into
developfrom
security-2026-10-26
Nov 20, 2026
Merged

corsacca merged 14 commits into
developfrom
security-2026-10-26

Conversation

@corsacca

Copy link
Copy Markdown
Member

Hardening from the October security review, one commit per area.

Record permissions

  • Connection fields (GO-57): adding a connection to a record now requires view access to that record when permissions are checked. A user's own contact record is allowed when the current user can list that user, matching what the typeahead offers. Removing a connection is unchanged. Calls with check_permissions = false are unchanged.
  • Duplicate merge on create (GO-77): when check_for_duplicates is set, the duplicate search and the merge into the matched record run with the caller's permissions instead of with checks off.

Input validation and escaping

  • Date-field list filters require a valid date (GO-56).
  • escapeHTML escapes non-string values, which list filter labels can pass (GO-60).
  • The bundled jQuery Typeahead escapes {{…}} template values and plain display text. The share modal renders the name with escapeHTML.

Login and magic links

  • Network-wide SSO fields can only be changed by super admins, and the default role is validated (GO-61).
  • Magic link REST verification requires the key to resolve to a record.

Behavior changes to note

  • A REST create or update that adds a connection to a record the user can't view now returns 403 instead of linking it.
  • A REST create with check_for_duplicates only merges into records the user can view; otherwise it creates a new record.

Tests updated: tests/unit-test-magic-url-rest-verify.php, tests/unit-test-search-viewable-post.php.

🤖 Generated with Claude Code

@github-actions

Copy link
Copy Markdown

Review

High

None found.

Medium

  1. create_post can leave an orphan record when the connection permission check fails — dt-posts/dt-posts.php:306, dt-posts/posts.php:~2640
    The new can_connect_to() 403 is returned from update_connections(), which create_post() calls after wp_insert_post and after the earlier field and contact-method writes. A create request that includes a connection to a record the user can't view now returns a 403, but the new post (and any other fields already saved) stays in the database. Callers will probably retry, which creates duplicates. The same applies to update_post, where earlier fields are already saved before the error, and to a multi-value connection list where earlier entries were already added before a later one is rejected. Consider validating connection permissions up front, before any writes, in create_post and update_post.

  2. Permission check depends on $post_settings['fields'][$type]['post_type'] — dt-posts/posts.php:~2640
    If a connection field has no post_type (custom or plugin-defined fields), $connected_post_type is '', can_view('', id) returns false, and every new connection is rejected with a confusing "connect with ID" message. Consider skipping the check or failing clearly when the target type is unknown. Also, the Disciple_Tools_Users::get_user_for_contact fallback applies only to contacts; confirm that other connection targets, such as peoplegroups, only depend on view_any_* for roles that previously could connect to them.

  3. Date validation in fields_to_sql uses is_numeric after strtotime — dt-posts/posts.php:884
    This closes the injection, but strtotime returning false on a bad start/end now returns a 400 for the whole query. Previously this produced an empty condition. Saved filters or list views with a stale or odd date value will now error instead of degrading. Intended, but worth a release note. Also, a plain value under date fields (without a start/end key) skips strtotime and relies solely on is_numeric. That is fine, but is only covered by the '0 OR 1=1' test.

Notes

  • The $check_permissions pass-through in duplicate handling (dt-posts.php, dt-posts-hooks.php), the magic-link empty-key guard, and the login-fields.php multisite/role hardening all look correct. Tests were added for the magic-link and date cases. I found no tests for the new update_connections permission path or the login-fields changes.
  • The jquery.typeahead.min.js patch is a vendored-library edit. I couldn't review the minified diff line by line, so make sure the change is reproducible (documented in the header comment) so a library upgrade doesn't silently drop the escaping.

Summary: The security fixes look sound, but the partial-write behaviour on rejected connections (item 1) should be addressed or acknowledged before merging.

… update (GO-57)

Validates every new connection, including email and title values, before
create_post or update_post writes anything, so a rejected connection leaves
no partial record. Fields without a post_type fall back to the target's
type, and records of types the user can list_all are allowed, matching the
connection typeahead.
@github-actions

Copy link
Copy Markdown

Review

High

None found.

Medium

  1. Duplicate merge can turn a create into a 403 - dt-posts/dt-posts.php:99
    The duplicate search now runs with the caller's permissions, so it returns records the user can view. The merge then calls update_post(..., $check_permissions, ...), which also requires update permission. If the match is viewable but not editable, create_post returns that error instead of creating a new record. The PR description says a create only merges into viewable records and otherwise creates a new one. Consider falling through to a normal create when the user can't update the match, or confirm the 403 is intended and update the description.

  2. Connection resolution runs twice and unresolved values skip the check - dt-posts/posts.php (check_new_connection_permissions)
    resolve_connection_value (title lookups) runs once in the check and again in update_connections. A value that doesn't resolve is skipped, which is harmless today because update_connections also only acts on numeric values. If the two paths ever diverge, the check can be bypassed. Consider resolving once and passing the result to both.

  3. No tests for the new permission paths - check_new_connection_permissions / can_connect_to (view-only, own-contact, list_all, rejected), the duplicate-merge permission change, and login-fields.php (multisite and role validation) have no coverage. These are the main security changes in the PR.

Notes

  • The earlier concern about partial writes on a rejected connection is addressed. The check runs before any write in both create_post and update_post.

Summary: The hardening looks sound; resolve the duplicate-merge 403 behaviour (item 1) and add tests for the permission paths before merging.

…t (GO-77)

When check_for_duplicates finds a match the user can view but not update,
create_post now creates a new record instead of returning the update error.
@github-actions

Copy link
Copy Markdown

Review

High

None found.

Medium

  1. New WP_Error from fields_to_sql is not handled by the mapping callers - dt-mapping/mapping-queries.php:1397,1421,1453,1547
    DT_Posts::fields_to_sql() now returns a 400 WP_Error for a non-date value in a date field (dt-posts/posts.php:~884). The callers in dt-posts check is_wp_error, but the four callers in mapping-queries.php go straight to $sql['where_sql']. On PHP 8 that is a fatal "Cannot use object of type WP_Error as array". A saved filter or map query with a bad date now fatals instead of giving an empty condition. Handle is_wp_error in those callers.

  2. Connections to records the user cannot view now return 403 - dt-posts/posts.php (check_new_connection_permissions)
    Intended per the PR description. Flows that previously linked to unviewable records (e.g. coached_by, subassigned, groups, plugin-defined connection fields) should be checked with a role that only has access_contacts.

Notes

  • Duplicate merge now filters by can_update and falls through to a normal create.
  • Permission checks run before any write in both create_post and update_post.

Summary: The hardening looks sound, but handle the new WP_Error in the mapping query callers before merging.

The mapping queries and the map totals endpoints now return the WP_Error
from fields_to_sql, so an invalid filter value such as a bad date gives a
400 instead of a fatal error.
@github-actions

Copy link
Copy Markdown

Review

High: None found.

Medium: None found.

Notes

  • All callers of fields_to_sql (including the recursive call and the four in mapping-queries.php) now handle the new WP_Error; the metrics REST callbacks pass it through.
  • Connection permission checks run before any write in create_post and update_post.
  • Duplicate merge filters by can_update and falls back to a normal create.
  • I could not review the minified typeahead diff line by line; the header comment documents how to reapply the patch.

Summary: No High or Medium issues found; the PR looks ready to merge.

@corsacca
corsacca merged commit 33c2bd8 into develop Nov 20, 2026
5 checks passed
@corsacca
corsacca deleted the security-2026-10-26 branch November 20, 2026 08:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant