Commit Graph
31 Commits
Author SHA1 Message Date
Ashesh Vashi 8383c1220b chore(tests): unskip MFA validation-view test by completing dummy harness
The previous commit (2e14bd95d) made the MFA test package discoverable
and resilient but left one scenario --
'Validation view of a MFA method should return a HTML tags' -- as a
documented unittest.SkipTest. The skip reason was that
validate.html -> security/render_page.html -> base.html references
'current_app' and 'csrf_token()' in Jinja, and the dummy Flask app
built by test_create_dummy_app() does not expose either: pgAdmin's
real create_app() injects current_app via an @app.context_processor
(web/pgadmin/__init__.py:922) and Flask-WTF registers csrf_token() in
the Jinja env. The bare Flask(name, ...) used by the dummy app has
neither, so the GET-path render fails with
UndefinedError: 'current_app' is undefined.

Add the same two globals to the dummy app:

* A @app.context_processor returning {'current_app': current_app} so
  the Flask proxy is bound at render time, mirroring what
  create_app() does in production.
* A jinja_env.globals['csrf_token'] = lambda: 'dummy-csrf-token' that
  matches what Flask-WTF would otherwise install. Tests asserting on
  the rendered HTML can rely on the marker being present and stable.

With both globals available the template renders, /mfa/validate
returns a 200 HTML response, and the scenario goes from SkipTest to
a real assertion. The fix is intentionally scoped to the dummy harness
in tests/utils.py -- no production code change.

Result on this worktree: pgadmin.authenticate.mfa.tests now runs as
13 passed / 0 failed / 0 skipped (was 12/0/1). Full suite goes from
1818/0/444 to 1819/0/443.
2026-06-08 19:41:51 +05:30
Ashesh Vashi 2e14bd95dd chore(tests): make MFA test package discoverable and resilient
The MFA test directory was missing __init__.py, so
find_modules('pgadmin', False, True) in regression/runtests.py could
not walk into it. The test classes therefore never reached the
TestsGeneratorRegistry registry and the entire pgadmin.authenticate.mfa
test suite was silently absent from the default test run. The
regression for #10028 added in this branch was caught by that gap.

Adding the missing __init__.py exposes a second pre-existing problem:
TestMFATests.setUp called BaseTestGenerator.setUp, which posts to
/browser/server/connect/... and asserts a 200 response. The MFA
scenarios all run against a dummy Flask app (or pure mocks), so that
endpoint is not registered and the connect_server assertion fires
before any check_*() function runs. Skip the BaseTestGenerator setUp
since these scenarios deliberately do not need a real PostgreSQL
server.

Three further fixes that surface once the suite actually runs:

* mfa_enabled() and init_app() both short-circuit when SERVER_MODE
  is False. test_config.json defaults to DESKTOP mode, so every
  scenario in the suite was taking the disabled path. Force
  SERVER_MODE=True for the duration of the TestMFATests class and
  restore the previous value in tearDownClass.

* check_validation_view_content patched flask.current_app to capture
  logger.exception() calls. Those only fire on the POST path of
  /mfa/validate; the test exercises only the GET path, so the patch
  was dead code -- and additionally turned flask.current_app into a
  MagicMock, which broke Jinja's lookup of current_app in
  validate.html. Drop the patch and the now-unused ValidationException
  import.

* check_validation_view_content still cannot render validate.html
  against the bare dummy Flask app because the template references
  current_app.config and extends Flask-Security's
  security/render_page.html, neither of which the dummy app provides.
  Skip the scenario with a clear unittest.SkipTest reason rather than
  paper over with a brittle patch; rebuilding the dummy harness to
  expose those globals is its own follow-up.

Result on this worktree: pgadmin.authenticate.mfa.tests now runs as
12 passed / 0 failed / 1 skipped (the dummy-app/template gap),
up from a silent 0/0/0. Full suite goes from 1806/0/443 to 1818/0/444.
2026-06-08 19:25:48 +05:30
Dave Page fff6a48185 fix(mfa): reject external 'next' targets in MFA flow to close open redirect
The MFA flow honoured the user-supplied "next" query/form parameter
without checking that it pointed back inside pgAdmin, so an attacker
who got a logged-in user to click /mfa/validate?next=<external> could
land them on an attacker-controlled host straight out of the auth
flow -- a trusted-domain redirect ideal for credential-phishing
follow-on.

Add a single _is_safe_redirect_url helper that allows only same-origin
http(s) targets (relative paths included) and rejects:

* external hosts in absolute and protocol-relative ("//host") form;
* non-http schemes a browser will still follow (javascript:, data:,
  mailto:);
* userinfo tricks ("http://localhost@attacker.example/");
* backslash variants ("/\\host", "\\\\host") that some browsers
  normalize to forward slashes, enabling protocol-relative bypasses;
* empty / missing targets.

Gate every redirect that consumes the user-supplied next value through
the helper -- the GET and POST branches of /mfa/validate and the POST
branch of /mfa/register -- falling back to the internal browser index
when the target is anything other than safe. The registration POST
keeps its existing 'internal' sentinel ("rendered from the in-app
dialog") since that string is matched exactly and is not a URL.

Ship the validator with a dedicated table-driven unit test covering
each accept/reject category and an integration test that POCs the
attacker payload from the report and asserts the response redirects
to the internal index instead of attacker.example.

Reported by: Mai Phạm Hiền <mai.phamhien171@gmail.com>
Reviewed by: Kundan Sable <kundan.sable@enterprisedb.com>
2026-06-08 18:55:51 +05:30
Akshay Joshi 52daa56a04 Copyright updated for 2026 2026-01-05 13:33:45 +05:30
Dave Page 70e4435b04 Python string cleanup
* Python string cleanup
* Fix line lengths
* Further Python string fixes.
2025-12-01 11:06:21 +05:30
Pravesh Sharma 08379d6ae0 Fixed an issue where the 2FA window redirected to the login page after session expiration. #9132 2025-10-31 11:17:04 +05:30
Akshay Joshi 964d211260 Copyright updated for 2025 2025-01-01 11:26:42 +05:30
Ahmad 5c30695d66 Fixed Typos 2024-05-23 12:52:41 +05:30
Khushboo Vashi f4761f55f7 Fixed Multi-Factor Authentication bypass vulnerability (CVE-2024-4215). #7425 2024-04-29 13:41:02 +05:30
Yogesh Mahajan 102e0a9839 - Update MUI v4 to v5
- Remove the SCSS dependency completely and use MUI for theming.
- Update - date-fns, @date-io, notistack. Remove - popper.js, sass-loader.
- Cleanup webpack config.
- Port PSQL tool to use MUI themes instead of SCSS theme.
- Theme change will reflect realtime without refreshing pgAdmin.
2024-04-09 08:21:14 +05:30
Anil Sahoo e99fc02f9e Fixed issue related to email authentication of Two-factor authentication. #7308 2024-03-26 11:27:35 +05:30
Akshay Joshi 0e0cbc40b8 Fixed SonarQube code smell Replace the unused local variable with '_'. 2024-01-24 18:33:43 +05:30
Akshay Joshi 740ce15bd7 Update copyright notices for 2024 2024-01-01 14:13:48 +05:30
Aditya Toshniwal 078a959e3d Remove the Pillow dependency completely. 2023-10-05 12:40:29 +05:30
Aditya Toshniwal a1c7265c41 Fix PEP8 issues with latest pycodestyle (#6636) 2023-07-31 18:14:39 +05:30
Aditya Toshniwal 2aea5b41ad Fix an issue where changing MFA_SUPPORTED_METHODS breaks the MFA validation. #6624 2023-07-31 15:02:30 +05:30
Aditya Toshniwal ac5be70c60 Fix issues found while testing login pages. #6295 2023-07-11 18:12:06 +05:30
Pravesh Sharma 62056cab14 Fixed sonaqube security smells and bugs
1. Delete unreachable code or refactor the code to make it reachable.
2. Unexpected var, use let or const instead.
3. Remove useless assignment to variable.
4. Define a constant instead of duplicating the literal
5. Remove commented out code
2023-07-10 10:36:15 +05:30
Aditya Toshniwal d6cddd8c29 Remove Bootstrap and jQuery from authentication pages and rewrite them in ReactJS. #6295 2023-06-30 16:08:33 +05:30
Akshay Joshi 98184e5835 Update copyright notices for 2023 2023-01-02 11:53:55 +05:30
Mark Mayo 41508f7f67 python 3 updates
- Fix super() calls for python 3
- No need to inherit objects.
- No need for u at the start of strings
- Tidied up some brackets and f-strings too
2022-11-19 10:13:41 +05:30
Akshay Joshi e17c50d304 Added support for storing configurations of pgAdmin in an external database. #1832 2022-10-20 16:18:41 +05:30
Akshay Joshi 0b6b2e733a 1) Remove Python's 'Six' package completely. #5357
2) Replace deprecated @abstractproperty with @property, @abstractmethod.
2022-09-26 12:47:31 +05:30
Akshay Joshi 7086719640 Fixed SonarQube issues. 2022-09-08 18:08:58 +05:30
Akshay Joshi 084203debc Fixed Securtiy Hotspot reported by SonarQube. 2022-08-12 17:10:26 +05:30
Aditya Toshniwal cb635f6706 Removing dynamic module loading and replacing it with static loading. Fixes #7492
Gets rid of all occurrences and usage of get_own_javascripts since it is no longer used.
2022-06-30 11:06:50 +05:30
Dave Page 39bfb575da Improve message wording. 2022-03-14 11:18:20 +00:00
Akshay Joshi 2786f7ac5a Update copyright notices for 2022 2022-01-04 13:54:25 +05:30
Ashesh Vashi 36c9eb3dfd Added support for Two-factor authentication for improving security. Fixes #6543 2021-12-02 16:47:18 +05:30
Akshay Joshi 7d07770244 Reverting 'Two-factor authentication' support as it cause OSX and docker build failures.
This reverts commit 787a441343.
2021-09-29 13:24:18 +05:30
Ashesh Vashi 787a441343 Added support for Two-factor authentication for improving security. Fixes #6543 2021-09-28 17:47:00 +05:30