Escaping late: a checklist for WordPress templates

Most template security bugs are output that was never escaped, or was escaped with the wrong function. This checklist covers both.

Trust nothing that crosses a boundary

Two-factor authentication is on for every account that can deploy, and shared passwords live in a manager, not in a chat thread.

<a href="<?php echo esc_url( $link ); ?>"
   title="<?php echo esc_attr( $label ); ?>">
	<?php echo esc_html( $title ); ?>
</a>

<div class="bio">
	<?php echo wp_kses_post( wpautop( $bio ) ); ?>
</div>

Sanitise on the way in, escape on the way out, and do both as late as possible. That one rule covers most of the bugs we find in reviews. The snippet above is the whole thing; the version in our repository only adds tests.

Keeping dependencies honest

  • Escape late, at the point of output
  • Start CSP in report-only mode
  • Review dependency updates weekly
  • Require two-factor for deploy access

Leave a comment

Your email address will not be published. Required fields are marked *