Synthetic secure-development scenario
Up-to-date technology is not enough for a secure integration
An educational scenario about trust in third-party components, content rendering, and testing beyond the happy path.
- TypeScript
- DOM
- AppSec
- Threat modeling
The engineering problem
An application uses a current framework and updated dependencies. It integrates a vendor component to display notices. The API responds and the UI works: the functional test passes. Yet an external field can cross the integration boundary and be interpreted as HTML instead of text.
Keeping dependencies updated remains necessary. An update does not decide which data is trusted, which permissions an integration receives, or how a value is rendered. Those are application design and implementation decisions.
This fictional scenario draws on lessons from authorized research. It does not reproduce vendor code, assets, parameters, credentials, or an exploitation sequence from a real system.
Where trust changes
The educational flow is: notice-service response → contract validation → UI component → DOM. A message field is product text; it does not need arbitrary formatting. Interpreting it as HTML adds a capability the requirement did not request.
Review must follow the value to the code that actually renders it. The main component may use safe interpolation while an SDK, wrapper, or plugin does something else. The framework name alone does not establish that this path is safe.
Decision and minimal example
In this example, the contract accepts only a bounded text message. The renderer uses textContent. The received object is not merged into privileged configuration. Type validation enforces the contract; the rendering choice prevents interpreting the content as markup.
If HTML is required, that becomes a separate product and security decision: define an allowed subset and use appropriate sanitization. The example below intentionally accepts only text.
What to test before integrating
Positive control: an ordinary message must appear. Markup must appear literally without creating elements. A malformed object, missing field, or oversized message must produce a controlled error while preserving the displayed content.
Beyond the renderer, the integration needs tests for outages, unexpected responses, production configuration, and vendor updates. A successful HTTP status does not establish that received content is safe.
The runnable example and its contract tests are in the profile repository. They cover the synthetic example; they do not certify a real application or demonstrate a vendor fix.
Operational choices
Inventory scripts and their owners. Assess whether the integration needs to execute inside the main page or can run in isolation with limited permissions. Keep a way to disable it and a process for reviewing changes.
SRI checks whether a resource matches the expected hash; it does not fix a vulnerable version’s logic. CSP is an additional layer and must fit application flows. Neither replaces reviewing the data path.
TypeScript example
export function parseNotice(input: unknown): string {
if (typeof input !== 'object' || input === null || Array.isArray(input)) {
throw new TypeError('Invalid notice');
}
const message = (input as Record<string, unknown>).message;
if (typeof message !== 'string' || message.length > 500) {
throw new TypeError('Invalid message');
}
return message;
}
export function renderNotice(target: HTMLElement, input: unknown): void {
target.textContent = parseNotice(input);
}