1414use OC \Files \Storage \Wrapper \Wrapper ;
1515use OCA \Circles \Api \v1 \Circles ;
1616use OCA \Deck \Sharing \ShareAPIHelper ;
17+ use OCA \Federation \TrustedServers ;
1718use OCA \Files \Helper ;
1819use OCA \Files_Sharing \Exceptions \SharingRightsException ;
1920use OCA \Files_Sharing \External \Storage ;
7475class ShareAPIController extends OCSController {
7576
7677 private ?Node $ lockedNode = null ;
78+ private array $ trustedServerCache = [];
7779
7880 /**
7981 * Share20OCS constructor.
@@ -97,6 +99,7 @@ public function __construct(
9799 private IProviderFactory $ factory ,
98100 private IMailer $ mailer ,
99101 private ITagManager $ tagManager ,
102+ private ?TrustedServers $ trustedServers ,
100103 private ?string $ userId = null ,
101104 ) {
102105 parent ::__construct ($ appName , $ request );
@@ -199,6 +202,32 @@ protected function formatShare(IShare $share, ?Node $recipientNode = null): arra
199202 $ result ['item_size ' ] = $ node ->getSize ();
200203 $ result ['item_mtime ' ] = $ node ->getMTime ();
201204
205+ if ($ this ->trustedServers !== null && in_array ($ share ->getShareType (), [IShare::TYPE_REMOTE , IShare::TYPE_REMOTE_GROUP ], true )) {
206+ $ result ['is_trusted_server ' ] = false ;
207+ $ sharedWith = $ share ->getSharedWith ();
208+ $ remoteIdentifier = is_string ($ sharedWith ) ? strrchr ($ sharedWith , '@ ' ) : false ;
209+ if ($ remoteIdentifier !== false ) {
210+ $ remote = substr ($ remoteIdentifier , 1 );
211+
212+ if (isset ($ this ->trustedServerCache [$ remote ])) {
213+ $ result ['is_trusted_server ' ] = $ this ->trustedServerCache [$ remote ];
214+ } else {
215+ try {
216+ $ isTrusted = $ this ->trustedServers ->isTrustedServer ($ remote );
217+ $ this ->trustedServerCache [$ remote ] = $ isTrusted ;
218+ $ result ['is_trusted_server ' ] = $ isTrusted ;
219+ } catch (\Exception $ e ) {
220+ // Server not found or other issue, we consider it not trusted
221+ $ this ->trustedServerCache [$ remote ] = false ;
222+ $ this ->logger ->error (
223+ 'Error checking if remote server is trusted (treating as untrusted): ' . $ e ->getMessage (),
224+ ['exception ' => $ e ]
225+ );
226+ }
227+ }
228+ }
229+ }
230+
202231 $ expiration = $ share ->getExpirationDate ();
203232 if ($ expiration !== null ) {
204233 $ expiration ->setTimezone ($ this ->dateTimeZone ->getTimeZone ());
0 commit comments