Skip to content

docs(security): verify the object-representation page - #320

Merged
homer6 merged 2 commits into
devfrom
security/293-object-representation
Nov 3, 2026
Merged

homer6 merged 2 commits into
devfrom
security/293-object-representation

Conversation

@homer6

@homer6 homer6 commented Nov 3, 2026

Copy link
Copy Markdown
Owner

Verifies docs/security/object-representation.md (#293). Stacked on #319.

What the page now says

  • Mental model: three ways representation becomes attack surface: uninitialized state, raw object bytes across a boundary, and casts that skip checks.
  • Initialize before use (ES.20, Type.5, Type.6, C.41; CERT EXP53-CPP): a bad session whose authenticated flag is indeterminate, and the fixed version with deny-by-default member initializers. -ftrivial-auto-var-init=zero (both our compilers accept it) and C++26 erroneous behaviour are defence in depth, not the fix.
  • Serialize field by field (CERT DCL55-CPP, DCL39-C, EXP62-CPP): a bad memcpy of a padded header. std::has_unique_object_representations_v detects the padding (static_assert in the example). An explicit little-endian wire encoding. Decode field by field with range checks.
  • Confine casts that skip type checks (Type.1–Type.4, Type.7, ES.48, ES.49, C.146–C.148; CERT EXP39-C): a bad run static_cast downcast to the wrong message type, caught by ASan as stack-buffer-overflow, and the dynamic_cast fix. bit_cast, endian and byteswap for representation work.

Tests: tests/security/object-representation_test.cpp, 5 tests:

  • default member initializers deny;
  • padding is detected by the trait (and absent in a padding-free struct);
  • the field-by-field encoding is exact, with no padding on the wire;
  • dynamic_cast rejects the wrong message type;
  • bit_cast copies bits.

Tested

  • security area: gcc-15 31/31, clang-22 31/31.
  • Snippets: GCC 15 and Clang 22, 6 checked, 0 failed. On Clang the bad run block was caught.
  • Links and index checks pass.

Status: verified. README.md and CLAUDE.md need no change.

Related to #293, #286

@homer6
homer6 force-pushed the security/293-object-representation branch from 11ecf8f to b8810a8 Compare November 3, 2026 12:23
@homer6
homer6 changed the base branch from security/292-integers to dev November 3, 2026 12:45
@homer6
homer6 merged commit 24990c0 into dev Nov 3, 2026
@homer6
homer6 deleted the security/293-object-representation branch November 3, 2026 12:47
@homer6

homer6 commented Nov 3, 2026

Copy link
Copy Markdown
Owner Author

Merged into dev as a merge commit (24990c0) on the owner's review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant