Skip to content

devsharmagit/secrettunnel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

62 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

SecretTunnel πŸ”

Zero-knowledge .env secret sharing for developers. Secrets are encrypted in your browser before they ever leave your machine β€” the server stores only ciphertext.

MIT License TypeScript Next.js Turbo Redis


🎯 The Problem

When collaborating on a codebase, sharing .env files over WhatsApp, Discord, or email is common β€” and dangerous. Those messages live in logs, backups, and screenshots forever.

SecretTunnel fixes this. Paste your secrets β†’ get a one-time link β†’ share it β†’ link self-destructs after first view.


✨ How It Works

Browser (yours)                 Server                   Browser (theirs)
──────────────────────────────────────────────────────────────────────────
Paste .env content
        β”‚
AES-256-GCM encrypt              
(Web Crypto API)                
        β”‚
POST /api/secrets ───────► Store ciphertext in Redis ◄── GET /api/secrets/:token
                             (with TTL + burn flag)          β”‚
        β”‚                                             Decrypt in browser
Receive token + key ◄────── Return token                     β”‚
        β”‚                                             Plaintext shown once
Share link with key                                          β”‚
(key never hits server)                               Redis entry deleted

The encryption key lives only in the URL fragment (#key=...). Fragments are never sent to the server. The server is provably blind to your plaintext.


πŸš€ Features

  • πŸ” Client-side AES-256-GCM encryption via Web Crypto API
  • πŸ”₯ Burn after read β€” secret deleted from Redis on first view
  • ⏱️ Configurable TTL β€” from minutes to weeks
  • πŸ”‘ Optional password protection β€” adds a second decryption layer
  • 🌐 Web UI β€” intuitive interface for sharing secrets
  • πŸ’» CLI tool β€” secrettnl command-line interface for automation
  • πŸ“Š Audit logging β€” track who viewed your secrets
  • πŸ”— Webhook notifications β€” get notified when secrets are accessed
  • πŸ”„ Versioned secrets β€” manage multiple versions of secret groups
  • πŸ‘€ User authentication β€” GitHub OAuth and credential-based auth
  • 🎨 Modern UI β€” built with shadcn/ui and Tailwind CSS

πŸ“¦ Tech Stack

Core Framework

Frontend

Backend & Database

Authentication

  • NextAuth.js β€” Authentication library
  • GitHub OAuth β€” Social login
  • Credential-based auth β€” Email/password authentication
  • Password hashing β€” scrypt with salt for secure storage

Infrastructure & Services

Development Tools

  • ESLint β€” Code linting
  • Prettier β€” Code formatting
  • tsup β€” TypeScript bundler

πŸ“ Project Structure

secrettunnel/
β”œβ”€β”€ apps/                          # Applications
β”‚   β”œβ”€β”€ cli/                       # Command-line interface
β”‚   β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”‚   β”œβ”€β”€ index.ts           # CLI entry point
β”‚   β”‚   β”‚   β”œβ”€β”€ push.ts            # Push (create secret) command
β”‚   β”‚   β”‚   β”œβ”€β”€ pull.ts            # Pull (read secret) command
β”‚   β”‚   β”‚   β”œβ”€β”€ config.ts          # Configuration
β”‚   β”‚   β”‚   β”œβ”€β”€ type.ts            # TypeScript types
β”‚   β”‚   β”‚   └── utils.ts           # Shared utilities
β”‚   β”‚   β”œβ”€β”€ package.json
β”‚   β”‚   β”œβ”€β”€ tsconfig.json
β”‚   β”‚   └── tsup.config.ts
β”‚   β”‚
β”‚   └── web/                       # Next.js web application
β”‚       β”œβ”€β”€ src/
β”‚       β”‚   β”œβ”€β”€ app/               # App router (Next.js)
β”‚       β”‚   β”‚   β”œβ”€β”€ api/           # API routes
β”‚       β”‚   β”‚   β”‚   β”œβ”€β”€ audit/     # Audit log endpoint
β”‚       β”‚   β”‚   β”‚   β”œβ”€β”€ auth/      # NextAuth.js routes
β”‚       β”‚   β”‚   β”‚   β”œβ”€β”€ secrets/   # Secret CRUD endpoints
β”‚       β”‚   β”‚   β”‚   β”œβ”€β”€ test/      # Test endpoint
β”‚       β”‚   β”‚   β”‚   β”œβ”€β”€ versioned-secrets/  # Versioned secrets API
β”‚       β”‚   β”‚   β”‚   └── webhooks/  # Webhook delivery
β”‚       β”‚   β”‚   β”œβ”€β”€ dashboard/     # Dashboard page
β”‚       β”‚   β”‚   β”œβ”€β”€ signin/        # Sign-in page
β”‚       β”‚   β”‚   β”œβ”€β”€ signup/        # Sign-up page
β”‚       β”‚   β”‚   β”œβ”€β”€ s/             # Public secret view page
β”‚       β”‚   β”‚   └── vs/            # Versioned secrets view
β”‚       β”‚   β”œβ”€β”€ components/        # React components
β”‚       β”‚   β”‚   β”œβ”€β”€ auth/          # Auth components (forms, buttons)
β”‚       β”‚   β”‚   β”œβ”€β”€ ui/            # shadcn/ui components
β”‚       β”‚   β”‚   β”œβ”€β”€ AppHeader.tsx  # Navigation header
β”‚       β”‚   β”‚   β”œβ”€β”€ SecretForm.tsx # Secret creation form
β”‚       β”‚   β”‚   β”œβ”€β”€ SecretViewer.tsx
β”‚       β”‚   β”‚   β”œβ”€β”€ AuditTable.tsx # Audit log display
β”‚       β”‚   β”‚   └── VersionedSecretsSection.tsx
β”‚       β”‚   β”œβ”€β”€ lib/               # Server/shared utilities
β”‚       β”‚   β”‚   β”œβ”€β”€ auth.ts        # NextAuth configuration
β”‚       β”‚   β”‚   β”œβ”€β”€ prisma.ts      # Prisma client
β”‚       β”‚   β”‚   β”œβ”€β”€ password.ts    # Password hashing
β”‚       β”‚   β”‚   β”œβ”€β”€ redis.ts       # Redis client
β”‚       β”‚   β”‚   β”œβ”€β”€ rate-limit.ts  # Rate limiting
β”‚       β”‚   β”‚   β”œβ”€β”€ schema.ts      # Zod validation schemas
β”‚       β”‚   β”‚   β”œβ”€β”€ user-store.ts  # User data management
β”‚       β”‚   β”‚   β”œβ”€β”€ utils.ts       # Utilities
β”‚       β”‚   β”‚   └── webhook-url.ts # Webhook URL handling
β”‚       β”‚   β”œβ”€β”€ types/             # TypeScript types
β”‚       β”‚   β”‚   └── next-auth.d.ts # NextAuth type extensions
β”‚       β”‚   β”œβ”€β”€ proxy.ts           # Request proxy
β”‚       β”‚   └── globals.css        # Global styles
β”‚       β”œβ”€β”€ prisma/                # Database schema
β”‚       β”‚   β”œβ”€β”€ schema.prisma      # Prisma schema
β”‚       β”‚   └── migrations/        # Database migrations
β”‚       β”œβ”€β”€ public/                # Static assets
β”‚       β”œβ”€β”€ package.json
β”‚       β”œβ”€β”€ tsconfig.json
β”‚       β”œβ”€β”€ next.config.ts
β”‚       β”œβ”€β”€ postcss.config.mjs
β”‚       β”œβ”€β”€ tailwind.config.ts
β”‚       └── eslint.config.js
β”‚
β”œβ”€β”€ packages/                      # Shared packages
β”‚   β”œβ”€β”€ encryption/                # Encryption utilities
β”‚   β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”‚   β”œβ”€β”€ crypto.ts          # Crypto functions
β”‚   β”‚   β”‚   └── index.ts           # Export
β”‚   β”‚   └── package.json
β”‚   β”œβ”€β”€ eslint-config/             # Shared ESLint configurations
β”‚   β”‚   β”œβ”€β”€ base.js
β”‚   β”‚   β”œβ”€β”€ next.js
β”‚   β”‚   └── react-internal.js
β”‚   └── typescript-config/         # Shared TypeScript configurations
β”‚       β”œβ”€β”€ base.json
β”‚       β”œβ”€β”€ nextjs.json
β”‚       └── react-library.json
β”‚
β”œβ”€β”€ package.json                   # Root package.json
β”œβ”€β”€ turbo.json                     # Turbo configuration
└── README.md                      # This file

πŸ—„οΈ Database Schema

SecretTunnel uses PostgreSQL with Prisma ORM. Key models:

User

  • Stores user account information
  • Fields: id, name, email, profilePhoto, emailVerified, createdAt, updatedAt
  • Relations: Has many Accounts

Account

  • Oauth/credential provider accounts linked to users
  • Fields: id, userId, provider, providerAccountId, access_token, refresh_token, expires_at, password_hash, etc.
  • Supports GitHub OAuth and credential-based auth
  • Relations: Belongs to User

SecretGroup

  • Groups of versioned secrets (e.g., "production .env")
  • Fields: id, userId, name, createdAt
  • Relations: Has many SecretVersions

SecretVersion

  • Individual versions of secrets within a group
  • Fields: id, groupId, versionNumber, ciphertext, iv, createdAt
  • Encrypted content stored as ciphertext + IV
  • Relations: Belongs to SecretGroup

πŸ› οΈ Getting Started

Prerequisites

  • Node.js β‰₯ 18
  • Bun β‰₯ 1.2.23 (or npm/yarn as fallback)
  • PostgreSQL database (or Docker PostgreSQL)
  • Optional: Redis/Upstash for session/TTL
  • Optional: GitHub OAuth credentials for authentication

Installation

  1. Clone the repository

    git clone https://github.com/yourusername/secrettunnel.git
    cd secrettunnel
  2. Install dependencies

    bun install
  3. Set up environment variables

    Create a .env.local file in apps/web/:

    # Database
    DATABASE_URL=postgresql://user:password@localhost:5432/secrettunnel
    
    # NextAuth
    NEXTAUTH_URL=http://localhost:3000
    NEXTAUTH_SECRET=your-secret-key-here
    
    # GitHub OAuth (optional)
    GITHUB_ID=your-github-oauth-app-id
    GITHUB_SECRET=your-github-oauth-app-secret
    
    # Upstash Redis (for TTL/caching)
    UPSTASH_REDIS_REST_URL=https://your-redis-url
    UPSTASH_REDIS_REST_TOKEN=your-token
    
    # Upstash QStash (for webhooks)
    QSTASH_TOKEN=your-qstash-token
    QSTASH_CURRENT_SIGNING_KEY=your-signing-key
    QSTASH_NEXT_SIGNING_KEY=your-next-signing-key
    
    # Optional: API URL for CLI
    SECRETTUNNEL_API_URL=http://localhost:3000
    API_URL=http://localhost:3000
  4. Set up the database

    cd apps/web
    bun prisma migrate deploy  # Apply migrations
    # or
    bun prisma db push         # For development
  5. Run the development server

    # From root
    bun dev

    This starts:

    Individual apps:

    # Web app only
    cd apps/web && bun run dev
    
    # CLI
    cd apps/cli && bun run dev

πŸ“ Available Commands

Root Commands (Turbo)

# Development
bun dev              # Run all apps in dev mode

# Building
bun run build        # Build all apps and packages

# Type checking
bun run check-types  # Type-check all apps

# Linting
bun run lint         # Lint all apps

# Formatting
bun run format       # Format code with Prettier

Web App Commands

cd apps/web

# Development
bun run dev          # Start dev server on :3000

# Building
bun run build        # Production build
bun run start        # Start production server

# Type checking & linting
bun run check-types  # TypeScript check
bun run lint         # ESLint

# Database
bun prisma migrate dev          # Create and apply migration
bun prisma migrate deploy       # Apply migrations
bun prisma db push              # Sync schema (dev)
bun prisma studio              # Open Prisma Studio

CLI Commands

cd apps/cli

# Development
bun run dev

# Build
bun run build

# Usage examples
bun src/index.ts push "my secret"
bun src/index.ts pull <share-url>

πŸ” Security Architecture

Encryption

  • Algorithm: AES-256-GCM (Web Crypto API)
  • Key location: URL fragment only (#key=...)
  • Server: Receives and stores only ciphertext
  • Key derivation: Not exposed to server; derived client-side

Password Protection (Optional)

  • Algorithm: scrypt with salt
  • Storage: Password hash stored in Redis/PostgreSQL
  • Comparison: Timing-safe comparison to prevent timing attacks
  • Implementation: lib/password.ts using Node.js crypto

Authentication

  • Provider 1: GitHub OAuth via NextAuth.js
  • Provider 2: Credential-based (email + password)
  • Session: HTTP-only cookies (NextAuth.js default)
  • Type safety: Custom next-auth.d.ts type extensions

Network Security

  • HTTPS: Required in production
  • Rate limiting: Implemented in lib/rate-limit.ts
  • CORS: Configured as needed
  • Webhook timeout: 5 seconds (configurable)

πŸ”— API Endpoints

Public Endpoints

Method Route Purpose
POST /api/secrets Create a secret
GET /api/secrets/:token Retrieve a secret
GET /api/test Health check

Authenticated Endpoints

Method Route Purpose
GET /api/audit List audit logs
GET /api/versioned-secrets/groups List secret groups
POST /api/versioned-secrets Create versioned secret
GET /api/versioned-secrets/:id Get versioned secret

Webhook Delivery

Method Route Purpose
POST /api/webhooks/deliver Deliver webhook notifications

πŸ—‚οΈ App Overview

apps/cli

SecretTunnel CLI β€” Node.js command-line tool for secret management without UI.

Features:

  • Push secrets from command line or files
  • Pull secrets with optional password
  • Configure TTL and webhooks
  • Custom API endpoints via environment variables

Commands:

# Push secret
bun src/index.ts push "content" [--ttl 24h] [--password pass] [--webhook url] [--file path]

# Pull secret
bun src/index.ts pull <url-or-token> [--key base64] [--password pass] [--output path|->]

API endpoints used:

  • POST /api/secrets β€” Create secret
  • GET /api/secrets/:token β€” Retrieve secret

apps/web

SecretTunnel Web App β€” Next.js full-stack application with UI, authentication, and versioned secrets.

Key routes:

Route Page Purpose
/ Home Landing page
/signin Sign in User login
/signup Sign up User registration
/dashboard Dashboard User's secret groups
/s/:token Secret viewer Public secret view
/vs/:groupId Versioned secrets Versioned secret group

Key features:

  • User authentication (GitHub + credentials)
  • Create, view, and delete secrets
  • Versioned secret management
  • Audit logging
  • Webhook integration
  • Dark mode support (next-themes)

πŸ“¦ Packages

@repo/encryption

Shared encryption utilities for AES-256-GCM encryption and decryption.

Exports:

  • encrypt() β€” Encrypt plaintext to ciphertext
  • decrypt() β€” Decrypt ciphertext to plaintext
  • Type utilities for working with encrypted data

Used by:

  • Web app (frontend + backend)
  • CLI (encryption/decryption)

@repo/eslint-config

Shared ESLint configuration files:

  • base.js β€” Core ESLint rules
  • next.js β€” Next.js-specific rules
  • react-internal.js β€” React rules for internal use

@repo/typescript-config

Shared TypeScript configuration files:

  • base.json β€” Base tsconfig
  • nextjs.json β€” Next.js specific
  • react-library.json β€” React library specific

πŸ”„ Webhook Flow

  1. User creates a secret with a webhook URL
  2. Webhook URL stored in Redis with secret metadata
  3. When secret is viewed:
    • Secret marked as "delivered"
    • QStash queues webhook task
  4. QStash triggers /api/webhooks/deliver:
    • Makes HTTP POST to webhook URL
    • Sends: { token, viewedAt, viewerIp }
    • Timeout: 5 seconds
  5. Webhook status stored: pending β†’ enqueued β†’ delivered|failed

Webhook retry logic:

  • Handled by QStash (configurable)
  • Failed webhooks can be retried manually

πŸ§ͺ Testing

Type Checking

bun run check-types   # All apps
cd apps/web && bun run check-types

Linting

bun run lint         # All apps with no warnings
cd apps/web && bun run lint

Manual Testing

  • Access web app: http://localhost:3000
  • CLI: cd apps/cli && bun run dev
  • Prisma Studio: cd apps/web && bun prisma studio

πŸš€ Deployment

Environment Setup

For production:

  • Use strong NEXTAUTH_SECRET (generate with: openssl rand -base64 32)
  • Set NEXTAUTH_URL to your production domain
  • Configure GitHub OAuth for your domain
  • Use Upstash Redis and QStash for prod instances
  • Enable HTTPS only

Building for Production

# Build all apps
bun run build

# Build web app specifically
cd apps/web && bun run build

# Preview production build
cd apps/web && bun run start

Deployment Platforms

Supported:

  • Vercel (Next.js optimized)
  • Docker (containerization-ready)
  • Self-hosted (Node.js β‰₯18)

Example Vercel deployment:

vercel deploy

πŸ“š Environment Variables Reference

Variable Used By Required Purpose
DATABASE_URL Web βœ… PostgreSQL connection string
NEXTAUTH_URL Web βœ… NextAuth callback URL
NEXTAUTH_SECRET Web βœ… NextAuth session secret
RESEND_API_KEY Web βœ… Resend API key for credential email verification
RESEND_FROM_EMAIL Web βœ… Verified sender, for example SecretTunnel <noreply@example.com>
GITHUB_ID Web ❌ GitHub OAuth app ID
GITHUB_SECRET Web ❌ GitHub OAuth app secret
UPSTASH_REDIS_REST_URL Web ❌ Redis URL for TTL/caching
UPSTASH_REDIS_REST_TOKEN Web ❌ Redis auth token
QSTASH_TOKEN Web ❌ QStash API token
QSTASH_CURRENT_SIGNING_KEY Web ❌ QStash signing key
QSTASH_NEXT_SIGNING_KEY Web ❌ QStash next signing key
SECRETTUNNEL_API_URL CLI ❌ Web API URL (default: localhost:3000)
API_URL CLI ❌ Fallback API URL
NODE_ENV Both ❌ Environment (dev/production)

🀝 Contributing

  1. Create a feature branch: git checkout -b feature/my-feature
  2. Make changes and commit: git commit -am "Add feature"
  3. Push to branch: git push origin feature/my-feature
  4. Open a Pull Request

Code Quality

  • Run type checking: bun run check-types
  • Run linting: bun run lint
  • Format code: bun run format
  • All checks must pass before merging

πŸ“„ License

This project is licensed under the MIT License β€” see LICENSE for details.


πŸ™ Acknowledgments


πŸ“ž Support

For issues, questions, or feature requests, please open an issue on GitHub.


Last updated: April 2026 | Node.js: β‰₯18 | Package Manager: Bun β‰₯1.2.23

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors