Package: plone.session
Overviewplone.sessionimplements secure session management for Zope sites.In its default configurationplone.sessionuses anHMACSHA-256secure cryptographic hash to authenticate sessions.
The hash is generated using the userid and a secret stored in the PAS plugin.
Otherwise, the cookie format is identical to that of Apache’smod_auth_tkt.
For single sign on with the original mod_auth_tkt or another compatible implementation, set themod_auth_tktproperty to true.
This invokes anMD5based double hashing scheme.
You will need to use the same secret across all servers.This has several advantages over other session management systems:passwords are not sent to the server in a cookie on every request, as is done by theCookie Auth Helperit does not require any ZODB write for sessions, as is needed by theSession Crumbler.
This allows it to scale very well.it allows you to invalidate all existing authentication cookies for users by updating the secret.The cookie is only valid for the period specified by thetimeoutproperty.There are some downsides to this approach:if a user’s password is changed or disabled session identifiers will continue to work, making it hard to lock out individual users.a user must have cookies enabled.A session cookie is used to track sessions;
that means that as long as a user keeps his browser open (and does not explicitly log out) the session remains open until the timeout limit is reached.
This can be changed by setting thetimeoutproperty of the plugin to the number of seconds the cookie should remain validafter the moment of login.plone.sessiondoesnotexcuse you from setting up TLS (aka HTTPS) for your site.tktauth.pyimplements the core mod_auth_tkt functionality.
It is self-contained and may be of useful to other frameworks.Using plone.sessionplone.sessiononly takes care of handling sessions for already authenticated users.
This means it can not be used stand-alone: you need to have another PAS plugin, such as the standardCookie Auth Helperto take care of authentication.After a user has been authenticatedplone.sessioncan take over via the PAScredentials updatemechanism.Configuration optionsTo enable logins between sites or other mod_auth_tkt systems, set the shared secret through the Zope Management Interface.
You can manage theplone.keyringsecrets through the same page.The following properties may be set through thePropertiestab:Cookie validity timeout (in seconds)After this, the session is invalid and the user must login again.
Set to 0 for the cookie to remain valid indefinitely.
Note that when the user folder has caching enabled, cookie validity may not be checked on every request.Refresh interval (in seconds, -1 to disable refresh)This controls the refresh CSS max-age (see below.)Use mod_auth_tkt compatible hashing algorithmCompatibility with other implementations, but at the cost of using a weaker hashing algorithm.Cookie nameWhich cookie to use. This must also be set on thecredentials_cookie_authplugin.Cookie lifetime (in days)This makes the cookie persistent across opening and closing the browser.Cookie domain (blank for default)A cookie may be shared across www1.example.com and www2.example.com by setting the cookie domain to.example.com.Cookie pathWhat path the cookie is set valid (defaults to/).Ticket refreshTo enable short validity timeouts you must ensure that the cookie is regularly updated.
One option is to put mod_auth_tkt in front of your site and set aTktAuthTimeoutRefresh.
As ofplone.session 3.1, an independent javascript solution is also supplied, installable as an optional add-on in Plone.Theory of operationThe optional add-on installs a css resource which updates the cookie when loaded.
This allows the cookie to be updated every time a page is loaded.
While this CSS cannot cached by proxy servers, it may be cached for a time on the client.
By controlling themax-ageof the CSS resource, it is possible to control how often the browser actually fetches the CSS and hence how often the cookie is updated.With short timeouts (15 or 30 minutes say), a user may not have loaded a new page before their cookie becomes invalid.
A javascript is included which polls the cookie refresh CSS periodically while the user is active on the page (key presses or mouse moves.)
If the refresh CSS max-age has passed, then the browser will refetch the CSS and the cookie will be updated.
The poll interval may be configured on the refresh CSS query stringminutesparameter, with the default being 5 minutes.Ticket removalWhen login sessions are shared across domains, it can be helpful to log users out of all domains when they log out of a Plone site.
Load the pseudo CSShttp://example.com/portal_path/acl_users/session/remove?type=csson the/logged_outpage for ticket removal.Single Sign On with IISFor intranet setups with users on a Windows domain, it’s possible to configure IIS withIntegrated Windows Authenticationto act as an external login provider, even for sites running on Linux/Unix servers.RequirementsYou need a Microsoft Windows Server running IIS.
Preferably Windows Server 2003 or a later version.The server must be a member of the Windows domain you want to authenticate users for.
It does not need to be an Active Directory server itself.You site should usepas.plugins.ldapto use the same Active Directory as a user source.PythonThe Windows server needs to havePython 2.7and thePython Win 32 extensions build >=216installed.Place a copy oftktauth.py(from plone/session of this package) into:C:\Python26\Lib\site-packages\Follow theseinstructions on how to configure Python for IIS.
In bullet point 2.d. use:Executable: "C:\Python27\python.exe -u %s %s"instead.
This will ensure files are opened in universal newline mode.
You can choose to only configure these settings for the specific web site and not the entire IIS.
Adjust settings accordingly and create the web site first as detailed in the next chapter.IISFind and open the IIS management console.Create a newWeb Site, by going into theWeb Sitesfolder and using the right-click menu.
You should get a wizard asking you for various questions:Description: SSO login service

TCP port: 80

Path: c:\Inetpub\sso

Allow anonymous access to this Web site: <not checked>

Permissions: Read, Run scripts, ExecuteIf you are running IIS 6, you need to go to theWeb Service Extensionsfolder and changeActive Server Pagesto beAllowed.
Otherwise you will get rather unhelpful404 Not Founderrors for the asp scripts.IIS scriptCopy thelogin.aspandtest.aspscripts (from the iis-login folder of this package) into root path of the web site (for example C:Inetpubsso).You need to modify theSECRETconstant found in thelogin.aspto the same shared secret set onplone.session’sManage secretstab.Modify theALLOWED_SITESconstant inlogin.aspto include the URLs of your Plone sites.Modify theDEFAULT_NEXTconstant inlogin.aspto refer the the URL oflogged_inon one of your Plone sites.Accesshttp://LOGONSERVER/test.aspto confirm access permissions are correctly configured.Configuring browsers to allow automatic logonBrowsers must be configured totrustthe logon server for user authentication data to be sent automatically.By default, Internet Explorer sends logon information to servers within theIntranet Zone, so long as the site is accessed using it’s intranet name (http://LOGONSERVER/login.asp).
If the site is accessed using a fully qualified domain name or IP address, it must be explicitly added to the list oftrusted sites.Firefox configuration information may be found in thisarticle.Configuring your Plone siteEnsure that you have setup authentication to Active Directory and that you can login with the your current Windows user name.Set the following configuration options through the Zope interface:In/Plone/acl_users/session. On theManage secretstab set a shared secret.In/Plone/portal_properties/site_propertiessetexternal_login_urltohttp://LOGONSERVER/login.asp.In/Plone/portal_properties/site_propertiessetexternal_login_iframeto true.Note for developers testing this under Windows XPIIS may be installed as an additional component using the Windows XP installation CD.The IIS management console can be located at:Start -> Control Panel -> Administrative Tools -> Internet Information ServicesThe pywin32 installer setup IIS sufficiently for me not to need to follow theinstructions on how to configure Python for IIS.I could not find how to setup a separate site, so placed the asp scripts directly inC:\Inetpub\wwwroot- theDefault Web SiteFrom the IIS management console, select “Default Web Site”.
You should seelogin.aspandtest.aspin the right hand pane.
With each file, right-click Properties.
On theFile Securitytab click Edit… onAnonymous access and authentication control.
UncheckAnonymous accessand checkBasic authentication(to be used as a fallback) andIntegrated Windows authentication.Accesshttp://localhost/test.aspto confirm IIS authentication works as expected.Set the secret inlogin.aspandManage secretsofplone.session.Set SITE_URL inlogin.asptohttp://localhost:8080/Plone(or whatever the address of your site is).Add a Plone user with the same name as your Windows login name (e.g.Administrator), this avoids setting up Active Directory.Follow the section above to configure your Plone site, but setLogin Formtohttp://localhost/login.asp.Changelog4.0.4 (2023-09-08)Bug fixes:Do not set an auth cookie after password reset, unless the user is authenticated.
Otherwise anonymous users will be logged in immediately, even when autologin after password reset is false.
Fixesissue 3835.
[maurits] (#3835)Internal:Update configuration files.
[plone devs] (7723aeaf)4.0.3 (2023-03-21)Bug fixes:Remove circular dependency on Products.CMFPlone. Use moved imports from plone.base instead.
[jensens] (#38)Internal:Update configuration files.
[plone devs] (a533099d)4.0.2 (2023-02-07)Bug fixes:Declare all dependencies.
[gforcada] (#1)4.0.1 (2023-01-30)Internal:Update code to current Plone meta standards.
[gforcada, maurits] (#1)4.0.0 (2022-12-02)Bug fixes:Final release for Plone 6.0.0 (#600)4.0.0b2 (2022-08-31)New features:Creating per-user keyrings in order to have session invalidation on log-out (server-side logout). [david-batranu] (#26)Cookie attribute SameSite is set to “Lax”. (#29)4.0.0b1 (2022-07-22)Bug fixes:Update the plone-session bundle to depend on the plone bundle instead of the jquery bundle, which no longer exists.
[davisagli] (#27)4.0.0a1 (2022-04-08)Breaking changes:Register single resource bundle for Plone 6 for our optional refresh support.
An upgrade step for this is in plone.app.upgrade, otherwise we leave partial bundles behind.
Removed our own upgrade step and profile, as they are not needed when migrating from Plone 5.2.
[maurits] (#24)3.7.5 (2020-06-24)Bug fixes:Fix hard dependency indirection with Products.CMFPlone (plone.session must not import from it).
[jensens] (#20)Only setup a session when the current user is the requested user.
[maurits] (#57)3.7.4 (2020-04-22)Bug fixes:Minor packaging updates. (#1)3.7.3 (2019-04-29)Bug fixes:Fix nameclash resulting in ImportWarning by renamingprofiles.pytohiddenprofiles.py. [jensens] (#16)3.7.2 (2019-02-13)Bug fixes:Remove last traces of ZopeTestCase. [gforcada] (#14)3.7.1 (2018-09-28)Bug fixes:Python3 compatibility [ale-rt, pbauer]3.7.0 (2018-04-03)New features:Use Resource Registry for JS/CSS registration
[jensens]Bug fixes:Fixes #11: Pseudo CSS-file is not loaded anymore in merged legacy bundle.
Now optional JS based auto-refresh support is working again.
[jensens]Modernize README.
[jensens]3.6.2 (2018-02-02)Bug fixes:Hardening default timeout of session.
This solves Plone security internal issue #126 (severity low, non-critical).
Session timeout is now the same as in mod_auth_tkt: 2h.
This follows the recommendation of the German BSI (federal office for security in the information technology).
Seehttps://www.bsi.bund.de/SharedDocs/Downloads/DE/BSI/Internetsicherheit/isi_web_server_checkliste_Plone.pdfFor existing sites this can be adjusted athttps://HOST/acl_users/session/manage_propertiesFormThe Plone Security Team follows the BSI and recommends administrators to change the setting in their existing Plone sites.
[jensens]Add Python 2 / 3 compatibility
[vincero]3.6.1 (2016-12-02)Bug fixes:Hide uninstall profile in install listings.
[jensens]3.6.0 (2016-05-26)New:Added uninstall profile.  [maurits]3.5.6 (2015-07-27)Cleanup: Pep8, plone style conventions, better readbility.
[jensens]3.5.5 (2015-04-29)Default encoding for createTicket to be compatible with unicode
user_id [puittenbroek]3.5.4 (2015-03-21)Move tests from PloneTestCase to plone.app.testing.
[tomgross]3.5.3 (2013-03-05)Revert accidental change to default encoding for validateTicket.
[davisagli]3.5.2 (2012-12-09)Use constant time comparison when validating tickets. This is part of the fix
forhttps://plone.org/products/plone/security/advisories/20121106/23[davisagli]3.5.1 - 2012-11-02Handle encoded strings for userids.
[elro]Add MANIFEST.in.
[WouterVH]Fix for Python 2.4 under 64bit Mac OS generating incorrect mod_auth_tkt
digests
[MatthewWilkes]3.5 - 2011-03-19Disable secure cookie in development mode, to ease local testing.
[hannosch]3.4 - 2011-03-02Added metadata.xml to the default profile.
[vincentfretin]3.3 - 2010-12-30Update login.asp to match Plone 4.1 SSO login form functionality.
[elro]Fix remove.
[elro]3.2 - 2010-12-14Removeexternal_loginmethod, the normallogged_inscript can be
used instead.
[elro]Fix refresh.
[elro]3.1 - 2010-11-11RemoveSessionPlugin.validate(ticket)method, it was not required.
[elro]3.1b1 - 2010-10-18Session refresh.
[elro]SessionPlugin.validate(ticket)method.
[elro]Close <input> tags properly (chameleon compatibility)
[swampmonkey]3.0 - 2010-07-18Update package metadata.
[hannosch]3.0b5 - 2010-06-13Make sure to load the right meta ZCML.
[hannosch]Avoid deprecation warnings under Zope 2.13.
[hannosch]Removed dependency on GPL licensed Products.PloneTestCase.
[hannosch]3.0b4 - 2010-05-23Make thesecureoption of cookies configurable. This allows to restrict
cookies to HTTPS connections alone. This closeshttp://dev.plone.org/plone/ticket/7897.
[pfurman, hannosch]Use the standard libraries doctest module, instead of the deprecated one
from zope.testing.
[hannosch]Marked the session cookie asHTTPOnly.
[hannosch]PEP8 cleanup.
[hannosch]Relicense as BSD following PF Board decision.http://lists.plone.org/pipermail/membership/2010-April/001123.html[elro]3.0b3 - 2010-04-09Example IIS login form and documentation. This builds on work by Hanno and I
at Jarn for Centrepoint.
[elro]Support authentication by an external form, perhaps one running on an IIS
server with Integrated Windows Authentication.
[elro]3.0b2 - 2010-03-09Prefix setupSession with underscore, the method should be unavailable TTW.
[elro]Catch a ComponentLookupError in authenticateCredentials.
[elro]3.0b1 - 2010-03-05Add back the hash management UI with added functionality to set shared
secret.
[elro]Add properties for cookie domain and ticket validity timeout.
[elro]Use mod_auth_tkt format cookies to give us a session validity timeout.
By default we use a more secure HMAC SHA-256 hashing scheme. An MD5 based
scheme compatible with other mod_auth_tkt implementations is optional.
[elro]Remove the source component indirection.
[elro]3.0a2 - 2009-11-13Remove hash management UI which had been accidentally re-merged.
[davisagli]3.0a1 - 2009-04-04Avoid deprecation warning for the sha module in Python 2.6.
[hannosch]Declare test dependencies in an extra.
[hannosch]Specify package dependencies.
[hannosch]Fixed the remaining tests to work with the new keyring backend.
[hannosch]Fixed a component lookup call in the HashSession source.
[davisagli, hannosch]Update default (hash) session source to use plone.keyring to manage the secrets.
[wichert]2.1 - 2009-02-04Protect the setupSession call with the ManageUsers permission.
Fixes possible privilege escalation.
[maurits]Make the cookie lifetime configurable. Patch by Rok Garbas.
Fixeshttp://dev.plone.org/plone/ticket/7248[wichert, garbas]2.0 - 2008-07-08Fix CSRF protection for managing server secrets via the Plone session
plugin for PAS. Fixeshttp://dev.plone.org/plone/ticket/8176[witsch]1.2 - 2007-02-15Use the binascii base64 methods to encode/decode the session cookie. This
prevents newlines being inserted in long cookies.
[wichert]1.1 - 2007-09-11Use the userid instead of the login name in session identifiers. This has the
side-effect of working around a bug in PAS which caused us to mix up users when
the login name used was an inexact match for another login name.
[wichert]1.0 - 2007-08-15First stable release
[wichert]