HTML Security & Session Watchdog
Kreft protects both client and server against Cross-Site Scripting (XSS) and unattended sessions out of the box—with zero external dependencies.
1. Live XSS Sanitizer Playground
Type or paste untrusted HTML below. Dangerous tags (<script>, <svg>, <iframe>), inline event handlers (onerror, onclick), and entity-obfuscated javascript: / data: URLs are neutralized automatically.
k-html Live Render (Safe DOM)
Kreftjs.cleanHtml(input) Output
<h3>Welcome to <b>Kreft v2.4</b>!</h3>
<p>Safe links work: <a href="https://example.com">Docs</a>.</p>
<img src="x">
stealCookies()
<a href="#">Malicious Link</a>
Kreftjs.stripTags(input) (Plain Text)
Welcome to Kreft v2.4 ! Safe links work: Docs . stealCookies() Malicious Link
Kreftjs.escapeHtml(input) (Entities)
<h3>Welcome to <b>Kreft v2.4</b>!</h3>
<p>Safe links work: <a href="https://example.com">Docs</a>.</p>
<img src="x" onerror="alert('XSS')">
stealCookies()
<svg onload="alert(1)"></svg>
<a href="javascript:alert(1)">Malicious Link</a>
2. Session Inactivity Watchdog (Kreftjs.useInactivityTimer)
Protects authenticated dashboards when a user leaves their screen unattended. Try the 10-second interactive simulation below (warning triggers at 5 seconds left):
3. Server-Side Request & Model Sanitization
// 1) Request sanitization in Controllers
const safeBody = req.clean('content') // strips scripts & unsafe attributes
const plainText = req.strip('title') // strips all HTML tags
const safeObj = req.html('bio') // wraps in SafeHtml instance
// 2) Automatic Model Casts (backend/app/Models/Article.js)
class Article extends Model {
static casts = {
title: 'strip_tags', // automatically strips tags before INSERT / UPDATE
content: 'safe_html', // sanitizes on write & hydrates as SafeHtml
snippet: 'escape_html', // escapes &, <, >, ", '
}
}