Security rules for MyBB themes and modules in MyStudio

amtekkie · Today

MyStudio is built so that restyling a MyBB forum can never compromise it. These are the rules MyStudio's own themes and modules follow, and the ones your themes and modules should follow too.

The short version
  • No PHP in themes; every template passes MyBB's check
  • Escape output and SQL; check the post key on every change
  • Sensitive actions behind MyStudio::canDo(); no secrets in files

No PHP in themes

Theme folders hold web files only: HTML templates, CSS, JavaScript, JSON, images, fonts and media. Theme PHP lives in inc/plugins/mystudio/themes/{slug}/, features in modules. Package imports refuse PHP files and dotfiles in the theme part, the editor refuses to create them, and .htaccess files let browsers load only assets from themes/ and inc/plugins/mystudio/. On nginx, add the rules the Themes page shows.

Templates pass MyBB's security check

MyBB templates are evaluated as PHP strings, so anything that writes a template (sync, the editor, package import, Page Builder pages) runs MyBB's template check, which refuses constructs that could run code such as {${…}}. Put logic in hooks.php and pass the result to templates as variables.

Escape output, escape SQL

  • Everything a user or admin typed goes through htmlspecialchars_uni() before it reaches HTML.
  • In this MyBB build, $db->insert_query() and $db->update_query() do not escape: run text through $db->escape_string() and cast numbers with (int).
  • Admin-entered filters never become raw SQL: fields and operators come from fixed lists.
  • Remember that MyBB cleans some request names itself (tid, uid, page, order …): use your own names for other meanings.

Check the post key on every change

Every form and AJAX action that changes data calls verify_post_check($mybb->get_input('my_post_key')). State changes in the Admin CP go through a confirmation page, so a link can't change anything by itself.

Sensitive actions need delegation

Installing PHP code, adding scripts to pages, payment credentials, refunds, membership products, licensing settings, server rewrites and points balances are for super administrators unless they grant them in Delegation. Code checks MyStudio::canDo($cap), never the super-admin list directly. A new sensitive action gets its own capability. Updating MyStudio can't be delegated.

Uploads

  • Check type and content (getimagesize, magic bytes), not only the extension; refuse files that are also scripts.
  • Store protected files (shop downloads) in folders the web server never serves, and send them through a checked download link.
  • Give stored files random names and set size limits.

No secrets in files

API keys and credentials are stored in the database, marked 'secret' => true in a module's settings so they're never shown again or exported. Never write secrets into themes/ or inc/plugins/mystudio/, which are web-reachable.

Outgoing requests

When MyStudio fetches from the internet (fonts, domain proof, update packages), it uses HTTPS, fixed hosts or public addresses only, no redirects, short timeouts and size limits, so a crafted address can't make your server reach its internal network. Update packages are checked against a signed fingerprint before anything is installed.

Server rules

The SEO module builds its .htaccess block only from checked paths and targets, never from raw admin text. Every write backs up the file, tests a pretty address and restores the backup if the test fails.

Privacy by default

Search tags and structured data only use content guests can read, alerts recheck permissions before showing, IP recording can be switched off, and deleting a member removes or unlinks their data. Follow the same approach in your modules.

Checklist

  1. Every PHP file starts with the IN_MYBB guard.
  2. Output escaped; SQL values escaped or cast.
  3. Post key checked on every change; admin actions confirmed.
  4. Sensitive actions behind MyStudio::canDo().
  5. Uploads checked by content and stored safely; no secrets in files.
  6. Templates pass MyBB's template check; no PHP in theme folders.