diff options
| author | jvoisin | 2017-09-29 17:17:54 +0200 |
|---|---|---|
| committer | GitHub | 2017-09-29 17:17:54 +0200 |
| commit | b5628fcc599919711171a5154f37ad90bd6b5065 (patch) | |
| tree | 545766f8293039a6df41ffacf4fa5f51d09698a6 /src/sp_cookie_encryption.c | |
| parent | e010aadf08350a242527a0a98a3b67fe25607b98 (diff) | |
Fix two cookie encryption issues found by @cfreal, and a bonus one (#18)
* Fix a cookie encryption issue found by @cfreal
- Use the base64-decoded payload length to allocate memory to decrypt
it, instead of allocating the length of the undecoded one. This has
no security impact, since the base64-encoded string is at least as large
as the decoded one. Since we're using AEAD, there is no way to leak
memory, since this would make the decryption fail.
Diffstat (limited to 'src/sp_cookie_encryption.c')
| -rw-r--r-- | src/sp_cookie_encryption.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/sp_cookie_encryption.c b/src/sp_cookie_encryption.c index ad8438a..a47f6e1 100644 --- a/src/sp_cookie_encryption.c +++ b/src/sp_cookie_encryption.c | |||
| @@ -61,14 +61,14 @@ int decrypt_cookie(zval *pDest, int num_args, va_list args, | |||
| 61 | 61 | ||
| 62 | debase64 = php_base64_decode((unsigned char *)(Z_STRVAL_P(pDest)), value_len); | 62 | debase64 = php_base64_decode((unsigned char *)(Z_STRVAL_P(pDest)), value_len); |
| 63 | 63 | ||
| 64 | if (value_len < | 64 | if (ZSTR_LEN(debase64) < |
| 65 | crypto_secretbox_NONCEBYTES + crypto_secretbox_ZEROBYTES) { | 65 | crypto_secretbox_NONCEBYTES + crypto_secretbox_ZEROBYTES) { |
| 66 | sp_log_msg("cookie_encryption", SP_LOG_DROP, | 66 | sp_log_msg("cookie_encryption", SP_LOG_DROP, |
| 67 | "Buffer underflow tentative detected in cookie encryption handling."); | 67 | "Buffer underflow tentative detected in cookie encryption handling."); |
| 68 | return ZEND_HASH_APPLY_REMOVE; | 68 | return ZEND_HASH_APPLY_REMOVE; |
| 69 | } | 69 | } |
| 70 | 70 | ||
| 71 | decrypted = pecalloc(value_len, 1, 0); | 71 | decrypted = pecalloc(ZSTR_LEN(debase64), 1, 0); |
| 72 | 72 | ||
| 73 | ret = crypto_secretbox_open( | 73 | ret = crypto_secretbox_open( |
| 74 | decrypted, | 74 | decrypted, |
