Skip to content

armgit / ente

Public Imported from GitHub
0

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

[API] Remove trailing slash from inconsistent cast endpoints

Manav Rathi7be9963303ba
diff --git a/mobile/lib/gateways/cast_gw.dart b/mobile/lib/gateways/cast_gw.dart
index 63735d6782..bc8af897ab 100644
--- a/mobile/lib/gateways/cast_gw.dart
+++ b/mobile/lib/gateways/cast_gw.dart
@@ -32,7 +32,7 @@ class CastGateway {
String castToken,
) {
return _enteDio.post(
- "/cast/cast-data/",
+ "/cast/cast-data",
data: {
"deviceCode": code,
"encPayload": castPayload,
@@ -45,7 +45,7 @@ class CastGateway {
Future<void> revokeAllTokens() async {
try {
await _enteDio.delete(
- "/cast/revoke-all-tokens/",
+ "/cast/revoke-all-tokens",
);
} catch (e) {
// swallow error
diff --git a/server/cmd/museum/main.go b/server/cmd/museum/main.go
index 0424f0065d..ed7d9027bb 100644
--- a/server/cmd/museum/main.go
+++ b/server/cmd/museum/main.go
@@ -566,10 +566,21 @@ func main() {
Ctrl: castCtrl,
}
+ publicAPI.POST("/cast/device-info", castHandler.RegisterDevice)
+ // Deprecated Nov 2024. Remove in a few months.
+ //
+ // This (and below) are deprecated copy of endpoints with a trailing slash.
+ // Kept around because existing desktop clients will not follow the 307
+ // redirect because of CORS headers missing on the 307. Can be safely
+ // removed in a few months after the desktop apps have updated.
publicAPI.POST("/cast/device-info/", castHandler.RegisterDevice)
privateAPI.GET("/cast/device-info/:deviceCode", castHandler.GetDeviceInfo)
publicAPI.GET("/cast/cast-data/:deviceCode", castHandler.GetCastData)
+ privateAPI.POST("/cast/cast-data", castHandler.InsertCastData)
+ // Deprecated Nov 2024. Remove in a few months.
privateAPI.POST("/cast/cast-data/", castHandler.InsertCastData)
+ privateAPI.DELETE("/cast/revoke-all-tokens", castHandler.RevokeAllToken)
+ // Deprecated Nov 2024. Remove in a few months.
privateAPI.DELETE("/cast/revoke-all-tokens/", castHandler.RevokeAllToken)
castAPI.GET("/files/preview/:fileID", castHandler.GetThumbnail)
diff --git a/server/pkg/middleware/rate_limit.go b/server/pkg/middleware/rate_limit.go
index 076c050c9f..9bbf056baa 100644
--- a/server/pkg/middleware/rate_limit.go
+++ b/server/pkg/middleware/rate_limit.go
@@ -150,6 +150,7 @@ func (r *RateLimitMiddleware) getLimiter(reqPath string, reqMethod string) *limi
reqPath == "/public-collection/verify-password" ||
reqPath == "/family/accept-invite" ||
reqPath == "/users/srp/attributes" ||
+ (reqPath == "/cast/device-info" && reqMethod == "POST") ||
(reqPath == "/cast/device-info/" && reqMethod == "POST") ||
reqPath == "/users/srp/verify-session" ||
reqPath == "/family/invite-info/:token" ||
diff --git a/web/apps/cast/src/services/pair.ts b/web/apps/cast/src/services/pair.ts
index 613bce6aa0..e10e6ab5ed 100644
--- a/web/apps/cast/src/services/pair.ts
+++ b/web/apps/cast/src/services/pair.ts
@@ -107,7 +107,7 @@ export const register = async (): Promise<Registration> => {
* @returns A device code that can be used to pair with us.
*/
const registerDevice = async (publicKey: string) => {
- const res = await fetch(await apiURL("/cast/device-info/"), {
+ const res = await fetch(await apiURL("/cast/device-info"), {
method: "POST",
headers: publicRequestHeaders(),
body: JSON.stringify({
diff --git a/web/packages/shared/network/cast.ts b/web/packages/shared/network/cast.ts
index 3c45b0aec3..6edb852418 100644
--- a/web/packages/shared/network/cast.ts
+++ b/web/packages/shared/network/cast.ts
@@ -22,7 +22,7 @@ class CastGateway {
try {
const token = getToken();
await HTTPService.delete(
- await apiURL("/cast/revoke-all-tokens/"),
+ await apiURL("/cast/revoke-all-tokens"),
undefined,
undefined,
{
@@ -64,7 +64,7 @@ class CastGateway {
) {
const token = getToken();
await HTTPService.post(
- await apiURL("/cast/cast-data/"),
+ await apiURL("/cast/cast-data"),
{
// eslint-disable-next-line @typescript-eslint/no-unnecessary-template-expression
deviceCode: `${code}`,