Official Crawl4AI Cloud: a hosted web scraping, extraction, and search API for AI agents. Free API key, 1,000 credits a month, no card. Fully open source: this repo is the Apache-2.0 crawler that powers it, and you can self-host it.
Python aiai-agentscrawl4ai-cloudcrawlerdata-extractionllmmarkdownmcpopen-sourceplaywrightpythonragscraperweb-crawlerweb-crawlingweb-scraping
fix(security): escape crawled data in the LinkedIn graph view template
ntohidi5fff5b962e31
diff --git a/docs/apps/linkdin/templates/graph_view_template.html b/docs/apps/linkdin/templates/graph_view_template.htmlindex 9d908d8f..84cb0258 100644--- a/docs/apps/linkdin/templates/graph_view_template.html+++ b/docs/apps/linkdin/templates/graph_view_template.html@@ -9,6 +9,7 @@<!-- our tiny OpenAI wrapper --><script src="ai.js"></script><script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>+ <script src="https://cdnjs.cloudflare.com/ajax/libs/dompurify/3.1.6/purify.min.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/split.js/1.6.5/split.min.js"></script><link href="https://unpkg.com/[email protected]/dist/vis-network.min.css" rel="stylesheet" /><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" />@@ -252,6 +253,18 @@<script>// Check localStorage first, otherwise fetch default datalet data;++ // Escape text before it goes into an innerHTML template (crawled data is untrusted)+ function esc(s) {+ return String(s ?? '').replace(/[&<>"']/g, c => ({+ '&': '&', '<': '<', '>': '>', '"': '"', "'": '''+ }[c]))+ }+ // Only allow http(s) URLs for src/href (escaped for the attribute), otherwise a harmless value+ function safeUrl(u) {+ return typeof u === 'string' && /^https?:\/\//i.test(u) ? esc(u) : '#'+ }+// Toast notification functionfunction showToast(message, duration = 3000) {const toast = document.getElementById('toast');@@ -499,16 +512,16 @@li.className = 'p-3 rounded bg-neutral-800 hover:bg-neutral-700 border border-neutral-700 transition-colors'li.innerHTML = `<div class="flex justify-between items-start mb-1">- <h3 class="font-semibold text-blue-400 cursor-pointer">${n.name}</h3>- <span class="px-2 py-0.5 bg-neutral-700 rounded-full text-xs">${n.industry || 'N/A'}</span>+ <h3 class="font-semibold text-blue-400 cursor-pointer">${esc(n.name)}</h3>+ <span class="px-2 py-0.5 bg-neutral-700 rounded-full text-xs">${esc(n.industry || 'N/A')}</span></div>- <p class="text-xs text-neutral-300 mb-2">${n.about || 'No description available'}</p>+ <p class="text-xs text-neutral-300 mb-2">${esc(n.about || 'No description available')}</p><div class="flex justify-between items-center text-xs"><div class="flex items-center"><i class="fa fa-users mr-1 text-neutral-400"></i><span>${n.followers?.toLocaleString() || '0'} followers</span></div>- <a href="https://www.linkedin.com${n.handle}" target="_blank" class="text-emerald-400 hover:text-emerald-300">+ <a href="https://www.linkedin.com${esc(n.handle || '')}" target="_blank" class="text-emerald-400 hover:text-emerald-300"><i class="fab fa-linkedin mr-1"></i>View on LinkedIn</a></div>@@ -593,7 +606,7 @@pane.innerHTML = `<div class="p-4 border-b border-neutral-700 bg-neutral-800"><div class="flex justify-between items-center">- <h2 class="font-semibold text-lg text-blue-400">${companyName}</h2>+ <h2 class="font-semibold text-lg text-blue-400">${esc(companyName)}</h2><span class="px-2 py-1 bg-neutral-700 rounded-full text-xs">${employeeCount} employees</span></div></div>@@ -607,12 +620,12 @@${decisionMakers.map(n => `<li class="p-2 rounded bg-neutral-700 hover:bg-neutral-600 transition-colors flex justify-between items-center"><div>- <div class="font-medium">${n.name}</div>- <div class="text-xs text-neutral-300">${n.title}</div>+ <div class="font-medium">${esc(n.name)}</div>+ <div class="text-xs text-neutral-300">${esc(n.title)}</div></div><div class="flex items-center gap-2"><span class="text-xs px-2 py-0.5 rounded-full" style="background-color:${colorForScore(n.decision_score)}">${(n.decision_score * 100).toFixed(0)}%</span>- <a href="${n.profile_url}" target="_blank" class="text-emerald-400 hover:text-emerald-300 text-xs">+ <a href="${safeUrl(n.profile_url)}" target="_blank" class="text-emerald-400 hover:text-emerald-300 text-xs"><i class="fab fa-linkedin"></i></a></div>@@ -721,41 +734,41 @@box.innerHTML = `<div class="bg-neutral-800 rounded-lg p-4"><div class="flex items-start space-x-3">- <img src="${p.avatar_url || 'https://ui-avatars.com/api/?name=' + encodeURIComponent(p.name)}"+ <img src="${p.avatar_url ? safeUrl(p.avatar_url) : 'https://ui-avatars.com/api/?name=' + encodeURIComponent(p.name)}"class="h-16 w-16 rounded-full object-cover border-2 border-neutral-700"/><div class="flex-1"><div class="flex justify-between items-start"><div>- <div class="font-semibold text-lg">${p.name}</div>- <div class="text-neutral-300 text-sm">${p.title || 'Employee'}</div>+ <div class="font-semibold text-lg">${esc(p.name)}</div>+ <div class="text-neutral-300 text-sm">${esc(p.title || 'Employee')}</div></div>- <span class="px-2 py-1 rounded-full text-sm font-medium"+ <span class="px-2 py-1 rounded-full text-sm font-medium"style="background-color:${scoreColor}">${scorePercentage}% influence</span></div>-+<div class="mt-3 grid grid-cols-2 gap-2 text-xs text-neutral-300"><div class="flex items-center"><i class="fas fa-sitemap w-5 text-neutral-500"></i>- <span class="ml-1">${p.dept || 'Department not specified'}</span>+ <span class="ml-1">${esc(p.dept || 'Department not specified')}</span></div><div class="flex items-center"><i class="fas fa-calendar-alt w-5 text-neutral-500"></i>- <span class="ml-1">${p.yoe_current || '?'} years at company</span>+ <span class="ml-1">${esc(p.yoe_current || '?')} years at company</span></div><div class="flex items-center"><i class="fas fa-briefcase w-5 text-neutral-500"></i>- <span class="ml-1">${p.title_level || 'Level not specified'}</span>+ <span class="ml-1">${esc(p.title_level || 'Level not specified')}</span></div><div class="flex items-center"><i class="fas fa-user-friends w-5 text-neutral-500"></i>- <span class="ml-1">${p.connection_count || '?'} connections</span>+ <span class="ml-1">${esc(p.connection_count || '?')} connections</span></div></div>-+<div class="mt-3 flex justify-end">- <a href="${p.id}" target="_blank"+ <a href="${safeUrl(p.id)}" target="_blank"class="bg-emerald-800 hover:bg-emerald-700 text-emerald-100 px-3 py-1 rounded text-xs flex items-center transition-colors"><i class="fab fa-linkedin mr-1"></i> View on LinkedIn</a>@@ -841,7 +854,7 @@let el = chatBody.lastElementChildif (streaming && el && el.dataset.sender === sender) {// Just append raw text for streaming mode- el.lastChild.innerHTML += text.replace(/\n/g, "<br>")+ el.lastChild.innerHTML += esc(text).replace(/\n/g, "<br>")} else {el = document.createElement('div')el.className = 'chat-message'@@ -856,8 +869,8 @@const contentEl = document.createElement('div')contentEl.className = 'ml-1 mt-1'- // Apply markdown parsing- contentEl.innerHTML = marked.parse(text)+ // Apply markdown parsing (sanitized, since the AI reply can echo back crawled text)+ contentEl.innerHTML = DOMPurify.sanitize(marked.parse(text))// Style markdown elementsconst style = document.createElement('style')@@ -1115,13 +1128,13 @@const graphInfoContent = document.getElementById('graphInfoContent');graphInfoContent.innerHTML = `- <div class="font-semibold text-neutral-200">${node.name}</div>- <div class="text-neutral-400">${node.industry || 'Industry: N/A'}</div>+ <div class="font-semibold text-neutral-200">${esc(node.name)}</div>+ <div class="text-neutral-400">${esc(node.industry || 'Industry: N/A')}</div><div class="flex items-center mt-1"><i class="fas fa-users mr-1 text-blue-400"></i><span>${node.followers?.toLocaleString() || '0'} followers</span></div>- <div class="mt-1">${node.about || ''}</div>+ <div class="mt-1">${esc(node.about || '')}</div>`;graphInfo.classList.remove('hidden');