1515use OC \Files \Storage \Wrapper \Wrapper ;
1616use OCA \Circles \Api \v1 \Circles ;
1717use OCA \Deck \Sharing \ShareAPIHelper ;
18+ use OCA \Federation \TrustedServers ;
1819use OCA \Files \Helper ;
1920use OCA \Files_Sharing \Exceptions \SharingRightsException ;
2021use OCA \Files_Sharing \External \Storage ;
7677class ShareAPIController extends OCSController {
7778
7879 private ?Node $ lockedNode = null ;
80+ private array $ trustedServerCache = [];
7981
8082 /**
8183 * Share20OCS constructor.
@@ -100,6 +102,7 @@ public function __construct(
100102 private IProviderFactory $ factory ,
101103 private IMailer $ mailer ,
102104 private ITagManager $ tagManager ,
105+ private ?TrustedServers $ trustedServers ,
103106 private ?string $ userId = null ,
104107 ) {
105108 parent ::__construct ($ appName , $ request );
@@ -202,6 +205,32 @@ protected function formatShare(IShare $share, ?Node $recipientNode = null): arra
202205 $ result ['item_size ' ] = $ node ->getSize ();
203206 $ result ['item_mtime ' ] = $ node ->getMTime ();
204207
208+ if ($ this ->trustedServers !== null && in_array ($ share ->getShareType (), [IShare::TYPE_REMOTE , IShare::TYPE_REMOTE_GROUP ], true )) {
209+ $ result ['is_trusted_server ' ] = false ;
210+ $ sharedWith = $ share ->getSharedWith ();
211+ $ remoteIdentifier = is_string ($ sharedWith ) ? strrchr ($ sharedWith , '@ ' ) : false ;
212+ if ($ remoteIdentifier !== false ) {
213+ $ remote = substr ($ remoteIdentifier , 1 );
214+
215+ if (isset ($ this ->trustedServerCache [$ remote ])) {
216+ $ result ['is_trusted_server ' ] = $ this ->trustedServerCache [$ remote ];
217+ } else {
218+ try {
219+ $ isTrusted = $ this ->trustedServers ->isTrustedServer ($ remote );
220+ $ this ->trustedServerCache [$ remote ] = $ isTrusted ;
221+ $ result ['is_trusted_server ' ] = $ isTrusted ;
222+ } catch (\Exception $ e ) {
223+ // Server not found or other issue, we consider it not trusted
224+ $ this ->trustedServerCache [$ remote ] = false ;
225+ $ this ->logger ->error (
226+ 'Error checking if remote server is trusted (treating as untrusted): ' . $ e ->getMessage (),
227+ ['exception ' => $ e ]
228+ );
229+ }
230+ }
231+ }
232+ }
233+
205234 $ expiration = $ share ->getExpirationDate ();
206235 if ($ expiration !== null ) {
207236 $ expiration ->setTimezone ($ this ->dateTimeZone ->getTimeZone ());
0 commit comments