Skip to content

armgit / ente

Public Imported from GitHub
0

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

Refine paste UI surfaces and link reveal behavior

Manav Rathi1ee2ef0570ee
diff --git a/server/ente/paste.go b/server/ente/paste.go
index 78334efde5..6e64a1cef3 100644
--- a/server/ente/paste.go
+++ b/server/ente/paste.go
@@ -1,10 +1,18 @@
package ente
import (
+ "encoding/base64"
"strings"
"unicode"
)
+const (
+ pasteKdfSaltBytes = 16
+ pasteKdfNonceMaxLength = 64
+ pasteKdfMemLimitInteractive = 64 * 1024 * 1024
+ pasteKdfOpsLimitInteractive = 2
+)
+
type CreatePasteRequest struct {
EncryptedData string `json:"encryptedData" binding:"required"`
DecryptionHeader string `json:"decryptionHeader" binding:"required"`
@@ -31,7 +39,18 @@ func (r *CreatePasteRequest) Validate(maxCiphertextBytes int) error {
if len(r.EncryptedPasteKey) > maxCiphertextBytes || len(r.EncryptedPasteKeyNonce) > maxCiphertextBytes {
return NewBadRequestWithMessage("key material too large")
}
- if r.KdfMemLimit <= 0 || r.KdfOpsLimit <= 0 {
+ if len(r.KdfNonce) > pasteKdfNonceMaxLength {
+ return NewBadRequestWithMessage("invalid key derivation parameters")
+ }
+ kdfNonce, err := base64.StdEncoding.DecodeString(r.KdfNonce)
+ if err != nil {
+ kdfNonce, err = base64.RawStdEncoding.DecodeString(r.KdfNonce)
+ }
+ if err != nil || len(kdfNonce) != pasteKdfSaltBytes {
+ return NewBadRequestWithMessage("invalid key derivation parameters")
+ }
+ if r.KdfMemLimit != pasteKdfMemLimitInteractive ||
+ r.KdfOpsLimit != pasteKdfOpsLimitInteractive {
return NewBadRequestWithMessage("invalid key derivation parameters")
}
return nil
diff --git a/server/ente/paste_test.go b/server/ente/paste_test.go
new file mode 100644
index 0000000000..d1b571730e
--- /dev/null
+++ b/server/ente/paste_test.go
@@ -0,0 +1,63 @@
+package ente
+
+import (
+ "encoding/base64"
+ "strings"
+ "testing"
+)
+
+func newValidPasteRequest() CreatePasteRequest {
+ return CreatePasteRequest{
+ EncryptedData: "encrypted-data",
+ DecryptionHeader: "decryption-header",
+ EncryptedPasteKey: "encrypted-paste-key",
+ EncryptedPasteKeyNonce: "encrypted-paste-key-nonce",
+ KdfNonce: base64.StdEncoding.EncodeToString(make([]byte, pasteKdfSaltBytes)),
+ KdfMemLimit: pasteKdfMemLimitInteractive,
+ KdfOpsLimit: pasteKdfOpsLimitInteractive,
+ }
+}
+
+func TestCreatePasteRequestValidate_Valid(t *testing.T) {
+ req := newValidPasteRequest()
+ if err := req.Validate(1024); err != nil {
+ t.Fatalf("expected valid request, got error: %v", err)
+ }
+}
+
+func TestCreatePasteRequestValidate_RejectsOversizedKdfNonce(t *testing.T) {
+ req := newValidPasteRequest()
+ req.KdfNonce = strings.Repeat("a", pasteKdfNonceMaxLength+1)
+
+ if err := req.Validate(1024); err == nil {
+ t.Fatal("expected oversized kdf nonce to be rejected")
+ }
+}
+
+func TestCreatePasteRequestValidate_RejectsInvalidKdfNonceEncoding(t *testing.T) {
+ req := newValidPasteRequest()
+ req.KdfNonce = "not-base64@@@"
+
+ if err := req.Validate(1024); err == nil {
+ t.Fatal("expected invalid kdf nonce encoding to be rejected")
+ }
+}
+
+func TestCreatePasteRequestValidate_RejectsUnexpectedKdfNonceLength(t *testing.T) {
+ req := newValidPasteRequest()
+ req.KdfNonce = base64.StdEncoding.EncodeToString(make([]byte, 8))
+
+ if err := req.Validate(1024); err == nil {
+ t.Fatal("expected invalid kdf nonce length to be rejected")
+ }
+}
+
+func TestCreatePasteRequestValidate_RejectsInvalidKdfCostParams(t *testing.T) {
+ req := newValidPasteRequest()
+ req.KdfMemLimit = pasteKdfMemLimitInteractive * 2
+ req.KdfOpsLimit = pasteKdfOpsLimitInteractive * 2
+
+ if err := req.Validate(1024); err == nil {
+ t.Fatal("expected invalid kdf cost params to be rejected")
+ }
+}
diff --git a/web/apps/paste/src/pages/index.tsx b/web/apps/paste/src/pages/index.tsx
index 61bd2116e6..26ea57e93c 100644
--- a/web/apps/paste/src/pages/index.tsx
+++ b/web/apps/paste/src/pages/index.tsx
@@ -7,7 +7,7 @@ import {
TextField,
Typography,
} from "@mui/material";
-import { EnteLogo, EnteLogoBox } from "ente-base/components/EnteLogo";
+import { EnteLogo } from "ente-base/components/EnteLogo";
import {
decryptBox,
decryptMetadataJSON,
@@ -48,19 +48,47 @@ const waitUntilVisible = () =>
document.addEventListener("visibilitychange", onVisible);
});
-const textFieldSx = {
- "& .MuiOutlinedInput-root.MuiInputBase-multiline": {
- borderRadius: "16px",
- bgcolor: "background.paper2",
+const textFieldSx = (
+ radius = "16px",
+ bgColor = "background.paper2",
+ borderColor = "stroke.faint",
+) => ({
+ margin: 0,
+ "& .MuiFilledInput-root": {
+ borderRadius: radius,
+ bgcolor: bgColor,
+ border: "1px solid",
+ borderColor,
alignItems: "flex-start",
- paddingTop: "10px",
- paddingBottom: "10px",
+ boxSizing: "border-box",
+ padding: "10px 12px",
+ "&:before": { display: "none" },
+ "&:after": { display: "none" },
+ "&:hover:not(.Mui-disabled, .Mui-error):before": { display: "none" },
+ "&:hover": {
+ bgcolor: bgColor,
+ },
+ "&.Mui-focused": {
+ bgcolor: bgColor,
+ borderColor: "accent.main",
+ },
+ },
+ "& .MuiInputBase-input": {
+ padding: "0 !important",
},
"& .MuiInputBase-inputMultiline": {
- paddingTop: "0 !important",
- paddingBottom: "0 !important",
+ padding: "0 !important",
+ margin: "0 !important",
},
-};
+ "& .MuiFilledInput-inputMultiline": {
+ padding: "0 !important",
+ margin: "0 !important",
+ },
+ "& textarea": {
+ padding: "0 !important",
+ margin: "0 !important",
+ },
+});
const createFragmentSecret = () => newID("").slice(0, fragmentSecretLength);
@@ -100,6 +128,7 @@ const Page: React.FC = () => {
const [resolvedText, setResolvedText] = useState<string | null>(null);
const startedConsumeRef = useRef(false);
+ const createdLinkRef = useRef<HTMLDivElement | null>(null);
useEffect(() => {
const cleanPath = window.location.pathname.replace(/^\/+|\/+$/g, "");
@@ -157,6 +186,26 @@ const Page: React.FC = () => {
void run();
}, [mode, accessToken]);
+ useEffect(() => {
+ if (!createdLink || mode !== "create") return;
+ const linkCard = createdLinkRef.current;
+ if (!linkCard) return;
+
+ const rect = linkCard.getBoundingClientRect();
+ const viewportHeight =
+ window.innerHeight || document.documentElement.clientHeight;
+ const isOutOfViewport = rect.top < 0 || rect.bottom > viewportHeight;
+ if (!isOutOfViewport) return;
+
+ const reduceMotion = window.matchMedia(
+ "(prefers-reduced-motion: reduce)",
+ ).matches;
+ linkCard.scrollIntoView({
+ behavior: reduceMotion ? "auto" : "smooth",
+ block: "start",
+ });
+ }, [createdLink, mode]);
+
const handleCreate = async () => {
setCreateError(null);
if (!inputText.trim()) {
@@ -237,12 +286,13 @@ const Page: React.FC = () => {
xs: "calc(100dvh - 16px)",
md: "calc(100dvh - 48px)",
},
+ flex: 1,
width: "100%",
bgcolor: "background.default",
borderRadius: { xs: "20px", md: "40px" },
- display: "flex",
- flexDirection: "column",
- alignItems: "center",
+ display: "grid",
+ gridTemplateRows: "1fr auto",
+ alignItems: "stretch",
"& ::selection": {
backgroundColor: "accent.main",
color: "fixed.white",
@@ -253,43 +303,14 @@ const Page: React.FC = () => {
},
}}
>
- <Box
- sx={{
- mt: { xs: 4, md: 5 },
- alignSelf: { xs: "center", md: "flex-end" },
- mr: { xs: 0, md: 6 },
- }}
- >
- <a
- href="https://ente.io"
- target="_blank"
- rel="noopener noreferrer"
- style={{
- display: "block",
- lineHeight: 0,
- color: "inherit",
- textDecoration: "none",
- }}
- >
- <EnteLogoBox
- sx={{
- color: "accent.main",
- "& svg": { color: "accent.main" },
- "& svg path": { fill: "accent.main" },
- }}
- >
- <EnteLogo height={28} />
- </EnteLogoBox>
- </a>
- </Box>
-
<Box
sx={{
width: "100%",
maxWidth: 760,
+ mx: "auto",
px: { xs: 3, md: 5 },
- pb: { xs: 5, md: 7 },
- mt: { xs: 3, md: 4 },
+ pb: { xs: 2, md: 2.5 },
+ mt: { xs: 4, md: 5 },
}}
>
<Stack spacing={2.5}>
@@ -312,11 +333,34 @@ const Page: React.FC = () => {
<Chip variant="outlined" label="24 hour retention max" />
<Chip variant="outlined" label="One-time view" />
<Chip variant="outlined" label="Purged after open" />
+ <Chip
+ variant="filled"
+ label="Open source"
+ component="a"
+ href="https://github.com/ente-io/ente"
+ target="_blank"
+ rel="noopener"
+ clickable
+ sx={{
+ textDecoration: "none",
+ bgcolor: "accent.main",
+ color: "fixed.white",
+ border: "1px solid",
+ borderColor: "accent.main",
+ "&:hover": {
+ bgcolor: "accent.dark",
+ borderColor: "accent.dark",
+ },
+ }}
+ />
</Stack>
{mode === "create" && (
<>
<TextField
+ variant="filled"
+ hiddenLabel
+ InputProps={{ disableUnderline: true }}
multiline
minRows={10}
placeholder="Paste text (keys, snippets, notes, instructions...)"
@@ -325,7 +369,7 @@ const Page: React.FC = () => {
setInputText(e.target.value)
}
inputProps={{ maxLength: maxChars }}
- sx={textFieldSx}
+ sx={textFieldSx()}
/>
<Box
sx={{
@@ -363,47 +407,38 @@ const Page: React.FC = () => {
{createdLink && (
<Stack
+ ref={createdLinkRef}
spacing={2}
sx={{
p: 2.5,
borderRadius: "20px",
- bgcolor: "background.paper2",
+ bgcolor: "background.paper",
border: "1px solid",
- borderColor: "stroke.faint",
+ borderColor: "stroke.muted",
+ scrollMarginTop: {
+ xs: "16px",
+ md: "24px",
+ },
}}
>
<Typography sx={{ fontWeight: 600 }}>
Your one-time link
</Typography>
<TextField
+ variant="filled"
+ hiddenLabel
value={createdLink}
multiline
minRows={2}
- InputProps={{ readOnly: true }}
- sx={{
- "& .MuiOutlinedInput-root.MuiInputBase-multiline":
- {
- borderRadius: "12px",
- bgcolor:
- "background.default",
- alignItems:
- "flex-start",
- paddingTop: "10px",
- paddingBottom:
- "10px",
- },
- "& .MuiInputBase-inputMultiline":
- {
- paddingTop:
- "0 !important",
- paddingBottom:
- "0 !important",
- },
- "& .MuiOutlinedInput-root": {
- borderRadius: "12px",
- bgcolor: "background.default",
- },
+ InputProps={{
+ readOnly: true,
+ disableUnderline: true,
}}
+ sx={textFieldSx(
+ "12px",
+ "background.default",
+ "stroke.muted",
+ )}
/>
<Stack
direction={{ xs: "column", sm: "row" }}
@@ -451,7 +486,23 @@ const Page: React.FC = () => {
</Stack>
)}
{consumeError && (
- <Typography color="error">{consumeError}</Typography>
+ <Stack spacing={1.5} alignItems="flex-start">
+ <Typography color="error">
+ {consumeError}
+ </Typography>
+ <Button
+ variant="outlined"
+ component="a"
+ href="/"
+ sx={{
+ mt: 0.75,
+ textTransform: "none",
+ borderRadius: "12px",
+ }}
+ >
+ Create new paste
+ </Button>
+ </Stack>
)}
{resolvedText && (
<Stack spacing={2}>
@@ -459,12 +510,21 @@ const Page: React.FC = () => {
Paste contents
</Typography>
<TextField
+ variant="filled"
+ hiddenLabel
multiline
minRows={10}
value={resolvedText}
- InputProps={{ readOnly: true }}
- sx={textFieldSx}
+ InputProps={{
+ readOnly: true,
+ disableUnderline: true,
+ }}
+ sx={textFieldSx()}
/>
+ <Typography variant="mini" color="text.muted">
+ This paste has now been removed from Ente
+ servers.
+ </Typography>
<Button
variant="outlined"
onClick={() => copyText(resolvedText)}
@@ -476,16 +536,83 @@ const Page: React.FC = () => {
>
Copy text
</Button>
- <Typography variant="mini" color="text.muted">
- This paste has now been removed from Ente
- servers.
- </Typography>
</Stack>
)}
</>
)}
</Stack>
</Box>
+ <Box
+ sx={{
+ width: "100%",
+ maxWidth: 760,
+ mx: "auto",
+ px: { xs: 3, md: 5 },
+ pt: { xs: 2, md: 2.5 },
+ pb: { xs: 3, md: 3.5 },
+ }}
+ >
+ <Stack spacing={1.25} alignItems="center">
+ <a
+ href="https://ente.io"
+ target="_blank"
+ rel="noopener"
+ style={{
+ display: "block",
+ lineHeight: 0,
+ color: "inherit",
+ textDecoration: "none",
+ }}
+ >
+ <Box
+ sx={{
+ color: "accent.main",
+ "& svg": { color: "accent.main" },
+ "& svg path": { fill: "accent.main" },
+ }}
+ >
+ <EnteLogo height={20} />
+ </Box>
+ </a>
+ <Typography variant="mini" color="text.muted">
+ <a
+ href="https://ente.io/photos"
+ target="_blank"
+ rel="noopener"
+ style={{
+ color: "inherit",
+ textDecoration: "none",
+ }}
+ >
+ Photos
+ </a>{" "}
+ {"\u2022"}{" "}
+ <a
+ href="https://ente.io/locker"
+ target="_blank"
+ rel="noopener"
+ style={{
+ color: "inherit",
+ textDecoration: "none",
+ }}
+ >
+ Documents
+ </a>{" "}
+ {"\u2022"}{" "}
+ <a
+ href="https://ente.io/auth"
+ target="_blank"
+ rel="noopener"
+ style={{
+ color: "inherit",
+ textDecoration: "none",
+ }}
+ >
+ Auth Codes
+ </a>
+ </Typography>
+ </Stack>
+ </Box>
</Box>
</Box>
</>
diff --git a/web/apps/paste/src/services/paste.ts b/web/apps/paste/src/services/paste.ts
index d430e9c99a..5b99f24ca0 100644
--- a/web/apps/paste/src/services/paste.ts
+++ b/web/apps/paste/src/services/paste.ts
@@ -15,8 +15,14 @@ export interface PastePayload {
kdfOpsLimit: number;
}
-const parseError = async (response: Response) => {
- if (response.status === 410 || response.status === 404) {
+const parseError = async (
+ response: Response,
+ context: "create" | "guard" | "consume",
+) => {
+ if (
+ (context === "consume" || context === "guard") &&
+ (response.status === 410 || response.status === 404)
+ ) {
return "This paste has expired or was already opened.";
}
try {
@@ -35,7 +41,7 @@ export const createPaste = async (payload: PastePayload) => {
body: JSON.stringify(payload),
});
if (!response.ok) {
- throw new Error(await parseError(response));
+ throw new Error(await parseError(response, "create"));
}
return (await response.json()) as CreatePasteResponse;
};
@@ -48,7 +54,7 @@ export const setGuard = async (accessToken: string) => {
body: JSON.stringify({ accessToken }),
});
if (!response.ok) {
- throw new Error(await parseError(response));
+ throw new Error(await parseError(response, "guard"));
}
};
@@ -63,7 +69,7 @@ export const consumePaste = async (accessToken: string) => {
body: JSON.stringify({ accessToken }),
});
if (!response.ok) {
- throw new Error(await parseError(response));
+ throw new Error(await parseError(response, "consume"));
}
return (await response.json()) as PastePayload;
};