Commit 8cc23dd
committed
feat: v2.0.0 — RFC 7231 timestamps, OpenSSL 3.x, 14 bug fixes, full test suite
Add RFC 7231/IMF-fixdate and ISO 8601 'Z' suffix timestamp parsing, port
HMAC computation to the OpenSSL 3.0 EVP_MAC API, fix 14 correctness and
safety bugs found during code review, and add a full Perl test suite with
CI.
--- Timestamp parsing ---
* Add ISO 8601 UTC 'Z' suffix support ("YYYY-MM-DDThh:mm:ssZ").
Previously fell through to the Unix branch and was silently misread.
* Add RFC 7231 / IMF-fixdate support ("Day, DD Mon YYYY hh:mm:ss GMT"),
including case-insensitive month-name lookup (RFC 7231 §7.1.1.1).
* Fix RFC 7231 internal-comma bug: the embedded comma in "Sun, 06 Nov …"
was previously mistaken for the field separator when an expiry field was
also present, leaving only a 3-byte substring for the timestamp parser.
Now detected and skipped before searching for the next field boundary.
* Extract ngx_http_secure_link_gauss() with calendar-field range checks
(year ≥ 1970, month 1–12, mday 1–31, hour 0–23, min 0–59, sec 0–60).
* Extract ngx_http_secure_link_parse_ts() to centralise all four format
branches; returns (time_t)-1 on any parse or range failure.
--- Security / correctness ---
* Fix Y2038 overflow: "365 * year" was int×int; large dates overflowed
before the (time_t) cast. Fixed: (time_t)year * 365 promotes all Gauss
arithmetic to the wider type.
* Fix strict Unix timestamp validation: replaced sscanf "%llu" fallback
(which accepted any digit-leading string) with a digit-only byte scan
followed by ngx_atotm(). Prevents ISO 8601 year-only values (e.g. "2025")
from being silently accepted.
* Fix size_t/unsigned-int mismatch in token variable handler: passing
(u_int*)&hmac.len to HMAC() wrote only 4 of 8 bytes on LP64; on
big-endian the written bytes were in the wrong half. Use a local
unsigned int hmac_len instead.
* Fix $secure_link_hmac_expires returning token bytes: ctx->expires was
set to value.data/len after value had been trimmed to the token. Now
points to the actual expiry-period substring.
* Fix EVP_MD_size() not checked: OpenSSL 3.0 returns -1 on error; the
unchecked cast to u_int produced a huge length passed to CRYPTO_memcmp.
* Fix GMT-offset sign: two independent `if` statements replaced with
if/else if/else so an unexpected sign character cannot silently apply
no offset.
--- OpenSSL compatibility ---
* Wrap HMAC computation in ngx_http_secure_link_hmac_compute():
uses EVP_MAC on OpenSSL >= 3.0 (no deprecation warning), HMAC() on 1.x.
* NGX_HMAC_MD_SIZE macro wraps EVP_MD_size (1.x) / EVP_MD_get_size (3.x).
* Add key.len overflow guard before narrowing size_t to int for HMAC().
--- Code quality ---
* Remove incorrect (ngx_tm_*_t*) casts from sscanf calls; plain int* is
correct for %d and portable across all platforms.
* Change %02d to %2d in all sscanf format strings (the '0' flag is a
printf-only concept; silently ignored by scanf).
* Fix debug log timestamp width: was hardcoded to 25 bytes; now uses the
actual substring length (int)(ts_end - ts_start).
* Move gmtoff, var, i to inner scopes (cppcheck --enable=all, zero warnings).
* Declare parse_ts ts_last parameter const (cppcheck constParameterPointer).
--- Documentation ---
* Replace verbose BUGS FIXED header block with a concise changelog;
rationale lives in CHANGELOG.md and the commit history.
* Document that the field separator in secure_link_hmac is always a comma
(hardcoded) and the separator in secure_link_hmac_message is freely
chosen by the operator (pipe, colon, slash, none, …).
* Document all three embedded variables ($secure_link_hmac,
$secure_link_hmac_expires, $secure_link_hmac_token) with their exact
possible values and evaluation ordering requirements.
* Add RFC 7231 client examples in PHP (gmdate), Node.js (toUTCString),
and Python (isoformat + Z suffix).
* Expand Security Notes with separator guidance and URL-encoding rules.
--- Testing and CI ---
* Add t/hmac_secure_link.t: 66 Test::Nginx::Socket tests across 10
categories (basic HMAC, Unix/ISO 8601/RFC 7231 timestamps, algorithms,
variable values, separators, config edge cases, access-control patterns).
* Add t/lib/HmacSecureLink.pm: shared token generators, timestamp
formatters, TS_FIXED constant (eliminates timing-race in token tests).
* Add .github/workflows/ci.yml.
* Add Makefile with build, test, test-syntax, lint, cpan-deps targets.
* Add CHANGELOG.md.1 parent 60893da commit 8cc23dd
12 files changed
Lines changed: 3267 additions & 225 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 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 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 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 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
0 commit comments