@@ -88,8 +88,8 @@ public function currentUserHasSigned(): bool {
8888 }
8989 }
9090
91- if ($ this ->isValidWOPIRequest ()) {
92- // Richdocuments and Collabora doing WOPI requests for the user
91+ if ($ this ->isAllowedRequest ()) {
92+ // Services such as Collabora doing requests for the user
9393 return true ;
9494 }
9595
@@ -126,27 +126,41 @@ public function currentUserHasSigned(): bool {
126126 return false ;
127127 }
128128
129- protected function isValidWOPIRequest (): bool {
130- return $ this ->isWOPIRemoteAddress ()
131- && $ this ->isAllowedAppPath ()
129+ protected function isAllowedRequest (): bool {
130+ return $ this ->isRequestAllowedInConfig ()
131+ || $ this ->isValidWOPIRequest ('richdocuments ' )
132+ || $ this ->isValidWOPIRequest ('officeonline ' );
133+ }
134+
135+ protected function isRequestAllowedInConfig (): bool {
136+ $ allowedPath = $ this ->config ->getAppValue (Application::APPNAME , 'allow_path_prefix ' );
137+ $ allowedRanges = $ this ->allowedRangeForApp (Application::APPNAME , 'allow_ip_ranges ' );
138+ return $ this ->isRemoteAddressInRanges ($ allowedRanges )
139+ && $ this ->isPathInfoStartingWith ($ allowedPath )
140+ && $ this ->isAllowedScriptName ();
141+ }
142+
143+ protected function isValidWOPIRequest (string $ app ): bool {
144+ $ allowedPath = '/apps/ ' . $ app . '/wopi/ ' ;
145+ $ allowedRanges = $ this ->allowedRangeForApp ($ app , 'wopi_allowlist ' );
146+ return $ this ->isRemoteAddressInRanges ($ allowedRanges )
147+ && $ this ->isPathInfoStartingWith ($ allowedPath )
132148 && $ this ->isAllowedScriptName ();
133149 }
134150
135- protected function isAllowedAppPath (): bool {
136- return strpos ($ this ->request ->getPathInfo (), '/apps/richdocuments/wopi/ ' ) === 0
137- || strpos ($ this ->request ->getPathInfo (), '/apps/officeonline/wopi/ ' ) === 0 ;
151+ protected function isPathInfoStartingWith (string $ allowedPath ): bool {
152+ // no path allowed
153+ if ($ allowedPath === '' ) {
154+ return false ;
155+ }
156+ return strpos ($ this ->request ->getPathInfo (), $ allowedPath ) === 0 ;
138157 }
139158
140159 protected function isAllowedScriptName (): bool {
141160 return substr ($ this ->request ->getScriptName (), 0 - strlen ('/index.php ' )) === '/index.php ' ;
142161 }
143162
144- protected function isWOPIRemoteAddress (): bool {
145- $ allowedRanges = array_merge (
146- $ this ->allowedRangeForApp ('richdocuments ' ),
147- $ this ->allowedRangeForApp ('officeonline ' )
148- );
149-
163+ protected function isRemoteAddressInRanges (array $ allowedRanges ): bool {
150164 $ userIp = $ this ->request ->getRemoteAddress ();
151165 foreach ($ allowedRanges as $ range ) {
152166 try {
@@ -164,8 +178,8 @@ protected function isWOPIRemoteAddress(): bool {
164178 return false ;
165179 }
166180
167- private function allowedRangeForApp (string $ appId ): array {
168- $ allowedRangesString = $ this ->config ->getAppValue ($ appId , ' wopi_allowlist ' );
181+ private function allowedRangeForApp (string $ appId, string : $ configKey ): array {
182+ $ allowedRangesString = $ this ->config ->getAppValue ($ appId , $ configKey );
169183 if ($ allowedRangesString === '' ) {
170184 return [];
171185 }
0 commit comments