CSRF token is missing error in docker pgadmin

Viewed 11511

I am trying to create a docker-compose stack with pg and pgadmin as follows,

version: '3.1'
services:
  pg-admin:
    image: dpage/pgadmin4
    volumes:
        - /Users/pkaramol/Desktop/backup.tar:/pgadmin4/dvdrental.tar
    ports:
      - "8181:80"
    environment:
      PGADMIN_DEFAULT_EMAIL: user@domain.com
      PGADMIN_DEFAULT_PASSWORD: 1234
    depends_on:
    - pg
  pg:
    image: postgres:12
    volumes:
      - ./pg-data:/var/lib/postgresql/data
    environment:
      POSTGRES_DB: postgres
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
    restart: always

but pgadmin logs error out as follows:

pg-admin_1  | Traceback (most recent call last):
pg-admin_1  |   File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1811, in full_dispatch_request
pg-admin_1  |     rv = self.preprocess_request()
pg-admin_1  |   File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 2087, in preprocess_request
pg-admin_1  |     rv = func()
pg-admin_1  |   File "/usr/local/lib/python3.8/site-packages/flask_wtf/csrf.py", line 224, in csrf_protect
pg-admin_1  |     self.protect()
pg-admin_1  |   File "/usr/local/lib/python3.8/site-packages/flask_wtf/csrf.py", line 259, in protect
pg-admin_1  |     self._error_response(e.args[0])
pg-admin_1  |   File "/usr/local/lib/python3.8/site-packages/flask_wtf/csrf.py", line 302, in _error_response
pg-admin_1  |     raise CSRFError(reason)
pg-admin_1  | flask_wtf.csrf.CSRFError: 400 Bad Request: The CSRF session token is missing.

Any suggestions?

4 Answers

Make sure that you close tab that were connected to pgAdmin before start the container.

Maybe you are running multiple instances of pgAdmin on the same host? At least for us this was the problem. Shutting down one of them resolved the issue.

For me there were three issues. I'm not sure which one solved it:

  • Disabled cloudflare cache and then purged the cache
  • I am using a non-standard port, 8082 instead of 5050
  • I removed the environment variable PGADMIN_LISTEN_PORT: 8082

Note I am still using port 8082 and can successfully log in.

For me only clearing cookies solved the problem.

Related