Security fixes: swarm signature verification and error handling

This commit is contained in:
Clawd Deploy Bot
2026-01-30 16:50:49 +01:00
parent 495a037eb1
commit 50355b740a
21 changed files with 850 additions and 467 deletions
+3 -8
View File
@@ -21,7 +21,7 @@ interface ComposeProps {
}
export function Compose({ onPost, replyingTo, onCancelReply, placeholder = "What's happening?", isReply }: ComposeProps) {
const { isIdentityUnlocked, setShowUnlockPrompt } = useAuth();
const { isIdentityUnlocked } = useAuth();
const [content, setContent] = useState('');
const [isPosting, setIsPosting] = useState(false);
const [attachments, setAttachments] = useState<MediaAttachment[]>([]);
@@ -92,8 +92,9 @@ export function Compose({ onPost, replyingTo, onCancelReply, placeholder = "What
const handleSubmit = async () => {
if (!content.trim() || isPosting || isUploading) return;
// With persistence, identity should be unlocked. If not, user needs to re-login
if (!isIdentityUnlocked) {
setShowUnlockPrompt(true, () => handleSubmit());
alert('Your session has expired. Please log in again.');
return;
}
@@ -248,12 +249,6 @@ export function Compose({ onPost, replyingTo, onCancelReply, placeholder = "What
<label
className="compose-media-button"
title="Add media"
onClick={(e) => {
if (!isIdentityUnlocked) {
e.preventDefault();
setShowUnlockPrompt(true);
}
}}
>
{isUploading ? '...' : <ImageIcon size={20} />}
<input
+5 -9
View File
@@ -1,7 +1,6 @@
'use client';
import { Lock, Shield } from 'lucide-react';
import { useAuth } from '@/lib/contexts/AuthContext';
import { Lock } from 'lucide-react';
interface IdentityLockScreenProps {
title?: string;
@@ -10,12 +9,10 @@ interface IdentityLockScreenProps {
}
export function IdentityLockScreen({
title = 'Identity Required',
description = 'Accessing settings requires your identity to be unlocked. Your private keys are used to sign changes to prove they came from you.',
title = 'Session Expired',
description = 'Your session has expired. Please log in again to continue.',
icon
}: IdentityLockScreenProps) {
const { setShowUnlockPrompt } = useAuth();
return (
<div style={{
display: 'flex',
@@ -41,12 +38,11 @@ export function IdentityLockScreen({
</p>
<button
onClick={() => setShowUnlockPrompt(true)}
onClick={() => window.location.href = '/login'}
className="btn btn-primary"
style={{ display: 'flex', alignItems: 'center', gap: '8px' }}
>
<Shield size={16} />
Unlock Identity
Go to Login
</button>
</div>
);
+1 -9
View File
@@ -4,10 +4,9 @@ import { usePathname } from 'next/navigation';
import { Sidebar } from './Sidebar';
import { RightSidebar } from './RightSidebar';
import { useAuth } from '@/lib/contexts/AuthContext';
import { IdentityUnlockPrompt } from './IdentityUnlockPrompt';
export function LayoutWrapper({ children }: { children: React.ReactNode }) {
const { loading, showUnlockPrompt, setShowUnlockPrompt } = useAuth();
const { loading } = useAuth();
const pathname = usePathname();
// Paths that should NOT have the app layout
@@ -58,13 +57,6 @@ export function LayoutWrapper({ children }: { children: React.ReactNode }) {
</main>
{!hideRightSidebar && <RightSidebar />}
{/* Global Identity Unlock Prompt */}
{showUnlockPrompt && (
<IdentityUnlockPrompt
onUnlock={() => setShowUnlockPrompt(false)}
onCancel={() => setShowUnlockPrompt(false)}
/>
)}
</div>
);
}
+3 -3
View File
@@ -44,7 +44,7 @@ interface PostCardProps {
}
export function PostCard({ post, onLike, onRepost, onComment, onDelete, onHide, isDetail, showThread = true, isThreadParent, parentPostAuthorId }: PostCardProps) {
const { user: currentUser, did, handle: currentUserHandle, isIdentityUnlocked, setShowUnlockPrompt } = useAuth();
const { user: currentUser, did, handle: currentUserHandle, isIdentityUnlocked } = useAuth();
const { showToast } = useToast();
const router = useRouter();
const [liked, setLiked] = useState(post.isLiked || false);
@@ -91,7 +91,7 @@ export function PostCard({ post, onLike, onRepost, onComment, onDelete, onHide,
e.stopPropagation();
if (!isIdentityUnlocked) {
setShowUnlockPrompt(true, () => handleLike(e));
showToast('Please log in to like posts', 'error');
return;
}
@@ -105,7 +105,7 @@ export function PostCard({ post, onLike, onRepost, onComment, onDelete, onHide,
e.stopPropagation();
if (!isIdentityUnlocked) {
setShowUnlockPrompt(true, () => handleRepost(e));
showToast('Please log in to repost', 'error');
return;
}
+47 -63
View File
@@ -7,11 +7,11 @@ import { usePathname, useRouter } from 'next/navigation';
import { useAuth } from '@/lib/contexts/AuthContext';
import { HomeIcon, SearchIcon, BellIcon, UserIcon, ShieldIcon, SettingsIcon, BotIcon } from './Icons';
import { formatFullHandle } from '@/lib/utils/handle';
import { LogOut, Settings2, Lock, Unlock } from 'lucide-react';
import { LogOut, Settings2, Unlock } from 'lucide-react';
// import { IdentityUnlockPrompt } from './IdentityUnlockPrompt'; // Moved to LayoutWrapper
export function Sidebar() {
const { user, isAdmin, logout, isIdentityUnlocked, setShowUnlockPrompt } = useAuth();
const { user, isAdmin, logout, isIdentityUnlocked, lockIdentity } = useAuth();
const pathname = usePathname();
const router = useRouter();
const [customLogoUrl, setCustomLogoUrl] = useState<string | null | undefined>(undefined);
@@ -192,70 +192,54 @@ export function Sidebar() {
</div>
</div>
{/* Identity Status Indicator */}
<div
onClick={() => {
if (!isIdentityUnlocked) {
setShowUnlockPrompt(true);
}
}}
title={isIdentityUnlocked ? 'Identity unlocked - you can perform actions' : 'Identity locked - click to unlock'}
style={{
display: 'flex',
alignItems: 'center',
gap: '8px',
padding: '10px 12px',
marginBottom: '12px',
borderRadius: '8px',
background: isIdentityUnlocked
? 'rgba(34, 197, 94, 0.1)'
: 'rgba(251, 191, 36, 0.1)',
border: isIdentityUnlocked
? '1px solid rgba(34, 197, 94, 0.2)'
: '1px solid rgba(251, 191, 36, 0.2)',
cursor: isIdentityUnlocked ? 'default' : 'pointer',
transition: 'all 0.2s',
}}
onMouseEnter={(e) => {
if (!isIdentityUnlocked) {
e.currentTarget.style.background = 'rgba(251, 191, 36, 0.15)';
}
}}
onMouseLeave={(e) => {
if (!isIdentityUnlocked) {
e.currentTarget.style.background = 'rgba(251, 191, 36, 0.1)';
}
}}
>
{isIdentityUnlocked ? (
{/* Identity Status - Only show when unlocked with option to lock */}
{isIdentityUnlocked && (
<div
onClick={() => lockIdentity()}
title="Click to lock your identity"
style={{
display: 'flex',
alignItems: 'center',
gap: '8px',
padding: '10px 12px',
marginBottom: '12px',
borderRadius: '8px',
background: 'rgba(34, 197, 94, 0.1)',
border: '1px solid rgba(34, 197, 94, 0.2)',
cursor: 'pointer',
transition: 'all 0.2s',
}}
onMouseEnter={(e) => {
e.currentTarget.style.background = 'rgba(34, 197, 94, 0.15)';
}}
onMouseLeave={(e) => {
e.currentTarget.style.background = 'rgba(34, 197, 94, 0.1)';
}}
>
<Unlock size={16} style={{ color: 'rgb(34, 197, 94)', flexShrink: 0 }} />
) : (
<Lock size={16} style={{ color: 'rgb(251, 191, 36)', flexShrink: 0 }} />
)}
<div style={{ flex: 1, minWidth: 0 }}>
<div style={{
fontSize: '13px',
fontWeight: 500,
color: isIdentityUnlocked ? 'rgb(34, 197, 94)' : 'rgb(251, 191, 36)',
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap'
}}>
{isIdentityUnlocked ? 'Identity Unlocked' : 'Identity Locked'}
</div>
<div style={{
fontSize: '11px',
color: 'var(--foreground-tertiary)',
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap'
}}>
{isIdentityUnlocked
? 'You can perform actions'
: 'Click to unlock'}
<div style={{ flex: 1, minWidth: 0 }}>
<div style={{
fontSize: '13px',
fontWeight: 500,
color: 'rgb(34, 197, 94)',
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap'
}}>
Identity Unlocked
</div>
<div style={{
fontSize: '11px',
color: 'var(--foreground-tertiary)',
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap'
}}>
Click to lock
</div>
</div>
</div>
</div>
)}
<button
onClick={handleLogout}