Skip to content

fix: trust proxy ssl to forward session cookie #1193

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

Merged
merged 6 commits into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
4 changes: 4 additions & 0 deletions config/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ The following config option are provided by the OpenHIM. All of these options ha
// The session secret key used for the hashing of signed cookie (used to detect if the client modified the cookie)
// Signed cookie is another cookie of the same name with the .sig suffix appended
"sessionKey": "r8q,+&1LM3)CD*zAGpx1xm{NeQhc;#",
// If OpenHIM is behind a proxy (should be `true` if the proxy sends relevant Forwarded headers)
"trustProxy": false,
// Secure the cookie (either protocol is https or trusting a secured proxy)
secureCookie: true,
// The session max age is the session cookie expiration time (in milliseconds)
"maxAge": 7200000,
// The number of characters that will be used to generate a random salt for the encryption of passwords
Expand Down
2 changes: 2 additions & 0 deletions config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
},
"api": {
"sessionKey": "r8q,+&1LM3)CD*zAGpx1xm{NeQhc;#",
"trustProxy": false,
"secureCookie": true,
"maxAge": 7200000,
"salt": 10,
"enabled": true,
Expand Down
7 changes: 6 additions & 1 deletion src/koaApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,17 @@ export function setupApp(done) {

// Configure Sessions Middleware
app.keys = [config.api.sessionKey]

if (config.api.trustProxy) {
app.proxy = true
}

app.use(
session(
{
maxAge: config.api.maxAge || 7200000,
resave: false,
secure: true,
secure: config.api.secureCookie,
httpOnly: true,
sameSite: 'none',
store: new MongooseStore()
Expand Down