GoAdmio

findbom

Find PHP files that start with a UTF-8 byte order mark (BOM), in one site, one path, or all sites

On this page: Overview · Quick start · Syntax · Arguments · Output · Examples · Troubleshooting · Details · See also


Overview

/go/findbom lists the .php files whose first bytes are a UTF-8 BOM (EF BB BF). It only reads; it never changes a file.

A BOM at the start of a PHP file is invisible in most editors, but the web server sends it to the browser before any other output. This causes problems such as:

To remove the BOM from the files found, use removebom.


Quick start

/go/findbom example.com

Syntax

/go/findbom <domain>
/go/findbom <path>
/go/findbom all
Form Scans
/go/findbom <domain> /home/<domain>/www
/go/findbom <path> The file or folder at that path.
/go/findbom all Everything under /home, for every account.

The command looks at the argument in this order and uses the first match:

  1. A file or folder that exists at that path, relative to the current folder or absolute.
  2. The word all.
  3. A hosted domain with a /home/<domain>/www folder.

If nothing matches, it prints <argument> does not exist and exits with code 1.


Arguments

Argument Required Default Notes
<domain> One of the three — The account's primary domain, written in full.
<path> One of the three — A folder or a single .php file. Avoid spaces in the path.
all One of the three — Scans all of /home.

The command has no --option flags.


Output

Outcome What you get
BOMs found The full path of each affected file, one per line.
None found Nothing. There is no "clean" message.
Target not found <argument> does not exist and exit code 1. With no argument the name is empty, so you see does not exist.

The exit code is 0 whether or not any BOM is found.

What is checked

Logging

Every run is appended to /var/log/go/findbom.log.


Examples

# Scan one site
/go/findbom example.com
# Scan one folder
/go/findbom /home/example.com/www/wp-content/plugins
# Check one file
/go/findbom /home/example.com/www/index.php
# Scan every site and count the affected files
/go/findbom all | wc -l

Troubleshooting

Symptom Likely cause Fix
No output No file has a BOM, or no .php file was found, or the files couldn't be read. Check that the path has .php files, and run the command as root.
does not exist with an empty name No argument was given. Pass a domain, a path, or all.
<name> does not exist The domain has no /home/<name>/www folder, or the path is wrong. Check the name.
It scans more than www for a domain A folder named like the domain exists in the current folder, and the command takes that first. Run it from another folder, or pass the full path.
awk errors about nextfile or about permissions The installed awk is too old, or the files can't be read by the current user. Use gawk, and run as root.
A BOM exists but isn't listed It isn't UTF-8, the file isn't named *.php in lowercase (.phtml, .inc, .PHP), or the problem is whitespace before <?php. Check the file by hand, for example with head -c 3 <file> | xxd.
A path with spaces gives wrong results The path isn't quoted inside the script. Use the domain name, or a path without spaces.
Pages show headers already sent errors A BOM or whitespace before <?php. Run /go/findbom <domain>, then removebom.

Details

What it does

  1. Logs the call to /var/log/go/findbom.log.
  2. Decides what to scan (see Syntax). Stops with <argument> does not exist if nothing matches.
  3. Finds every regular file whose name ends in .php under that target.
  4. Passes the files to awk, which reads only the first line of each file and prints the file name if the line starts with the bytes EF BB BF.
flowchart TD
    A["findbom argument"] --> B{"File or folder exists at that path?"}
    B -- "Yes" --> S["Scan it"]
    B -- "No" --> C{"all?"}
    C -- "Yes" --> H["Scan /home"]
    C -- "No" --> D{"/home/argument/www exists?"}
    D -- "Yes" --> W["Scan /home/argument/www"]
    D -- "No" --> E["argument does not exist, exit 1"]

Notes for maintainers

Issue Why it matters Suggested fix
$Directory is not quoted Paths with spaces or special characters break the scan. Quote it and put -- before it.
A path in the current folder is checked before the domain findbom example.com run from /home scans the whole account folder. Check /home/$1/www first, or require absolute paths.
The *"/www/"* branch can never run An existing folder is already caught by the first test. Remove it.
No usage message An empty argument prints does not exist. Print a usage line.
awk and xargs run without sudo Files the current user can't read are skipped. Re-run through sudo at the top, like most other commands.
Only lowercase *.php .PHP, .phtml, .inc, and .php5 files are missed. Use -iname, and add the other extensions.
Only the UTF-8 BOM is detected UTF-16 and UTF-32 BOMs and whitespace before <?php cause the same errors. Also detect those cases.
The check depends on awk features and the locale Needs nextfile support, and hex escapes can behave differently in some locales. Run awk with LC_ALL=C, or use another method such as head -c 3.
No summary and no "none found" message An empty result looks like a failure. Print a count at the end.
The exit code doesn't change when files are found Hard to use in scripts. Exit non-zero when a BOM is found, or add an option for it.

See also

Command Description
removebom Remove BOM from all PHP files in GoAdmio
scan Scan newly modified PHP files for shells and the root password
displayerrors Toggle PHP display_errors across all php.ini files
fix Fix GoAdmio file and folder permissions