Database API and Security I'm working on a controller that queries a table based on the value in a route parameter

Example route path:

path: '/path/{parameter}'


Controller:

  public function myFunction($parameter) {
    $connection = \Drupal::database();
    $query = $connection-&gt;select('my_custom_table', 'mct');
    $query-&gt;condition('mct.col', $parameter, '=');
    ...
    $result = $query-&gt;execute();
    $records = $result-&gt;fetchAll();


Is there any sanitization that should occur in this circumstance or does the database API take care of this?
For input, saving to the DB, Database API takes care of it, automatically prevents SQL injection when using dynamic query. Since your code is using dynamic query, you're all good.

If you were to use static query you have to make sure you use placeholders as the docs mention.

For output, to prevent XSS, you'll want to use a template file, and print your value via Twig. Which auto escapes everything by default. If you don't use Twig, then you need to use the appropriate API function.