Skip to content

Commit 3a1cffd

Browse files
authored
Fix API Authentication Bypass (#7376)
# Description & Issue number it closes <!-- Please include a summary of the changes and the related issue. Please also include relevant motivation and context. --> - Fix API Authentication Bypass in apis where a query param alows security check bypass. - https://github.com/ChurchCRM/CRM/security/advisories/GHSA-v3p2-mx78-pxhc#event-489177 ## Screenshots (if appropriate) <!-- Before and after --> http://localhost/api/persons/latest?bypass=api/public was returning the full API Payload and now it returns 401. ## How to test the changes? ## Type of change - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update # How Has This Been Tested? <!-- Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration --> # Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules
2 parents c677bb6 + 7960ca1 commit 3a1cffd

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/// <reference types="cypress" />
2+
3+
context("API Private wihouth Auth", () => {
4+
it("Basic Rejcet", () => {
5+
cy.request({
6+
method: "GET",
7+
url: "/api/persons/latest",
8+
failOnStatusCode: false
9+
}).then((resp) => {
10+
const result = JSON.parse(JSON.stringify(resp.body));
11+
expect(resp.status).to.eq(401);
12+
});
13+
});
14+
15+
it("Basic Rejcet, public bypass", () => {
16+
cy.request({
17+
method: "GET",
18+
url: "/api/persons/latest?bypass=api/public",
19+
failOnStatusCode: false
20+
}).then((resp) => {
21+
const result = JSON.parse(JSON.stringify(resp.body));
22+
expect(resp.status).to.eq(401);
23+
});
24+
});
25+
26+
});

src/ChurchCRM/Slim/Middleware/AuthMiddleware.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class AuthMiddleware
1212
{
1313
public function __invoke(Request $request, RequestHandler $handler): Response
1414
{
15-
if (!str_contains($request->getUri(), 'api/public')) {
15+
if (!str_starts_with($request->getUri()->getPath(), '/api/public')) {
1616
$apiKey = $request->getHeader('x-api-key');
1717
if (!empty($apiKey)) {
1818
$authenticationResult = AuthenticationManager::authenticate(new APITokenAuthenticationRequest($apiKey[0]));

0 commit comments

Comments
 (0)