CKTIS / C++
Security boundaries in C++
A security boundary separates data or code with different levels of trust. In C++, private access control must not be confused with execution isolation: validating data before use is a separate responsibility, and undefined behavior does not guarantee safe program termination.
Version: C++23; repository compiler flag, production runtime not attested
Syntax
#include <utility>
if (index < 0 || std::cmp_greater_equal(index, values.size())) { /* reject */ }Security boundaries (security boundaries) identify places where data or requests need checking before they can reach protected operations. When designing a boundary, identify what is untrusted, which resource you protect, and which conditions must hold. An argument having the correct type does not mean that its value is permitted.
Access control through private and protected restricts naming class members in C++ code; it is not a mechanism for user authorization or execution isolation. The design implication is: do not treat a class as a barrier against hostile code running in the same program. Separate interface rules from requirements for actual isolation.
The example checks an index before reading from values. It first rejects negative values. The || operator skips its right operand when its left operand is true. Otherwise, std::cmp_greater_equal compares the int index directly with the array size without first converting the index to std::size_t. Only after the check passes does the code explicitly convert the index to std::size_t to access the array element. Index 1 produces 20; indices -1 and 3 are rejected. Range validation does not replace a separate check of permission to access the data.
Undefined behavior means that the standard imposes no requirements on program behavior; therefore, do not assume that an error will result in controlled rejection of a request. This entry targets C++23, but the supplied standard URL contains an evolving draft, not a frozen C++23 publication. The displayed example source was run unchanged in an isolated environment. A repository compiler flag does not attest the production runtime.
Examples
#include <array>
#include <cstddef>
#include <initializer_list>
#include <iostream>
#include <utility>
int main() {
const std::array<int, 3> values{10, 20, 30};
for (int index : {1, -1, 3}) {
if (index < 0 || std::cmp_greater_equal(index, values.size())) {
std::cout << "rejected\n";
continue;
}
std::cout << values[static_cast<std::size_t>(index)] << '\n';
}
}
Result
20 rejected rejected
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.