Skip to content

Conversation

@didoda
Copy link
Member

@didoda didoda commented Feb 5, 2025

This introduces some security checks for internals /api/{action} calls.

Request on urls like /api/* from browser will be blocked with 401 Unauthorized, because /api is supposed to be used as internal proxy from ajax calls.

When no user is authenticated or user has no roles: 401 Unauthorized.

When user has role admin, skip all checks.

When user has non admin roles, this checks {action} considering allowed methods for the user: data is retrieved from BEdita api, to consider which methods are allowed per action; you can customize the "blocking" logic, with a configuration ApiProxy.blocked. An example follows

[
    'ApiProxy' => [
        'blocked' => [
            'objects' => ['GET', 'POST', 'PATCH', 'DELETE'],
            'users' => ['GET', 'POST', 'PATCH', 'DELETE'],
        ],
    ],
],

This introduces some refactor to avoid using api/objects and api/users, by using specific routes, with "safe" data (no relationships, no included, etc.

@didoda didoda added bug Something isn't working release:patch labels Feb 5, 2025
@didoda didoda added this to the 5.x milestone Feb 5, 2025
@didoda didoda changed the title Secure API controller Secure api "proxy" controller Feb 5, 2025
@codecov
Copy link

codecov bot commented Feb 5, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.65%. Comparing base (fe029b4) to head (9653eb1).
Report is 11 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##             master    #1224    +/-   ##
==========================================
  Coverage     99.65%   99.65%            
- Complexity     1321     1339    +18     
==========================================
  Files            97       98     +1     
  Lines          5151     5252   +101     
==========================================
+ Hits           5133     5234   +101     
  Misses           18       18            

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@didoda didoda marked this pull request as ready for review February 5, 2025 17:07
@didoda didoda marked this pull request as draft February 6, 2025 09:19
@didoda didoda marked this pull request as ready for review February 6, 2025 11:32
@didoda didoda merged commit 42814dd into bedita:master Feb 6, 2025
9 checks passed
@didoda didoda deleted the fix/secure-api-controller branch February 6, 2025 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working release:patch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant