Skip to the content.

Security Debug Information Display

Overview

The Security Debug Information feature provides developers and administrators with detailed insights into the authorization system during development. This feature displays user policies and tracks all authorization checks performed during a page request.

Features

1. Debug Mode Only

2. User Policies Display

Shows all policies assigned to the current user with:

3. Authorization Check Log

Tracks and displays all authorization checks performed during the request:

4. Interactive UI

Architecture

Components

1. AuthorizationService (src/Services/AuthorizationService.php)

Enhanced to track authorization checks:

public function checkCan(?KmpIdentityInterface $user, string $action, $resource, ...$optionalArgs): bool
{
    // ... authorization logic ...
    
    // Only log in debug mode
    if (\Cake\Core\Configure::read('debug')) {
        $this->logAuthCheck($user, $action, $resource, $resultBool, $optionalArgs);
    }
    
    return $resultBool;
}

Key methods:

2. SecurityDebugHelper (src/View/Helper/SecurityDebugHelper.php)

View helper for rendering security information:

3. Stimulus Controller (assets/js/controllers/security-debug-controller.js)

JavaScript controller for interactive UI:

Integrated display in application footer:

Usage

Viewing Security Information

  1. Enable debug mode in config/app.php or config/.env:
    'debug' => true,
    
  2. Navigate to any page in the application while logged in

  3. Scroll to the footer and click “Show Security Info”

  4. Review:
    • Your assigned policies and their scope
    • All authorization checks performed on the page
    • Which checks passed or failed

Interpreting Policy Display

Policy Table Columns:

Interpreting Authorization Log

Log Table Columns:

Color Coding:

Development Workflow

Debugging Authorization Issues

  1. Reproduce the issue: Navigate to the page with authorization problems

  2. Check the log: Click “Show Security Info” to see all authorization checks

  3. Identify failed checks: Look for red (denied) entries

  4. Verify user policies: Confirm the user has the required policy/method

  5. Check scope: Ensure branch IDs match if scope is branch-specific

Common Scenarios

Scenario 1: User can’t access a page

Scenario 2: Button/action is hidden

Scenario 3: Unexpected access granted

Performance Considerations

Debug Mode Only

Memory Usage

Best Practices

Security Considerations

Information Exposure

Production Safety

Multiple layers prevent accidental exposure:

  1. Debug mode configuration check
  2. Button only rendered in debug mode
  3. Tracking only occurs in debug mode
  4. Helper returns empty string if not in debug mode

Integration with KMP Authorization System

Policy System

Works with KMP’s existing policy infrastructure:

Identity System

Integrates with KmpIdentityInterface:

Troubleshooting

Security Info Not Visible

Problem: “Show Security Info” button doesn’t appear

Solutions:

Empty Authorization Log

Problem: No checks appear in the log

Solutions:

Incorrect Policy Display

Problem: Policies shown don’t match expectations

Solutions:

Future Enhancements

Potential improvements:

Code References

Modified Files

Key Classes

Example Output

User Policies Table

┌──────────────────┬─────────────────┬───────────────────────┬──────────────┐
│ Policy Class     │ Method          │ Scope                 │ Branches     │
├──────────────────┼─────────────────┼───────────────────────┼──────────────┤
│ MemberPolicy     │ canView         │ 🔵 Global             │ All branches │
│                  │ canEdit         │ 🔵 Branch Only        │ 1, 5, 12     │
│                  │ canDelete       │ 🟢 Branch + Children  │ 1, 5         │
└──────────────────┴─────────────────┴───────────────────────┴──────────────┘

Authorization Check Log

┌───┬─────────┬──────────────┬────────────┬──────┐
│ # │ Action  │ Resource     │ Result     │ Args │
├───┼─────────┼──────────────┼────────────┼──────┤
│ 1 │ view    │ Member #123  │ ✓ Granted  │ 0    │
│ 2 │ edit    │ Member #123  │ ✓ Granted  │ 1    │
│ 3 │ delete  │ Member #456  │ ✗ Denied   │ 0    │
└───┴─────────┴──────────────┴────────────┴──────┘