Skip to content

Commit 93d25ee

Browse files
Use COOKIE_DEFAULT_PATH or SCRIPT_NAME in session cookie path. #6557
1 parent a166f8d commit 93d25ee

File tree

5 files changed

+13
-8
lines changed

5 files changed

+13
-8
lines changed

web/pgadmin/__init__.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -496,11 +496,6 @@ def run_migration_for_others():
496496
'SECURITY_EMAIL_VALIDATOR_ARGS': config.SECURITY_EMAIL_VALIDATOR_ARGS
497497
}))
498498

499-
if 'SCRIPT_NAME' in os.environ and os.environ["SCRIPT_NAME"]:
500-
app.config.update(dict({
501-
'APPLICATION_ROOT': os.environ["SCRIPT_NAME"]
502-
}))
503-
504499
app.config.update(dict({
505500
'INTERNAL': INTERNAL,
506501
'LDAP': LDAP,
@@ -833,7 +828,7 @@ def after_request(response):
833828
config.COOKIE_DEFAULT_DOMAIN != 'localhost':
834829
domain['domain'] = config.COOKIE_DEFAULT_DOMAIN
835830
response.set_cookie('PGADMIN_INT_KEY', value=request.args['key'],
836-
path=config.COOKIE_DEFAULT_PATH,
831+
path=config.SESSION_COOKIE_PATH,
837832
secure=config.SESSION_COOKIE_SECURE,
838833
httponly=config.SESSION_COOKIE_HTTPONLY,
839834
samesite=config.SESSION_COOKIE_SAMESITE,

web/pgadmin/browser/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ def index():
422422
domain['domain'] = config.COOKIE_DEFAULT_DOMAIN
423423

424424
response.set_cookie("PGADMIN_LANGUAGE", value=language,
425-
path=config.COOKIE_DEFAULT_PATH,
425+
path=config.SESSION_COOKIE_PATH,
426426
secure=config.SESSION_COOKIE_SECURE,
427427
httponly=config.SESSION_COOKIE_HTTPONLY,
428428
samesite=config.SESSION_COOKIE_SAMESITE,

web/pgadmin/evaluate_config.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,13 @@ def evaluate_and_patch_config(config: dict) -> dict:
127127
config.setdefault('DISABLED_LOCAL_PASSWORD_STORAGE', False)
128128
config.setdefault('KEYRING_NAME', k_name)
129129

130+
config.setdefault('SESSION_COOKIE_PATH', config.get('COOKIE_DEFAULT_PATH'))
131+
132+
# if a script name is preset, session cookies should go to sub path
133+
if 'SCRIPT_NAME' in os.environ and os.environ["SCRIPT_NAME"]:
134+
config.update(dict({
135+
'APPLICATION_ROOT': os.environ["SCRIPT_NAME"],
136+
'SESSION_COOKIE_PATH': os.environ["SCRIPT_NAME"],
137+
}))
138+
130139
return config

web/pgadmin/preferences/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ def save():
262262

263263
setattr(session, 'PGADMIN_LANGUAGE', language)
264264
response.set_cookie("PGADMIN_LANGUAGE", value=language,
265-
path=config.COOKIE_DEFAULT_PATH,
265+
path=config.SESSION_COOKIE_PATH,
266266
secure=config.SESSION_COOKIE_SECURE,
267267
httponly=config.SESSION_COOKIE_HTTPONLY,
268268
samesite=config.SESSION_COOKIE_SAMESITE,

web/pgadmin/utils/session.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ def save_session(self, app, session, response):
314314
app.config['SESSION_COOKIE_NAME'],
315315
'%s!%s' % (session.sid, session.hmac_digest),
316316
expires=cookie_exp,
317+
path=config.SESSION_COOKIE_PATH,
317318
secure=config.SESSION_COOKIE_SECURE,
318319
httponly=config.SESSION_COOKIE_HTTPONLY,
319320
samesite=config.SESSION_COOKIE_SAMESITE,

0 commit comments

Comments
 (0)