Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose expiry period for notes as environment variable #55

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ services:
# Rate limit for downloading notes
- GET_LIMIT_WINDOW_SECONDS=60
- GET_LIMIT=20
# Duration in days that notes are kept
- EXPIRE_WINDOW_DAYS=30
depends_on:
migrate:
condition: service_completed_successfully
Expand Down
3 changes: 3 additions & 0 deletions server/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ DATABASE_URL="file:./dev.sqlite"
# and expired notes are deleted.
CLEANUP_INTERVAL_SECONDS=60

# Duration in days that notes are kept, after which they are expired.
EXPIRE_WINDOW_DAYS=30

# Rate limit for uploading notes.
POST_LIMIT_WINDOW=86400
POST_LIMIT=50
Expand Down
1 change: 1 addition & 0 deletions server/.env.test
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ POST_LIMIT_WINDOW_SECONDS=0.25
GET_LIMIT=20
GET_LIMIT_WINDOW_SECONDS=0.1
LOG_LEVEL=warn
EXPIRE_WINDOW_DAYS=30

# Make cleanup interval very long to avoid automatic cleanup during tests
CLEANUP_INTERVAL_SECONDS=99999
5 changes: 2 additions & 3 deletions server/src/controllers/note/note.post.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,13 @@ export async function postNoteController(
}

// Create note object
const EXPIRE_WINDOW_DAYS = 30;
const secret_token = generateToken();

const note = {
ciphertext: notePostRequest.ciphertext as string,
hmac: notePostRequest.hmac as string,
iv: notePostRequest.iv as string,
expire_time: addDays(new Date(), EXPIRE_WINDOW_DAYS),
expire_time: addDays(new Date(), process.env(EXPIRE_WINDOW_DAYS)),
crypto_version: notePostRequest.crypto_version,
secret_token: secret_token,
} as EncryptedNote;
Expand All @@ -65,7 +64,7 @@ export async function postNoteController(
event.success = true;
event.note_id = savedNote.id;
event.size_bytes = getNoteSize(note);
event.expire_window_days = EXPIRE_WINDOW_DAYS;
event.expire_window_days = process.env(EXPIRE_WINDOW_DAYS);
await EventLogger.writeEvent(event);
res.json({
view_url: `${process.env.FRONTEND_URL}/note/${savedNote.id}`,
Expand Down