Skip to content

Commit b73bc64

Browse files
Merge pull request #1193 from jembi/fix/cookie-proxy
fix: trust proxy ssl to forward session cookie
2 parents ee71267 + 6cad525 commit b73bc64

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

config/config.md

+4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ The following config option are provided by the OpenHIM. All of these options ha
4646
// The session secret key used for the hashing of signed cookie (used to detect if the client modified the cookie)
4747
// Signed cookie is another cookie of the same name with the .sig suffix appended
4848
"sessionKey": "r8q,+&1LM3)CD*zAGpx1xm{NeQhc;#",
49+
// If OpenHIM is behind a proxy (should be `true` if the proxy sends relevant Forwarded headers)
50+
"trustProxy": false,
51+
// Secure the cookie (either protocol is https or trusting a secured proxy)
52+
secureCookie: true,
4953
// The session max age is the session cookie expiration time (in milliseconds)
5054
"maxAge": 7200000,
5155
// The number of characters that will be used to generate a random salt for the encryption of passwords

config/default.json

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
},
3434
"api": {
3535
"sessionKey": "r8q,+&1LM3)CD*zAGpx1xm{NeQhc;#",
36+
"trustProxy": false,
37+
"secureCookie": true,
3638
"maxAge": 7200000,
3739
"salt": 10,
3840
"enabled": true,

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "openhim-core",
33
"description": "The OpenHIM core application that provides logging and routing of http requests",
4-
"version": "7.2.1",
4+
"version": "7.3.0",
55
"main": "./lib/server.js",
66
"bin": {
77
"openhim-core": "./bin/openhim-core.js"

src/koaApi.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,17 @@ export function setupApp(done) {
4040

4141
// Configure Sessions Middleware
4242
app.keys = [config.api.sessionKey]
43+
44+
if (config.api.trustProxy) {
45+
app.proxy = true
46+
}
47+
4348
app.use(
4449
session(
4550
{
4651
maxAge: config.api.maxAge || 7200000,
4752
resave: false,
48-
secure: true,
53+
secure: config.api.secureCookie,
4954
httpOnly: true,
5055
sameSite: 'none',
5156
store: new MongooseStore()

0 commit comments

Comments
 (0)