Skip to content

docs(security): verify the parsing-and-validation page - #321

Merged
homer6 merged 2 commits into
devfrom
security/294-parsing
Nov 3, 2026
Merged

homer6 merged 2 commits into
devfrom
security/294-parsing

Conversation

@homer6

@homer6 homer6 commented Nov 3, 2026

Copy link
Copy Markdown
Owner

Verifies docs/security/parsing-and-validation.md (#294). Stacked on #320.

What the page now says

  • Mental model: the parser as the most exposed code. Size limits → grammar → range/structure checks → typed values → authorize → act; each stage rejects, none repairs.
  • Parse into constrained values (SL.io.2; CERT ERR62-CPP): parse_port with from_chars, checking the error, full consumption and the domain. from_chars rejects +, leading whitespace and - for unsigned.
  • Define the ambiguous cases: trailing data, duplicates, unknown values, versions, encodings, embedded NUL, inconsistent lengths. An example rejects duplicate headers rather than first-wins or last-wins.
  • Never let input become code (CERT FIO30-C): a compile-fail std::format(user_text), which both compilers reject because the format string must be a constant, plus the right form. runtime_format/vformat only for program-controlled strings. The same rule for SQL and processes.
  • Bound the parser's work: depth, counts, decoded size. A depth-bounded parser example. std::regex cautions: ReDoS, and libstdc++ before GCC 16 recursing on long input (GCC bug 86164, made iterative in GCC 16 by r16-7193). Mature parsers, tracked.

Tests: tests/security/parsing-and-validation_test.cpp, 5 tests:

  • parse_port against 11 inputs, including an embedded NUL, signs, whitespace, overflow and the domain edges;
  • duplicate fields are rejected;
  • hostile braces passed as a format argument are printed verbatim;
  • a runtime format string with a bad spec throws format_error;
  • nesting depth is bounded, and malformed input is rejected.

Tested

  • security area: gcc-15 36/36, clang-22 36/36.
  • Snippets: GCC 15 and Clang 22, 5 checked, 0 failed. The compile-fail pattern covers both compilers' consteval wording.
  • Links and index checks pass.

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

Related to #294, #286

@homer6
homer6 force-pushed the security/293-object-representation branch from 11ecf8f to b8810a8 Compare November 3, 2026 12:23
@homer6
homer6 force-pushed the security/294-parsing branch from b92c5e5 to b1b6853 Compare November 3, 2026 12:23
@homer6
homer6 changed the base branch from security/293-object-representation to dev November 3, 2026 12:47
@homer6
homer6 merged commit a1c2cde into dev Nov 3, 2026
@homer6
homer6 deleted the security/294-parsing branch November 3, 2026 12:48
@homer6

homer6 commented Nov 3, 2026

Copy link
Copy Markdown
Owner Author

Merged into dev as a merge commit (a1c2cde) 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