Skip to content

fix(security): keep tenants and scoped contexts inside their boundaries - #9

Merged
ivanmercedes merged 2 commits into
mainfrom
security/tenant-boundaries
Nov 9, 2026
Merged

ivanmercedes merged 2 commits into
mainfrom
security/tenant-boundaries

Conversation

@ivanmercedes

Copy link
Copy Markdown
Owner

Moves into the package the tenant and scope checks that Flexa added on its side after a security audit, so every app using flex-fields is protected. Proposed as 0.8.1 (entry added to CHANGELOG.md).

Changes

  • REST API, expanded relationships. RecordResource no longer expands relationship fields whose target entity the caller can't read (outside api.allowed_entities, inactive, or without view).
    • New RecordResource::canExpand() and EntityRecord::relatedEntity().
  • AI / MCP. CreateFieldTool and UpdateFieldTool reject a settings.related_entity outside the context's allowed entities.
    • Before, a scoped key could link an allowed entity to a forbidden one and then read its records through ?include=relations.values.
  • Categories.
    • EntityCategory refuses, on saving, an entity_id of another tenant or a parent from another entity.
    • The resource now sets entity_id server-side; it used to come from a client-controlled Hidden field.
    • getCurrentEntity() and getDefaultEntity() now use currentTenant(); before, ?entity= resolved any tenant's entity.
  • File values.
    • New UploadPaths class: works out the tenant's upload directory from directory_pattern and tenant_key_attribute.
    • With tenancy enabled, RecordValueValidator only accepts absolute URLs or paths under that directory.
    • The generated FileUpload fields use preventFilePathTampering() with that same rule.
    • Before, a tenant could store another tenant's path; the panel would then sign it (private visibility) or delete it.
  • Error messages. A QueryException is reported and replaced with a generic message in RecordApiController::domain(), describeException() (AI tools) and FlexFieldsMcpTool, so SQL and connection details no longer leak.

Compatibility

  • No signature changes. relations(bool, ?string) stays as it is for subclasses.
  • Behaviour change: with tenancy enabled, file values outside the tenant's directory are now refused. This only affects apps that changed directory_pattern or tenant_key_attribute and resend old values. It's noted in the CHANGELOG.

Tests

  • New tests/Feature/TenantBoundariesTest.php: 5 tests.
  • Full suite: 195 tests, 900 assertions, OK (vendor/bin/phpunit --bootstrap vendor/autoload.php tests).
  • The base TestCase now registers LivewireServiceProvider. Without it, 165 tests failed to boot (Target class [livewire] does not exist).
  • Also checked inside the Flexa app: its suite passes with this version, except one assertion that expects the error key values.cover and now gets cover. That's adjusted on the app side when it upgrades.

🤖 Generated with Claude Code

ivanmercedes and others added 2 commits November 9, 2026 12:57
- REST API: expanded relationships skip entities the caller cannot read.
- AI/MCP field tools: related_entity must be an allowed entity.
- Categories: entity and parent must belong to the category's tenant;
  the resource sets entity_id server-side and scopes ?entity= to the tenant.
- File values: must be absolute URLs or paths under the tenant upload
  directory (UploadPaths); generated upload fields prevent path tampering.
- Database errors are reported and replaced by a generic message in the
  REST API, AI tool results and MCP responses.

Also registers Livewire in the base test case, which the suite needs to boot.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ivanmercedes
ivanmercedes merged commit f875ffe into main Nov 9, 2026
3 checks passed
@ivanmercedes
ivanmercedes deleted the security/tenant-boundaries branch November 9, 2026 17:15
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