Overview
DefDrive implements a sophisticated access control system that allows file owners to create shareable links with fine-grained restrictions including IP whitelisting, subnet restrictions, time-to-live (TTL), expiration dates, and one-time use.IP Restrictions
Whitelist specific IPs or subnets
Time-Based
Set expiration dates for links
TTL (Hops)
Limit number of access attempts
One-Time Use
Links that expire after first use
Access Model
The Access model defines the structure for shareable file links with various restrictions.Model Definition
Each Access record is linked to a specific File via the
FileID foreign key. Multiple access links can be created for the same file with different restrictions.Key Fields
| Field | Type | Description |
|---|---|---|
Link | string | Unique identifier for the access link (uniqueIndex) |
IPs | []string | Array of allowed IP addresses |
Subnets | []string | Array of allowed CIDR subnets |
Expires | string | RFC3339 timestamp for expiration |
Public | bool | Whether the access link is public |
OneTimeUse | bool | If true, link becomes invalid after first use |
Used | bool | Tracks if a one-time link has been used |
TTL | int | Number of remaining access attempts (hops) |
EnableTTL | bool | Whether TTL enforcement is active |
Public vs Private Access
Both the File and Access must be public for unrestricted access.Public Access Logic
Both conditions must be true: The File must have
Public = true AND the Access must have Public = true for unrestricted access. This dual-check ensures explicit permission at both levels.Public File + Public Access
Fully accessible (subject to other restrictions)
Private File OR Private Access
Access denied regardless of other settings
IP and Subnet Restrictions
Restrict file access to specific IP addresses or CIDR subnets.IP Whitelist
Only clients with whitelisted IP addresses can access the file:Subnet Whitelist
Allow access from entire subnets using CIDR notation:Time-Based Restrictions
Expiration Time
Set an absolute expiration date using RFC3339 format:2026-12-31T23:59:59Z
If the
Expires field is empty, the link never expires based on time. However, other restrictions (TTL, one-time use) may still apply.TTL (Time-To-Live)
TTL limits the number of times a link can be accessed, regardless of who accesses it.TTL Enforcement
TTL Behavior:
- TTL is decremented before access is granted
- When TTL reaches 0, the link becomes permanently invalid
- The final access (when TTL becomes 0) is denied
EnableTTLmust betruefor TTL to be enforced
TTL Example
One-Time Use Links
One-time use links become invalid immediately after the first successful access.One-Time Use Check
Marking as Used
After all checks pass, one-time links are marked as used:Access Restrictions Flow
The middleware validates access in a specific order:Validation Order
- Link Lookup - Verify the access link exists
- File Lookup - Verify the associated file exists
- Public Check - Both file and access must be public
- Subnet Restriction - Check if client IP is in allowed subnets
- IP Restriction - Check if client IP is in allowed IPs
- One-Time Use - Check if link has already been used
- TTL - Decrement and check remaining hops
- Expiration - Check if link has expired
- Mark as Used - If one-time use, mark the link as used
The checks use short-circuit evaluation with OR (
||). If any check fails, the remaining checks are skipped and access is denied.Restriction Combinations
Restrictions can be combined for enhanced security:Corporate Sharing
IP Restriction + Expiration
Share with office network (subnet) for limited time
Share with office network (subnet) for limited time
Secret Document
One-Time Use + IP Restriction + Expiration
Maximum security for sensitive files
Maximum security for sensitive files
Limited Distribution
TTL + Expiration
Allow specific number of downloads within timeframe
Allow specific number of downloads within timeframe
Public with Limits
Public + TTL
Publicly accessible but limited to N downloads
Publicly accessible but limited to N downloads
Access Link Structure
Access links reference both the controller and file:Links are enforced with a unique index at the database level to prevent collisions.
Related Concepts
Authentication
Learn about JWT authentication
File Management
Understand file ownership and storage
User Limits
Explore storage and file quotas