Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Document device-limit route scope and fix web formatting

Neeraj Gupta8d20e8d04a8e
diff --git a/server/pkg/middleware/collection_link.go b/server/pkg/middleware/collection_link.go
index 57bbcc32b8..277c3e6278 100644
--- a/server/pkg/middleware/collection_link.go
+++ b/server/pkg/middleware/collection_link.go
@@ -200,6 +200,9 @@ func (m *CollectionLinkMiddleware) checkDeviceLimit(c *gin.Context, accessToken
}
func shouldCheckCollectionLinkDeviceLimit(reqPath string) bool {
+ // Device admission for public collections is intentionally tied to the two
+ // metadata endpoints used as the browser entry/refresh points. Other routes
+ // (download/upload/social) continue to use the already-admitted session.
return reqPath == "/public-collection/info" ||
reqPath == "/public-collection/diff"
}
diff --git a/server/pkg/middleware/file_link.go b/server/pkg/middleware/file_link.go
index ee67444d34..9508ce5fe4 100644
--- a/server/pkg/middleware/file_link.go
+++ b/server/pkg/middleware/file_link.go
@@ -45,7 +45,7 @@ func (m *FileLinkMiddleware) Authenticate(urlSanitizer func(_ *gin.Context) stri
clientIP := network.GetClientIP(c)
userAgent := c.GetHeader("User-Agent")
reqPath := urlSanitizer(c)
- shouldCheckDeviceLimit := reqPath == "/file-link/info"
+ shouldCheckDeviceLimit := shouldCheckFileLinkDeviceLimit(reqPath)
passwordValidated := false
cacheKey := computeHashKeyForList([]string{accessToken, clientIP, userAgent}, ":")
@@ -150,6 +150,12 @@ func (m *FileLinkMiddleware) checkDeviceLimit(c *gin.Context, accessToken string
return token, false, stacktrace.Propagate(err, "")
}
+func shouldCheckFileLinkDeviceLimit(reqPath string) bool {
+ // File-link admission is currently anchored to /file-link/info, which is the
+ // discovery endpoint clients call before fetching the actual blob.
+ return reqPath == "/file-link/info"
+}
+
func (m *FileLinkMiddleware) isDeviceLimitReached(ctx context.Context,
collectionSummary *ente.FileLinkRow, ip string, ua string) (bool, error) {
// skip deviceLimit check & record keeping for requests via CF worker
diff --git a/web/apps/albums/src/public-album/data/api/public-collection.ts b/web/apps/albums/src/public-album/data/api/public-collection.ts
index e91e4e6ce0..ed04dd6ba3 100644
--- a/web/apps/albums/src/public-album/data/api/public-collection.ts
+++ b/web/apps/albums/src/public-album/data/api/public-collection.ts
@@ -107,8 +107,11 @@ export const pullCollection = async (
referralCode: string;
linkDeviceToken?: string;
}> => {
- const { collection: remoteCollection, referralCode, linkDeviceToken } =
- await getPublicCollectionInfo(credentials);
+ const {
+ collection: remoteCollection,
+ referralCode,
+ linkDeviceToken,
+ } = await getPublicCollectionInfo(credentials);
const collection = await decryptRemoteCollection(
remoteCollection,
@@ -142,16 +145,15 @@ const PublicCollectionInfo = z.object({
*
* @param accessToken A public collection access key.
*/
-const getPublicCollectionInfo = async (credentials: PublicAlbumsCredentials) => {
+const getPublicCollectionInfo = async (
+ credentials: PublicAlbumsCredentials,
+) => {
const res = await fetch(await apiURL("/public-collection/info"), {
headers: authenticatedPublicAlbumsInfoRequestHeaders(credentials),
});
ensureOk(res);
const info = PublicCollectionInfo.parse(await res.json());
- return {
- ...info,
- linkDeviceToken: linkDeviceTokenFromResponse(res),
- };
+ return { ...info, linkDeviceToken: linkDeviceTokenFromResponse(res) };
};
/**
diff --git a/web/apps/embed/src/pages/index.tsx b/web/apps/embed/src/pages/index.tsx
index b01f7a1804..74bbc9b18b 100644
--- a/web/apps/embed/src/pages/index.tsx
+++ b/web/apps/embed/src/pages/index.tsx
@@ -27,9 +27,9 @@ import { EmbedPasswordForm } from "../components/EmbedPasswordForm";
import {
removePublicCollectionByKey,
savedPublicCollectionAccessTokenJWT,
- savedPublicCollectionLinkDeviceToken,
savedPublicCollectionByKey,
savedPublicCollectionFiles,
+ savedPublicCollectionLinkDeviceToken,
savePublicCollectionAccessTokenJWT,
savePublicCollectionLinkDeviceToken,
} from "../services/public-albums-storage";
diff --git a/web/apps/share/src/hooks/useCollectionShare.ts b/web/apps/share/src/hooks/useCollectionShare.ts
index 097d51cd06..54cda8751f 100644
--- a/web/apps/share/src/hooks/useCollectionShare.ts
+++ b/web/apps/share/src/hooks/useCollectionShare.ts
@@ -487,10 +487,7 @@ export const useCollectionShare = (): UseCollectionShareResult => {
setDownloadProgress(null);
try {
await downloadPublicCollectionFile(
- {
- accessToken,
- accessTokenJWT: accessTokenJWT ?? undefined,
- },
+ { accessToken, accessTokenJWT: accessTokenJWT ?? undefined },
item.id,
fileKey,
item.fileName,
diff --git a/web/apps/share/src/hooks/useFileShare.ts b/web/apps/share/src/hooks/useFileShare.ts
index 37289938c6..5602f1e957 100644
--- a/web/apps/share/src/hooks/useFileShare.ts
+++ b/web/apps/share/src/hooks/useFileShare.ts
@@ -1,5 +1,5 @@
-import type { NotificationAttributes } from "ente-new/photos/components/Notification";
import { apiOrigin } from "ente-base/origins";
+import type { NotificationAttributes } from "ente-new/photos/components/Notification";
import { useRouter } from "next/router";
import { useEffect, useState } from "react";
import {
@@ -94,7 +94,7 @@ export const useFileShare = (): UseFileShareResult => {
await fetchFileInfo(
token,
storedLinkDeviceToken ?? undefined,
- );
+ );
if (linkDeviceToken) {
saveLinkDeviceToken(
currentAPIOrigin,
diff --git a/web/apps/share/src/services/collection-share.ts b/web/apps/share/src/services/collection-share.ts
index 09b2232e35..2dc638f4ac 100644
--- a/web/apps/share/src/services/collection-share.ts
+++ b/web/apps/share/src/services/collection-share.ts
@@ -303,9 +303,7 @@ export const fetchPublicCollectionShareMetadata = async (
});
ensureOk(res);
- const data = (await res.json()) as {
- collection: unknown;
- };
+ const data = (await res.json()) as { collection: unknown };
const remoteCollection = RemoteCollection.parse(data.collection);
const collection = await decryptRemoteCollection(
remoteCollection,
diff --git a/web/apps/share/src/services/file-share.ts b/web/apps/share/src/services/file-share.ts
index fbaeb60d5a..a4ac3d5862 100644
--- a/web/apps/share/src/services/file-share.ts
+++ b/web/apps/share/src/services/file-share.ts
@@ -1,8 +1,4 @@
import bs58 from "bs58";
-import {
- linkDeviceTokenFromResponse,
- linkDeviceTokenRequestHeader,
-} from "ente-base/http";
import {
decryptBoxBytes,
decryptMetadataJSON,
@@ -11,6 +7,10 @@ import {
fromHex,
toB64,
} from "ente-base/crypto";
+import {
+ linkDeviceTokenFromResponse,
+ linkDeviceTokenRequestHeader,
+} from "ente-base/http";
import { apiOrigin } from "ente-base/origins";
import type {
DecryptedFileInfo,