Skip to content

Commit a683b01

Browse files
committed
Fix signature verification
1 parent 1b4351a commit a683b01

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

tools/bazar/controllers/ApiController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public function postFormActorInbox($formId, Request $request)
134134
if ($activityPubService->isEnabled($form)) {
135135
$activity = json_decode($request->getContent(), true);
136136

137-
// $httpSignatureService->verifySignature($request);
137+
$httpSignatureService->verifySignature($request);
138138
$activityPubService->processActivity($activity, $form);
139139

140140
return new ApiResponse(null, Response::HTTP_OK, ['Content-Type' => 'application/activity+json']);

tools/bazar/services/HttpSignatureService.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,13 @@ public function verifySignature(Request $request) {
112112
throw new Exception('Malformed public key');
113113
}
114114

115+
// We cannot use getRequestUri() because it returns the real URI, eg. /?api/forms/2/actor
116+
$requestUri = $request->getScriptName();
117+
115118
$sigParts = [];
116119
foreach (explode(' ', $sigConf['headers']) as $headerKey) {
117120
if ($headerKey === '(request-target)') {
118-
$sigParts[] = sprintf('%s: %s %s', $headerKey, strtolower($request->getMethod()), $request->getRequestUri());
121+
$sigParts[] = sprintf('%s: %s %s', $headerKey, strtolower($request->getMethod()), $requestUri);
119122
} else {
120123
if (!$request->headers->has($headerKey)) {
121124
throw new Exception('Missing signature part: ' . $headerKey);
@@ -129,8 +132,6 @@ public function verifySignature(Request $request) {
129132
}
130133

131134
if ($request->headers->get('Digest') !== $this->getDigest($request->getContent())) {
132-
var_dump('DIGEST1', $request->headers->get($headerKey));
133-
var_dump('DIGEST2', $this->getDigest($request->getContent()));
134135
throw new Exception('Digest mismatch');
135136
}
136137
}

0 commit comments

Comments
 (0)