Skip to content

fix(core): add CSRF token to HordePopup.popup at click time#171

Open
TDannhauer wants to merge 1 commit into
FRAMEWORK_6_0from
fix/popup-csrf-token
Open

fix(core): add CSRF token to HordePopup.popup at click time#171
TDannhauer wants to merge 1 commit into
FRAMEWORK_6_0from
fix/popup-csrf-token

Conversation

@TDannhauer

Copy link
Copy Markdown
Contributor

Summary

  • Add session ID and CSRF token to every HordePopup.popup() URL at click time via HordeCore.addRequestParams().
  • Ensure token_secret_key exists before read-only sessions are closed, so download/view scripts can validate HMAC tokens.
  • Fix ViewModeConfigurator to expose a modern HMAC HordeCore.conf.TOKEN instead of the legacy empty session slot.

Motivation

After Horde 6 switched to HMAC CSRF tokens, IMP links that open MIME parts in a popup (e.g. “View HTML data in new window”) failed with “Invalid token!” and showed the portal instead of the message. Horde::popupJs() uses HordePopup.popup(), which never appended token/SID parameters, unlike HordeCore.popupWindow().

Changes

  • js/popup.js: call HordeCore.addRequestParams() before window.open().
  • lib/Horde/Registry.php: seed per-session CSRF secret before SESSION_READONLY close.
  • src/PageOutput/ViewModeConfigurator.php (+ factory, tests): use Horde\Token\Token for TOKEN.

Test plan

  • Open an HTML message in IMP dynamic view; click “View HTML data in new window”; popup shows rendered HTML.
  • No “Invalid token!” growler messages in the parent window.
  • Other Horde::popupJs() popups (help, prefs import, etc.) still open and authenticate correctly.
  • vendor/bin/phpunit -c phpunit.xml.dist test/Unit/PageOutput/ViewModeConfiguratorTest.php test/Unit/PageOutput/ViewModeConfiguratorDiscovererTest.php

HordePopup.popup() did not merge session ID and CSRF token into popup
URLs, unlike HordeCore.popupWindow(). Append them at open time via
HordeCore.addRequestParams() when available.

Seed per-session token_secret_key before closing read-only sessions so
view/download endpoints can validate HMAC tokens.

ViewModeConfigurator: emit modern HMAC TOKEN for HordeCore.conf instead
of the legacy empty horde.token session slot.
@TDannhauer TDannhauer requested a review from ralflang June 22, 2026 15:34

@ralflang ralflang left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like adding session ID to ajax URLs like its 1998. These belong into a header (cookie or other).

@TDannhauer

Copy link
Copy Markdown
Contributor Author

Feel free to adapt 🙂

Session and tokens is your Expertise

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants