# RFC: Secure Session Options

- Status: Inactive
- Authors: Yasuo Ohgaki, yohgaki@ohgaki.net
- Date: 2014-02-01
- Version: 0.11
- Original: https://wiki.php.net/rfc/secure-session-options-by-default
- Page: https://externals.io/rfc/secure-session-options-by-default
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

## Votes

### Secure Session Module Options by Default (closed)

Yes: 0 · No: 0

## Discussions on the mailing list

- [\[RFC\] Secure Session Module Options by Default](https://externals.io/message/71949.md) — started on 2014-02-01, 17 messages
- [\[VOTE\] Secure Session Module Options/Internal by Default](https://externals.io/message/72643.md) — started on 2014-02-17, 9 messages

---

## Introduction

HTTP session management is core of Web security. Current default of session module options are weaker than it could be. Secure values by default would be better.

## Proposal

Secure setting should be the default and user should selectively use weaker setting.

**use\_strict\_mode=on** disallow user supplied session ID and improve session ID security. Most applications work with this option.

**cookie\_httponly=on** disallow use of session ID cookie from JavaScript. It reduces risk of stolen session ID via JavaScript injections. Most applications work with this option.

**hash\_function=“sha256”** SHA-256 has larger bits than SHA-1/MD5. (256 bits vs 160/128 bits) More difficult to guess. i.e. Birthday attack. With stronger hash,[collision is less likely](http://preshing.com/20110504/hash-collision-probabilities/).

NIST [suggests](http://csrc.nist.gov/groups/ST/hash/policy_2006.html) not to use SHA-1 for “applications that require collision resistance as soon as practical, and must use the SHA-2 family of hash functions for these applications after 2010.” Files save handler detects session ID collision (PHP 5.5 and later). Therefore it is out of NIST requirement scope for small sites, but collision detection is up to save handlers.

“sha256” is Hash extension function. Hash extension is built by default, but “sha256” could be unavailable. Session module raises E\_ERROR if Hash extension is unavailable.

**entropy\_length=64** entropy\_lengh=32 is too short for SHA-256. Default to 64.

## Backward Incompatible Changes

use\_strict\_mode=on: Do not accept user provided session ID. User may send obsolete and/or attacker provided session ID. This prevents these invalid session ID. Applications that assume certain session ID for data sharing/etc would not work with strict mode. Users may turn off at their own risks.

cookie\_httponly=on: JavaScript cannot access session ID cookie. Even when web app has JavaScript injection vulnerability, session ID cannot be stolen. JavaScript injection vulnerability is the most common issue of web apps. Applications that uses session ID as CSRF protection key would be affected. However, use of session ID as CSRF key is bad practice. Session ID could be stolen by BREACH attack even with HTTPS, for example.

hash\_function=“sha256”: Longer session ID string. NIST suggests to use SHA-2 or stronger hash for security related features. If session database has limited storage, session ID cannot be stored. Users should use weaker hash or modify database schema in this case. Hash extension could be unavailable. If “sha256” is not usable (not compiled or compiled as DL module), E\_ERROR is raised and script stops.

## Proposed PHP Version(s)

PHP 5.x+

## Impact to Existing Extensions

Session module

## php.ini Defaults

- hardcoded default values
- php.ini-development values
- php.ini-production values

use\_strict\_mode=on, cookie\_httponly=on, hash\_function=sha256, entropy\_length=64 for all

## Open Issues

## Future Scope

- When use of HTTPS becomes dominant, session.cookie\_secure=on should be used.
- Build ext/hash always. If SHA-256(Hash extension which is built by default) is not available, session raises E\_ERROR for it.
- **Detect collision via PS\_VALIDATE\_FUNC()** When session ID is generated, collision could be checked by PS\_VALIDATE\_FUNC() if it is available. Check collision in session module instead of save handler module. (Easier use\_strict\_mode adoption)

## Proposed Voting Choices

Yes/No

## VOTE

VOTE: 2014/XX/XX - 2014/XX/XX

**Vote: Secure Session Module Options by Default** — Yes: 0 · No: 0 (closed)

Thank you for voting!

## Implementation

After the project is implemented, this section should contain

1. the version(s) it was merged to
2. a link to the git commit(s)
3. a link to the PHP manual entry for the feature

## References

1. <https://externals.io/rfc/session-lock-ini>
2. Collision probability - <http://preshing.com/20110504/hash-collision-probabilities/>
3. NIST advises not to use SHA-1 - [http://csrc.nist.gov/groups/ST/hash/policy\_2006.html](http://csrc.nist.gov/groups/ST/hash/policy_2006.html)

## Rejected Features

Keep this updated with features that were discussed on the mail lists.
