Fix incorrect boolean evaluation for OVERLEAF_SECURE_COOKIE and OVERLEAF_BEHIND_PROXY #1428
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
The current implementation in
server-ce/config/settings.jshas two issues with environment variable handling:1.
OVERLEAF_SECURE_COOKIE: Uses incorrect boolean evaluationThe expression
!= nullonly checks if the variable exists, not its value:OVERLEAF_SECURE_COOKIE=false→ evaluates totrue(variable exists)OVERLEAF_SECURE_COOKIE=true→ evaluates totrue(variable exists)falseResult: Users cannot disable secure cookies even when explicitly setting
false.2.
OVERLEAF_BEHIND_PROXY: Hardcoded totrue, ignoring environment variableThe environment variable
OVERLEAF_BEHIND_PROXYis completely ignored, making it impossible to disable proxy mode through configuration.Impact
This is particularly problematic because the default configuration template in overleaf/toolkit at
lib/config-seed/variables.envincludes:Users who uncomment these lines and set them to
false(e.g., for local development or HTTP-only deployments) will find:OVERLEAF_SECURE_COOKIE=falsedoesn't work - secure cookies are still enabledOVERLEAF_BEHIND_PROXY=falseis completely ignored - proxy mode is always onThis causes:
Solution
This PR fixes both issues:
1.
OVERLEAF_SECURE_COOKIE: Changed to properly parse string values2.
OVERLEAF_BEHIND_PROXY: Changed to read from environment variableNow the behavior is correct:
OVERLEAF_SECURE_COOKIE=true→trueOVERLEAF_SECURE_COOKIE=false→falseOVERLEAF_BEHIND_PROXY=true→trueOVERLEAF_BEHIND_PROXY=false→falsefalse(safe default for development)Testing
Tested with various configurations:
OVERLEAF_SECURE_COOKIE=falsenow correctly allows HTTP cookiesOVERLEAF_BEHIND_PROXY=falsenow correctly disables proxy modetruevalues work as expectedBreaking Changes
None. This fixes broken behavior while maintaining backward compatibility:
falsetruecontinues to work as expectedFixes #1032