Skip to content

Commit 407df95

Browse files
Detail the serialization hardening convention
1 parent 61eb22b commit 407df95

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

‎AGENTS.md‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,14 @@
1414
`\z`; a bare `$` accepts a trailing newline.
1515
- Never embed raw control bytes in exception messages and other diagnostics;
1616
escape or redact the offending value first.
17-
- Classes holding streams, resources, or callbacks reject native PHP
18-
serialization, and refusal messages report the class name with
19-
`static::class`.
17+
- Classes holding streams, resources, handles, callbacks, or credentials reject
18+
native PHP serialization so they cannot join object-injection gadget chains:
19+
`__serialize()` and `__unserialize()` both throw
20+
`\LogicException(static::class.' should never be serialized')` and its
21+
unserialized counterpart, usually via the repo's `@internal` non-serializable
22+
trait. Guards that protect a `__destruct()` gadget also neutralize the
23+
dangerous state before throwing, so the protection holds even if the exception
24+
is swallowed.
2025
- In general, numeric inputs should not accept non-finite floats. In situations
2126
where they are accepted and we need to cast to a string, we should branch on
2227
`\is_finite($value)`, using `(string) $value` for the finite case and

0 commit comments

Comments
 (0)