1616use OCP \AppFramework \Http \JSONResponse ;
1717use OCP \AppFramework \Http \Response ;
1818use OCP \AppFramework \Middleware ;
19+ use OCP \Constants ;
1920use OCP \Files \IRootFolder ;
2021use OCP \Files \NotPermittedException ;
2122use OCP \IL10N ;
2223use OCP \IRequest ;
24+ use OCP \ISession ;
2325use OCP \IUserSession ;
2426use OCP \Share \Exceptions \ShareNotFound ;
2527use OCP \Share \IManager as ShareManager ;
@@ -31,6 +33,7 @@ public function __construct(
3133 private IRequest $ request ,
3234 private SessionService $ sessionService ,
3335 private DocumentService $ documentService ,
36+ private ISession $ session ,
3437 private IUserSession $ userSession ,
3538 private IRootFolder $ rootFolder ,
3639 private ShareManager $ shareManager ,
@@ -125,10 +128,28 @@ private function assertUserOrShareToken(ISessionAwareController $controller): vo
125128 } catch (ShareNotFound ) {
126129 throw new InvalidSessionException ();
127130 }
131+
128132 // Check if shareToken has access to document
129133 if (count ($ this ->rootFolder ->getUserFolder ($ share ->getShareOwner ())->getById ($ documentId )) === 0 ) {
130134 throw new InvalidSessionException ();
131135 }
136+
137+ /** @psalm-suppress RedundantConditionGivenDocblockType */
138+ if ($ share ->getPassword () !== null ) {
139+ $ shareId = $ this ->session ->get ('public_link_authenticated ' );
140+ if ($ share ->getId () !== $ shareId ) {
141+ throw new InvalidSessionException ();
142+ }
143+ }
144+
145+ if (($ share ->getPermissions () & Constants::PERMISSION_READ ) !== Constants::PERMISSION_READ ) {
146+ throw new InvalidSessionException ();
147+ }
148+
149+ $ attributes = $ share ->getAttributes ();
150+ if ($ attributes !== null && $ attributes ->getAttribute ('permissions ' , 'download ' ) === false ) {
151+ throw new InvalidSessionException ();
152+ }
132153 } else {
133154 throw new InvalidSessionException ();
134155 }
0 commit comments