Skip to content

Runtime stripping of additional return properties (Response Sanitization) #1827

@skrukwa

Description

@skrukwa

Currently, tsoa handles input validation (including noImplicitAdditionalProperties) but does not validate or sanitize output data against the controller's return type.

This creates a risk of accidental data leakage. For example, returning an object that contains extra fields (e.g., a database entity with passwordHash, internalFlags, or sensitive nested relations) results in those fields being serialized and sent to the client, even if they are not defined in the return interface.

I propose a configuration option in tsoa.json like stripExcessReturnProperties: true (defaulting to false). Since tsoa already generates metadata for models to validate inputs, could this same logic be used to recursively sanitize the output in the generated promise handler?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions