security: unsafe %-string data-ol-link-track/tracking-attribute construction in 4 templates (modal_links, title_and_author, onboarding_card, header_dropdown)
Context
While reviewing #12985 (which converts Follow.html from a macro to a template to fix unsafe %-string HTML attribute construction), I found the same unsafe pattern still present in 4 other files. PR #12985 itself flagged modal_links.html as an explicit known follow-up; this issue also covers 3 more instances found during a full sweep.
The real vulnerability mechanism (precise)
Initial framing (in #12634/#12985) described this as <script> tag breakout via unescaped </>. That's not quite right in production: Open Library's real render_template pipeline auto-escapes <, >, &, " for a bare $var substitution (confirmed empirically), so a naive <script> payload is already neutralized.
The actual exploitable mechanism is attribute injection via unescaped whitespace: since the escaped output is spliced in as a bare, unquoted-in-effect fragment (any literal " in the constructed string becomes the inert entity text ", not a real quote delimiter), a value containing a space — e.g. x onmouseover=alert(document.cookie)// — creates a real, working new HTML attribute (onmouseover=...) on the tag. Confirmed via direct rendering through the actual render_template pipeline against the current modal_links.html code:
Input ga_data: x onmouseover=alert(document.cookie)//
Output: <a data-ol-link-track=x onmouseover=alert(document.cookie)//>Follow</a>
None of today's callers pass anything but hardcoded string literals, so this isn't attacker-reachable right now through any live code path — same as Follow.html's pre-fix state. It's a defense-in-depth gap: the moment any caller passes dynamic/user-influenced data into one of these attributes, it's a working XSS.
Files affected (same category, same fix)
openlibrary/templates/type/edition/modal_links.html(icon_link()'sga_attr)openlibrary/templates/type/edition/title_and_author.html(duplicateicon_link(), samega_attrlogic)openlibrary/templates/home/onboarding_card.html(data_ol_link_track)openlibrary/templates/lib/header_dropdown.html(tracker, 2 call sites)
Proposed fix
Mirror the pattern from #12985: replace the %-string attribute-fragment construction with a static, literal-quoted attribute in the template markup itself, using $if var: attr="$var" conditional blocks — the same fix already reviewed and validated for Follow.html.