BlogMedia
← Back to Blog
September 11, 20262 views

Dead Man's Switch: Securing Your Digital Legacy

Secure sensitive data and automate alerts if you go offline. Implement dead man's switch with practical examples for developers and teams.

Apa Itu Dead Man's Switch?

Dead man's switch adalah mekanisme yang otomatis trigger aksi jika kamu tidak memberikan sinyal dalam periode tertentu. Konsepnya simple: kamu harus "checkin" secara berkala, kalau tidak, sistem akan execute predefined actions.

Untuk developer dan tim, ini berguna untuk:

Secure sensitive data (reset credentials, revoke access)
Alert emergency contacts jika sesuatu terjadi
Automate disaster recovery procedures
Ensure business continuity

Real Use Cases

Developer solo: Backup encryption keys ke trusted contact jika offline 30 hari
Startup: Immediate access revocation untuk ex-employees jika system tidak di-checkin
Security team: Auto-escalate alerts jika monitoring system down

Implementasi Simple dengan Node.js

Berikut setup dasar dead man's switch menggunakan Node.js dan database:

import { CronJob } from 'cron';
import { db } from './db';

interface DeadMansSwitch {
  id: string;
  userId: string;
  lastCheckin: Date;
  interval: number; // milliseconds
  actions: string[]; // what to do when triggered
}

async function checkDeadMansSwitches() {
  const switches = await db.deadMansSwitches.find({ active: true });
  const now = new Date();

  for (const dms of switches) {
    const timeSinceCheckin = now.getTime() - dms.lastCheckin.getTime();
    
    if (timeSinceCheckin > dms.interval) {
      console.log(`Dead man's switch triggered for user ${dms.userId}`);
      await executeActions(dms);
      await db.deadMansSwitches.updateOne(
        { id: dms.id },
        { active: false }
      );
    }
  }
}

async function executeActions(dms: DeadMansSwitch) {
  for (const action of dms.actions) {
    if (action === 'revoke-access') {
      await revokeUserAccess(dms.userId);
    }
    if (action === 'notify-emergency') {
      await notifyEmergencyContacts(dms.userId);
    }
    if (action === 'backup-secrets') {
      await backupSecretsToTrustedContact(dms.userId);
    }
  }
}

// Run check every hour
new CronJob('0 * * * *', checkDeadMansSwitches).start();

Checkin Endpoint

User perlu checkin secara berkala untuk reset timer:

app.post('/api/checkin', async (req, res) => {
  const { userId } = req.body;
  
  const result = await db.deadMansSwitches.updateOne(
    { userId, active: true },
    { lastCheckin: new Date() }
  );
  
  if (result.modifiedCount === 0) {
    return res.status(404).json({ error: 'No active switch found' });
  }
  
  res.json({ success: true, checkedInAt: new Date() });
});

Setup Dead Man's Switch

Create switch untuk user:

async function createDeadMansSwitch(userId: string, options: {
  intervalDays: number;
  actions: string[];
  emergencyContact?: string;
}) {
  const dms = {
    id: crypto.randomUUID(),
    userId,
    lastCheckin: new Date(),
    interval: options.intervalDays * 24 * 60 * 60 * 1000,
    actions: options.actions,
    emergencyContact: options.emergencyContact,
    active: true,
    createdAt: new Date()
  };
  
  await db.deadMansSwitches.insertOne(dms);
  return dms;
}

// Usage
await createDeadMansSwitch('user-123', {
  intervalDays: 30,
  actions: ['notify-emergency', 'backup-secrets'],
  emergencyContact: '[email protected]'
});

Security Considerations

Encryption: Jangan store sensitive data di database tanpa encryption
Audit logging: Log semua checkins dan trigger events
Verification: Require confirmation sebelum execute destructive actions
Failsafe: Always have manual override untuk trusted admins

Kapan Perlu Dead Man's Switch

Solo developer dengan akses admin critical system
Team dengan sensitive data yang perlu immediate revocation
Business continuity planning untuk contingency scenarios
Security protocol untuk automated responses

Kesimpulan

Dead man's switch adalah tool powerful untuk automate critical actions based on inactivity. Simple implementation bisa protect sensitive data dan ensure team security.

Kalau kamu manage critical systems atau sensitive data, consider adding basic dead man's switch ke infrastructure kamu. Bukan hanya security measure, tapi peace of mind juga.