T09 · Insecure Skill Coding Practices
- Location
SKILL.md:158- Finding
Unescaped Custom Field Value in an HTML Attribute
- Content
View full analysis
``` ### Technical Analysis The example prints an Advanced Custom Fields sub-field directly into the `id` attribute using `the_sub_field()`. This function outputs the stored value without applying context-appropriate HTML attribute escaping. If an attacker or an insufficiently trusted content editor can control `section_id`, a value containing quotes may terminate the `id` attribute and introduce additional attributes or markup. Because the Skill instructs users to reproduce this pattern in generated WordPress themes, it may create a stored cross-site scripting condition. ### Attack Path 1. An attacker obtains access to an account or workflow that can modify the relevant custom field. 2. The attacker stores a payload containing an attribute terminator and injected event handler or markup in `section_id`. 3. WordPress saves the attacker-controlled custom-field value. 4. A visitor opens a page rendered by the affected template. 5. `the_sub_field()` prints the value directly into the `section` element. 6. The browser interprets the injected HTML or event handler, potentially executing script in the visitor's WordPress origin. ### Impact Assessment Successful exploitation could execute attacker-controlled JavaScript in the browser of a visitor viewing the affected page. Depending on the victim's WordPress privileges, this may allow administrative actions through the victim's authenticated session, content manipulation, sensitive page-data access, or account compromise. The exploit requires the attacker to control the relevant custom-field value. The resulting scope is the WordPress site and ori ...[truncated 61 chars]- Remediation
View remediation
``` Additional hardening measures: - Restrict the field to letters, digits, underscores, and hyphens. - Validate and sanitize the value when it is saved, not only when rendered. - Limit custom-field modification privileges to trusted roles. - Apply context-specific escaping to every dynamic attribute. - Add tests using values containing quotes, angle brackets, and event-handler syntax. ]]>
