Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Db/DirectMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function getByToken($token) {
->from('officeonline_direct')
->where($qb->expr()->eq('token', $qb->createNamedParameter($token)));

$cursor = $qb->execute();
$cursor = $qb->executeQuery();
$row = $cursor->fetch();
$cursor->closeCursor();

Expand Down
9 changes: 3 additions & 6 deletions lib/Db/WopiMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,15 @@ public function generateFileToken($fileId, $owner, $editor, $version, $updatable
* Given a token, validates it and
* constructs and validates the path.
* Returns the path, if valid, else false.
*
* @param string $token
* @return Wopi
*/
public function getWopiForToken($token) {
public function getWopiForToken(string $token): ?Wopi {
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from('officeonline_wopi')
->where(
$qb->expr()->eq('token', $qb->createNamedParameter($token))
);
$result = $qb->execute();
$result = $qb->executeQuery();
$row = $result->fetch();
$result->closeCursor();

Expand All @@ -108,7 +105,7 @@ public function getWopiForToken($token) {
if ($wopi->getExpiry() < $this->timeFactory->getTime()) {
$qb = $this->db->getQueryBuilder();
$qb->delete('officeonline_wopi')->where($qb->expr()->lt('expiry',
$qb->createNamedParameter($this->timeFactory->getTime(), IQueryBuilder::PARAM_INT)))->execute();
$qb->createNamedParameter($this->timeFactory->getTime(), IQueryBuilder::PARAM_INT)))->executeStatement();
return null;
}

Expand Down
7 changes: 6 additions & 1 deletion lib/Middleware/WOPIMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,13 @@ public function beforeController($controller, $methodName) {
$accessToken = $this->request->getParam('access_token');
[$fileId, ,] = Helper::parseFileId($fileId);
$wopi = $this->wopiMapper->getWopiForToken($accessToken);

if ($wopi === null) {
throw new NotPermittedException('Unable to find a valid wopi for the given access token.');
}

if ((int)$fileId !== $wopi->getFileid()) {
throw new NotPermittedException();
throw new NotPermittedException("Wopi token doesn't match the expected file id");
}
} catch (\Exception $e) {
$this->logger->error('Failed to validate WOPI access', [ 'exception' => $e ]);
Expand Down
Loading