HTML Security and Privacy: Hidden Data to Check
Review active content, parser risks and hidden metadata before opening or sharing HTML files.
Active Content Vectors
Script Elements and Event Handlers
The <script> element is the most direct mechanism for executable content in HTML. A file may contain inline scripts (<script>alert(1)</script>) or external references (<script src="https://example.com/tracker.js">). Either form executes in the viewer's browser within the sandbox constraints of that environment.
Event handler attributes—onload, onclick, onmouseover, onerror, and approximately 80 others defined in the specification—attach executable code directly to elements. These attributes accept JavaScript strings and fire without explicit script blocks.
Validation checks:
- Count every
<script>element. Separate inline from external by presence of asrcattribute. - Search for the pattern
on[a-z]+=across the raw source. This catches handlers on any element, including those injected into otherwise static markup. - Inspect
javascript:pseudo-URLs inhrefattributes (<a href="javascript:...">). These execute in the browsing context when activated.
Data URIs as Embedded Executables
The data: URL scheme (RFC 2397) allows resources to be embedded directly in attribute values. A script source of data:text/javascript;base64,YWxlcnQoMSk= decodes to executable JavaScript with no external network request. The same scheme applies to src attributes on <iframe>, <img>, and <object> elements.
Verification step: Search the raw source for the literal string data:. For each match, identify the MIME type after the colon. If the type is text/javascript, application/javascript, or any module type, the content is executable. Decode base64 segments and inspect the result before opening the file in a browser.
Autoplay Media and Automatic Requests
<audio> and <video> elements with the autoplay attribute initiate playback and network requests without user interaction. The preload attribute on these elements can trigger resource fetching even without playback. <iframe> and <embed> elements load remote documents automatically unless blocked by sandboxing or content security policy.
Checklist: Search for autoplay in any attribute position. Also search for <iframe and <embed to inventory all automatically-loading subdocuments.
Hidden Metadata in Markup
Comments as Data Carriers
HTML comments (<!-- ... -->) are ignored by the rendering engine but preserved verbatim in the source. They can contain credentials, internal identifiers, revision logs, database connection strings, or API keys. Because comments produce no visual output, they survive casual inspection.
Detection procedure: Open the file in a text editor and search for <!--. Review every comment block individually. Automated extraction tools can collect comments, but manual review is necessary to identify sensitive patterns such as password, token, key, or email addresses.
Obsolete Conditional Comments
Internet Explorer versions 5 through 9 supported conditional comments using the syntax <!--[if IE]> ... <![endif]-->. The WHATWG specification does not define these; they are a legacy artifact. Files containing them may include fallback content, version-specific scripts, or instructions intended only for that browser family.
What to search for: Any comment containing [if or [endif]. These indicate non-standard markup that may carry hidden logic.
Custom Data Attributes
Attributes prefixed with data- (e.g., data-user-id="481516", data-session="a1b2c3") are valid per the specification and are intended for script consumption. They are not displayed by default but can expose internal identifiers, configuration values, or tracking tokens.
Verification: Search for data- in the source. Cross-reference attribute values against patterns that suggest sensitivity: numeric IDs, UUIDs, base64-encoded strings, or values matching known token formats.
Embedded Subdocuments and Foreign Content
Iframes and the srcdoc Attribute
An <iframe> loads a separate browsing context. The src attribute points to an external URL; the srcdoc attribute embeds an entire HTML document as a string literal within the parent file. The sandbox attribute can restrict capabilities, but its absence means the iframe runs with full permissions of its origin.
Security check: List every <iframe> and <frame> element. For each, inspect both src and srcdoc. If srcdoc is present, extract its value, decode HTML entities, and review the embedded document as a separate HTML file. Pay attention to script elements and event handlers within the srcdoc content.
Object and Embed Elements
<object> and <embed> load external resources by MIME type. While modern browsers restrict Java applets and Flash, these elements can still reference PDFs, SVG files, or other document types. The data attribute on <object> and the src attribute on <embed> specify the resource location.
What to check: Search for <object and <embed. Note the type attribute value. If the type is application/pdf, image/svg+xml, or any plugin-associated MIME type, the element loads external content that may contain its own active components.
SVG with Embedded Scripts
Scalable Vector Graphics files are XML documents. When included inline via <svg> elements or referenced through <img>, <object>, or <embed>, they can contain <script> elements and event handler attributes. An SVG loaded through <img> has restricted script execution in most browsers, but <object> and inline SVG do not share that restriction.
Inspection: If the HTML contains inline <svg> blocks or references .svg files, extract the SVG content and scan it independently for <script> tags and on* attributes.
External Resource Loading and Tracking Surfaces
Stylesheets, Fonts, and Imports
<link rel="stylesheet"> and CSS @import rules trigger network requests to external URLs. While not directly executable, these requests expose the viewer's IP address and user agent to the remote server. @font-face declarations with external src URLs behave identically.
Verification: Extract all URLs from <link> elements, @import statements, and @font-face src properties. Identify each domain and determine whether it is necessary for the document's function or a third-party tracking endpoint.
Image Beacons and Tracking Pixels
<img> elements with external src attributes generate requests regardless of whether the image is visible. A 1×1 transparent pixel with query parameters (<img src="https://tracker.example.com/beacon?uid=abc123">) functions as a web beacon. The <source>, <track>, and <link rel="prefetch"> elements can similarly trigger requests with identifying parameters.
Check: For every <img>, <source>, and <track> element, examine the URL for query parameters resembling identifiers (uid, client, token, id). Also check <form action> and <input formaction> attributes for external submission endpoints.
Verification Workflow
Step 1: Static Source Inspection
Open the file in a text editor, not a browser. Execute these searches in order:
<script— inventory all script elements; distinguish inline from external.on[a-z]+=— catch event handler attributes on any element.data:— locate all data URIs; decode and inspect base64 payloads.<!--— review every comment block for sensitive content.srcdoc— identify inline iframe documents; extract and review.autoplay— flag media elements that activate without user interaction.
Step 2: URL Extraction and Audit
Collect every URL from href, src, data, action, formaction, and cite attributes. List them in a separate document. For each URL, check:
- Whether the domain is expected or third-party.
- Whether query parameters contain identifiers or tokens.
- Whether the URL references an internal hostname or IP address.
Step 3: Sanitization Before Sharing
If the file must be distributed but contains sensitive metadata or active content:
- Remove all
<script>elements andon*event handler attributes. - Strip all HTML comments.
- Replace external resource URLs with local paths or remove them.
- Convert
<iframe srcdoc="...">to a static placeholder noting the original content was removed.
Hard Limits on Removal
Some hidden data cannot be removed without destroying the document's intended behavior:
- Inline event handlers driving core functionality. If
onclickoronsubmitattributes are essential to the document's operation, stripping them breaks the file. - Data URIs containing the sole copy of an image or font. Removing a
data:URI that embeds the only available resource leaves a broken placeholder. - Legacy conditional comments with layout fallbacks. In files targeting older Internet Explorer, these comments may contain structural markup whose removal alters rendering.
The HTML specification provides no "safe subset" guarantee. Any element or attribute not explicitly removed may carry hidden content or active behavior (see WHATWG HTML: Writing HTML documents). When removal is impossible, the decision reduces to whether the file's function justifies the risk of sharing it.