Раздел 10. Apache modules Пункты: 85 86 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 163 164 165 166 167 168 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 203 204 205 206 207 208 209 210 211 212 213 RU EN Пункт 189. Apache Module mod_session
SummaryWarningThe session modules make use of HTTP cookies, and as such can fall victim to Cross Site Scripting attacks, or expose potentially private information to clients. Please ensure that the relevant risks have been taken into account before enabling the session functionality on your server. This module provides support for a server wide per user session interface. Sessions can be used for keeping track of whether a user has been logged in, or for other per user information that should be kept available across requests. Sessions may be stored on the server, or may be stored on the
browser. Sessions may also be optionally encrypted for added security.
These features are divided into several modules in addition to
Sessions may be manipulated from other modules that depend on the session, or the session may be read from and written to using environment variables and HTTP headers, as appropriate. What is a session?At the core of the session interface is a table of key and value pairs that are made accessible across browser requests. These pairs can be set to any valid string, as needed by the application making use of the session. The "session" is a application/x-www-form-urlencoded string containing these key value pairs, as defined by the HTML specification. The session can optionally be encrypted and base64 encoded before being written to the storage mechanism, as defined by the administrator. Who can use a session?The session interface is primarily developed for the use by other
server modules, such as Keeping sessions on the serverApache can be configured to keep track of per user sessions stored on a particular server or group of servers. This functionality is similar to the sessions available in typical application servers. If configured, sessions are tracked through the use of a session ID that is stored inside a cookie, or extracted from the parameters embedded within the URL query string, as found in a typical GET request. As the contents of the session are stored exclusively on the server, there is an expectation of privacy of the contents of the session. This does have performance and resource implications should a large number of sessions be present, or where a large number of webservers have to share sessions with one another. The Keeping sessions on the browserIn high traffic environments where keeping track of a session on a server is too resource intensive or inconvenient, the option exists to store the contents of the session within a cookie on the client browser instead. This has the advantage that minimal resources are required on the server to keep track of sessions, and multiple servers within a server farm have no need to share session information. The contents of the session however are exposed to the client, with a
corresponding risk of a loss of privacy. The
The Basic ExamplesCreating a session is as simple as turning the session on, and deciding
where the session will be stored. In this example, the session will be
stored on the browser, in a cookie called Browser based sessionSession On SessionCookieName session path=/ The session is not useful unless it can be written to or read from. The
following example shows how values can be injected into the session through
the use of a predetermined HTTP response header called
Writing to a sessionSession On SessionCookieName session path=/ SessionHeader X-Replace-Session The header should contain name value pairs expressed in the same format as a query string in a URL, as in the example below. Setting a key to the empty string has the effect of removing that key from the session. CGI to write to a session#!/bin/bash echo "Content-Type: text/plain" echo "X-Replace-Session: key1=foo&key2=&key3=bar" echo env If configured, the session can be read back from the HTTP_SESSION
environment variable. By default, the session is kept private, so this
has to be explicitly turned on with the
Read from a sessionSession On SessionEnv On SessionCookieName session path=/ SessionHeader X-Replace-Session Once read, the CGI variable Session PrivacyUsing the "show cookies" feature of your browser, you would have seen a clear text representation of the session. This could potentially be a problem should the end user need to be kept unaware of the contents of the session, or where a third party could gain unauthorised access to the data within the session. The contents of the session can be optionally encrypted before being
placed on the browser using the Browser based encrypted sessionSession On SessionCryptoPassphrase secret SessionCookieName session path=/ The session will be automatically decrypted on load, and encrypted on save by Apache, the underlying application using the session need have no knowledge that encryption is taking place. Sessions stored on the server rather than on the browser can also be
encrypted as needed, offering privacy where potentially sensitive
information is being shared between webservers in a server farm using
the Cookie PrivacyThe HTTP cookie mechanism also offers privacy features, such as the ability to restrict cookie transport to SSL protected pages only, or to prevent browser based javascript from gaining access to the contents of the cookie. WarningSome of the HTTP cookie privacy features are either non-standard, or
are not implemented consistently across browsers. The session modules
allow you to set cookie parameters, but it makes no guarantee that privacy
will be respected by the browser. If security is a concern, use the
Standard cookie parameters can be specified after the name of the cookie, as in the example below. Setting cookie parametersSession On SessionCryptoPassphrase secret SessionCookieName session path=/private;domain=example.com;httponly;secure; In cases where the Apache server forms the frontend for backend origin servers,
it is possible to have the session cookies removed from the incoming HTTP headers using
the Session Support for AuthenticationAs is possible within many application servers, authentication modules can use
a session for storing the username and password after login. The
Form based authenticationSession On SessionCryptoPassphrase secret SessionCookieName session path=/ AuthFormProvider file AuthUserFile "conf/passwd" AuthType form AuthName realm #... See the Integrating Sessions with External ApplicationsIn order for sessions to be useful, it must be possible to share the contents of a session with external applications, and it must be possible for an external application to write a session of its own. A typical example might be an application that changes a user's password set by
A second example might involve an application that registers a new user for the first time. When registration is complete, the username and password is written to the session, providing a seamless transition to being logged in.
Session Directive
The SessionEnv Directive
If set to On, the The string is written in the URL query format, for example: SessionExclude Directive
The WarningThis directive has a similar purpose to the path attribute in HTTP cookies, but should not be confused with this attribute. This directive does not set the path attribute, which must be configured separately. SessionHeader Directive
The The header value is expected to be in the URL query format, for example: Where a key is set to the empty string, that key will be removed from the session. SessionInclude Directive
The WarningThis directive has a similar purpose to the path attribute in HTTP cookies, but should not be confused with this attribute. This directive does not set the path attribute, which must be configured separately. SessionMaxAge Directive
The Setting the maxage to zero disables session expiry. Пункты: 85 86 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 163 164 165 166 167 168 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 203 204 205 206 207 208 209 210 211 212 213 |