Skip to content

Commit 3795c1e

Browse files
Prevent caching of API routes with dynamic content (#922)
Prevent caching of routes with dynamic content
1 parent 91c0c68 commit 3795c1e

13 files changed

Lines changed: 84 additions & 32 deletions

File tree

app/sprinkles/account/routes/routes.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
* @license https://github.com/userfrosting/UserFrosting/blob/master/LICENSE.md (MIT License)
88
*/
99

10+
use UserFrosting\Sprinkle\Core\Util\NoCache;
11+
1012
$app->group('/account', function () {
1113
$this->get('/captcha', 'UserFrosting\Sprinkle\Account\Controller\AccountController:imageCaptcha');
1214

@@ -55,6 +57,6 @@
5557

5658
$this->post('/settings/profile', 'UserFrosting\Sprinkle\Account\Controller\AccountController:profile')
5759
->add('authGuard');
58-
});
60+
})->add(new NoCache());
5961

6062
$app->get('/modals/account/tos', 'UserFrosting\Sprinkle\Account\Controller\AccountController:getModalAccountTos');

app/sprinkles/admin/routes/activities.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77
* @license https://github.com/userfrosting/UserFrosting/blob/master/LICENSE.md (MIT License)
88
*/
99

10+
use UserFrosting\Sprinkle\Core\Util\NoCache;
11+
1012
/**
1113
* Routes for administrative activity monitoring.
1214
*/
1315
$app->group('/activities', function () {
1416
$this->get('', 'UserFrosting\Sprinkle\Admin\Controller\ActivityController:pageList')
1517
->setName('uri_activities');
16-
})->add('authGuard');
18+
})->add('authGuard')->add(new NoCache());
1719

1820
$app->group('/api/activities', function () {
1921
$this->get('', 'UserFrosting\Sprinkle\Admin\Controller\ActivityController:getList');
20-
})->add('authGuard');
22+
})->add('authGuard')->add(new NoCache());

app/sprinkles/admin/routes/admin.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,20 @@
77
* @license https://github.com/userfrosting/UserFrosting/blob/master/LICENSE.md (MIT License)
88
*/
99

10+
use UserFrosting\Sprinkle\Core\Util\NoCache;
11+
1012
/**
1113
* Routes for administrative panel management.
1214
*/
1315
$app->group('/dashboard', function () {
1416
$this->get('', 'UserFrosting\Sprinkle\Admin\Controller\AdminController:pageDashboard')
1517
->setName('dashboard');
16-
})->add('authGuard');
18+
})->add('authGuard')->add(new NoCache());
1719

1820
$app->group('/api/dashboard', function () {
1921
$this->post('/clear-cache', 'UserFrosting\Sprinkle\Admin\Controller\AdminController:clearCache');
20-
})->add('authGuard');
22+
})->add('authGuard')->add(new NoCache());
2123

2224
$app->group('/modals/dashboard', function () {
2325
$this->get('/clear-cache', 'UserFrosting\Sprinkle\Admin\Controller\AdminController:getModalConfirmClearCache');
24-
})->add('authGuard');
26+
})->add('authGuard')->add(new NoCache());

app/sprinkles/admin/routes/groups.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
* @license https://github.com/userfrosting/UserFrosting/blob/master/LICENSE.md (MIT License)
88
*/
99

10+
use UserFrosting\Sprinkle\Core\Util\NoCache;
11+
1012
/**
1113
* Routes for administrative group management.
1214
*/
@@ -15,7 +17,7 @@
1517
->setName('uri_groups');
1618

1719
$this->get('/g/{slug}', 'UserFrosting\Sprinkle\Admin\Controller\GroupController:pageInfo');
18-
})->add('authGuard');
20+
})->add('authGuard')->add(new NoCache());
1921

2022
$app->group('/api/groups', function () {
2123
$this->delete('/g/{slug}', 'UserFrosting\Sprinkle\Admin\Controller\GroupController:delete');
@@ -29,12 +31,12 @@
2931
$this->post('', 'UserFrosting\Sprinkle\Admin\Controller\GroupController:create');
3032

3133
$this->put('/g/{slug}', 'UserFrosting\Sprinkle\Admin\Controller\GroupController:updateInfo');
32-
})->add('authGuard');
34+
})->add('authGuard')->add(new NoCache());
3335

3436
$app->group('/modals/groups', function () {
3537
$this->get('/confirm-delete', 'UserFrosting\Sprinkle\Admin\Controller\GroupController:getModalConfirmDelete');
3638

3739
$this->get('/create', 'UserFrosting\Sprinkle\Admin\Controller\GroupController:getModalCreate');
3840

3941
$this->get('/edit', 'UserFrosting\Sprinkle\Admin\Controller\GroupController:getModalEdit');
40-
})->add('authGuard');
42+
})->add('authGuard')->add(new NoCache());

app/sprinkles/admin/routes/permissions.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
* @license https://github.com/userfrosting/UserFrosting/blob/master/LICENSE.md (MIT License)
88
*/
99

10+
use UserFrosting\Sprinkle\Core\Util\NoCache;
11+
1012
/**
1113
* Routes for administrative permission management.
1214
*/
@@ -15,12 +17,12 @@
1517
->setName('uri_permissions');
1618

1719
$this->get('/p/{id}', 'UserFrosting\Sprinkle\Admin\Controller\PermissionController:pageInfo');
18-
})->add('authGuard');
20+
})->add('authGuard')->add(new NoCache());
1921

2022
$app->group('/api/permissions', function () {
2123
$this->get('', 'UserFrosting\Sprinkle\Admin\Controller\PermissionController:getList');
2224

2325
$this->get('/p/{id}', 'UserFrosting\Sprinkle\Admin\Controller\PermissionController:getInfo');
2426

2527
$this->get('/p/{id}/users', 'UserFrosting\Sprinkle\Admin\Controller\PermissionController:getUsers');
26-
})->add('authGuard');
28+
})->add('authGuard')->add(new NoCache());

app/sprinkles/admin/routes/roles.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
* @license https://github.com/userfrosting/UserFrosting/blob/master/LICENSE.md (MIT License)
88
*/
99

10+
use UserFrosting\Sprinkle\Core\Util\NoCache;
11+
1012
/**
1113
* Routes for administrative role management.
1214
*/
@@ -15,7 +17,7 @@
1517
->setName('uri_roles');
1618

1719
$this->get('/r/{slug}', 'UserFrosting\Sprinkle\Admin\Controller\RoleController:pageInfo');
18-
})->add('authGuard');
20+
})->add('authGuard')->add(new NoCache());
1921

2022
$app->group('/api/roles', function () {
2123
$this->delete('/r/{slug}', 'UserFrosting\Sprinkle\Admin\Controller\RoleController:delete');
@@ -33,7 +35,7 @@
3335
$this->put('/r/{slug}', 'UserFrosting\Sprinkle\Admin\Controller\RoleController:updateInfo');
3436

3537
$this->put('/r/{slug}/{field}', 'UserFrosting\Sprinkle\Admin\Controller\RoleController:updateField');
36-
})->add('authGuard');
38+
})->add('authGuard')->add(new NoCache());
3739

3840
$app->group('/modals/roles', function () {
3941
$this->get('/confirm-delete', 'UserFrosting\Sprinkle\Admin\Controller\RoleController:getModalConfirmDelete');
@@ -43,4 +45,4 @@
4345
$this->get('/edit', 'UserFrosting\Sprinkle\Admin\Controller\RoleController:getModalEdit');
4446

4547
$this->get('/permissions', 'UserFrosting\Sprinkle\Admin\Controller\RoleController:getModalEditPermissions');
46-
})->add('authGuard');
48+
})->add('authGuard')->add(new NoCache());

app/sprinkles/admin/routes/users.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
* @license https://github.com/userfrosting/UserFrosting/blob/master/LICENSE.md (MIT License)
88
*/
99

10+
use UserFrosting\Sprinkle\Core\Util\NoCache;
11+
1012
/**
1113
* Routes for administrative user management.
1214
*/
@@ -15,7 +17,7 @@
1517
->setName('uri_users');
1618

1719
$this->get('/u/{user_name}', 'UserFrosting\Sprinkle\Admin\Controller\UserController:pageInfo');
18-
})->add('authGuard');
20+
})->add('authGuard')->add(new NoCache());
1921

2022
$app->group('/api/users', function () {
2123
$this->delete('/u/{user_name}', 'UserFrosting\Sprinkle\Admin\Controller\UserController:delete');
@@ -37,7 +39,7 @@
3739
$this->put('/u/{user_name}', 'UserFrosting\Sprinkle\Admin\Controller\UserController:updateInfo');
3840

3941
$this->put('/u/{user_name}/{field}', 'UserFrosting\Sprinkle\Admin\Controller\UserController:updateField');
40-
})->add('authGuard');
42+
})->add('authGuard')->add(new NoCache());
4143

4244
$app->group('/modals/users', function () {
4345
$this->get('/confirm-delete', 'UserFrosting\Sprinkle\Admin\Controller\UserController:getModalConfirmDelete');
@@ -49,4 +51,4 @@
4951
$this->get('/password', 'UserFrosting\Sprinkle\Admin\Controller\UserController:getModalEditPassword');
5052

5153
$this->get('/roles', 'UserFrosting\Sprinkle\Admin\Controller\UserController:getModalEditRoles');
52-
})->add('authGuard');
54+
})->add('authGuard')->add(new NoCache());

app/sprinkles/admin/src/Controller/PermissionController.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,9 @@ public function getUsers(Request $request, Response $response, $args)
140140

141141
$sprunje = $classMapper->createInstance('permission_user_sprunje', $classMapper, $params);
142142

143-
$response = $sprunje->toResponse($response);
144-
145143
// Be careful how you consume this data - it has not been escaped and contains untrusted user-supplied content.
146144
// For example, if you plan to insert it into an HTML DOM, you must escape it on the client side (or use client-side templating).
147-
return $response;
145+
return $sprunje->toResponse($response);
148146
}
149147

150148
/**

app/sprinkles/admin/src/Controller/UserController.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -834,11 +834,9 @@ public function getPermissions(Request $request, Response $response, $args)
834834
$params['user_id'] = $user->id;
835835
$sprunje = $classMapper->createInstance('user_permission_sprunje', $classMapper, $params);
836836

837-
$response = $sprunje->toResponse($response);
838-
839837
// Be careful how you consume this data - it has not been escaped and contains untrusted user-supplied content.
840838
// For example, if you plan to insert it into an HTML DOM, you must escape it on the client side (or use client-side templating).
841-
return $response;
839+
return $sprunje->toResponse($response);
842840
}
843841

844842
/**

app/sprinkles/core/routes/routes.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
* @license https://github.com/userfrosting/UserFrosting/blob/master/LICENSE.md (MIT License)
88
*/
99

10+
use UserFrosting\Sprinkle\Core\Util\NoCache;
11+
1012
global $app;
1113
$config = $app->getContainer()->get('config');
1214

@@ -16,7 +18,8 @@
1618

1719
$app->get('/about', 'UserFrosting\Sprinkle\Core\Controller\CoreController:pageAbout')->add('checkEnvironment');
1820

19-
$app->get('/alerts', 'UserFrosting\Sprinkle\Core\Controller\CoreController:jsonAlerts');
21+
$app->get('/alerts', 'UserFrosting\Sprinkle\Core\Controller\CoreController:jsonAlerts')
22+
->add(new NoCache());
2023

2124
$app->get('/legal', 'UserFrosting\Sprinkle\Core\Controller\CoreController:pageLegal');
2225

0 commit comments

Comments
 (0)