page-meta-analyzer

Is it safe to display another site's meta tags on my page?

Grabzies Ecommerce · 23 September 2026 · 3 replies
I'm building a small tool that fetches a URL and shows all its meta tags in a table. It inserts each tag's content into the table with innerHTML.

A friend said that's a security risk. The tags come from someone else's site, not from my users, so is it really a problem?
3 Replies
John Carlsson · 23 Sept 2026
Your friend is right. The tag content comes from whatever site is being checked, and anyone can build a page whose meta tag content contains HTML. Inserted with innerHTML, that HTML runs inside your site, in your visitor's logged-in session. For example, a content value like <img src=x onerror=...> would execute.

Always escape anything from the fetched page before inserting it: replace & < > " with their HTML codes, or set textContent instead of innerHTML.
Grabzies Ecommerce · 23 Sept 2026
Changed it to escape everything. But now titles with an ampersand show as &amp;. How do I fix that without reopening the hole?
John Carlsson · 23 Sept 2026
Decode first, then escape. The value you extracted from the page source is still HTML-encoded, so decode it to plain text (a textarea element decodes without running anything: set its innerHTML, read its value), then escape that plain text for display. Titles show "&" correctly, and an encoded attack like &lt;script&gt; is decoded to text and then shown safely rather than run. Test with both a normal title and a hostile one.

Join the discussion

Sign in to reply, share your SEO experience and connect with other members.