Summary
A Time-of-Check to Time-of-Use (TOCTOU) flaw in FreeScout's file name sanitization allows attackers to bypass protections against dangerous uploads by abusing zero-width space characters.
Any authenticated user with file upload permissions can upload a malicious .htaccess file that is incorrectly accepted and interpreted by the web server, leading to remote code execution on the underlying server.
Affected context
The vulnerability occurs in FreeScout installations that:
- Run versions 1.8.206 or earlier
- Allow authenticated users to upload files (e.g., attachments, assets, or content)
- Rely on the
sanitizeUploadedFileName()helper inapp/Http/Helper.phpto prevent dangerous filenames
The risk appears when Apache or another web server honors .htaccess directives in upload-accessible directories, allowing an uploaded .htaccess file with executable configuration to influence request handling.
Exploit preconditions
- Attack surface: Web application endpoints that accept file uploads (e.g., ticket attachments, media uploads).
- Required access: Valid authenticated account with any role that grants file upload permissions; no administrative privileges are strictly required if upload is allowed.
- Trigger point: Uploading a file whose name is crafted with a zero-width space or other invisible character before
.htaccess, causing the pre-sanitization prefix check to pass while the post-sanitization result becomes an effective.htaccessfile. - Why exploitation is possible: The filename is validated before sanitization strips invisible characters. This TOCTOU sequence allows an attacker to submit a name that passes the dot-prefix check initially, but transforms into a disallowed name after sanitization, with the system still treating it as safe.
Why this happens
The bug stems from a mismatch between the validation logic and the final value that is actually written to disk.
In sanitizeUploadedFileName(), FreeScout checks for dangerous dot-prefixed filenames (such as .htaccess) before it removes invisible characters like zero-width spaces from the filename.
Because the security-critical check operates on a different representation of the data than the one ultimately used, an attacker can insert zero-width characters to evade the initial check.
After the check, sanitization strips those characters, effectively converting the filename into a protected pattern, such as .htaccess, which is then written to disk.
This behavior maps to CWE-434: Unrestricted Upload of File with Dangerous Type, enabled by a TOCTOU-style validation flaw where filtering and enforcement are not applied atomically to the final value.
Potential impact
- Upload of a malicious
.htaccessfile that can alter web server behavior - Remote code execution through server-side configuration and script execution
- Access to or exfiltration of sensitive data handled by the application
- Privilege escalation within the hosting environment if web server directives allow it
- Service disruption, defacement, or use of the server as a pivot for further attacks
General mitigation guidance
Effective mitigation focuses on making file validation consistent, conservative, and independent of filename tricks:
- Perform all sanitization, normalization, and stripping of invisible or special characters before any security checks on filenames or extensions.
- Enforce a strict allowlist of safe file extensions and MIME types, rejecting anything that does not match known-safe patterns.
- Prohibit dot-prefixed filenames entirely for user-controlled uploads, or rewrite them to a neutral pattern that cannot affect server behavior.
- Store uploaded files outside the web root or in locations where
.htaccessand similar configuration files are not interpreted by the web server. - Configure the web server to ignore
.htaccessfiles in upload directories or disable per-directory overrides where possible. - Apply least-privilege file system permissions so that the application cannot overwrite server configuration or executable locations.
How teams detect issues like this
Detection typically involves both code-centric and operational approaches:
- Static analysis: Look for file upload handling code where:
- Filenames are modified (e.g., sanitized, normalized) after validation checks.
- Checks for dangerous prefixes or extensions are performed before transformations that may alter those values.
- Code review red flags:
- Multiple stages of filename handling where security checks and final writes are separated.
- Reliance on blacklists (e.g., "block
.htaccess") instead of extension allowlists. - Use of character-stripping routines (including invisible/Unicode characters) after access-control or policy validation has occurred.
- Runtime and operational monitoring:
- Monitor upload directories for new
.htaccessor other configuration-like files appearing at runtime. - Use file integrity monitoring to detect unexpected changes in web-accessible directories.
- Log and alert on uploads with unusual Unicode or zero-width characters in filenames.
- Automated SAST or custom linters can be configured to flag TOCTOU patterns in upload handlers and mismatches between validation and use of sanitized inputs.

