viewof userMaxCaps = Inputs.checkbox(
["READ", "WRITE", "EXECUTE", "DELETE", "CREATE", "ADMIN_READ", "ADMIN_WRITE", "GRANT"],
{label: "User's maximum allowed capabilities", value: ["READ", "WRITE", "EXECUTE", "CREATE"]}
)
viewof attemptedResource = Inputs.select(
["Sensor Data (READ)", "Configuration (WRITE)", "Device Control (EXECUTE)", "System Logs (AUDIT)", "User Management (ADMIN_WRITE)", "Emergency Override (EMERGENCY)", "Debug Console (DEBUG)", "Firmware Update (ADMIN_WRITE + EXECUTE)"],
{label: "Resource to access", value: "User Management (ADMIN_WRITE)"}
)
viewof escalationAttemptCount = Inputs.range([1, 10], {
label: "Number of attempts in window",
step: 1,
value: 1
})Try It: Privilege Escalation Detector
Try It: Privilege Escalation Detector
animation
authentication
security
Try Change Number of attempts in window from 1 to 5.
Observe Watch Status and Escalation attempts after you press Play access.
Explain Explain why a forbidden request triggers lockdown at 5 attempts.
Technical boundaries. The detector compares selected resource requirements with the user's maximum allowed capabilities. The attempt count is set manually; forbidden requests trigger lockdown at 5 attempts.
NoteTry It: Privilege Escalation Detector
Configure a user’s current and maximum capabilities, then attempt to access a resource. The detector shows whether the request triggers an escalation alert and how repeated attempts lead to lockdown.
The detector first reports whether access is granted, an escalation is denied, or the session is locked down. In the table, each capability has a row: “User Has” shows the user’s maximum rights, “Required” shows what the selected resource needs, and the status highlights any required right the user lacks in red. When a request is forbidden, the attempt bar compares the count with the five-attempt threshold. Its fill and percentage rise together: one of five is 20%, and five reaches 100%. At the threshold, the status changes to security lockdown and the session is terminated. A request within the allowed rights is granted and does not show the escalation bar.
{
const capMap = {
"READ": 0x0001, "WRITE": 0x0002, "EXECUTE": 0x0004, "DELETE": 0x0008,
"CREATE": 0x0010, "ADMIN_READ": 0x0020, "ADMIN_WRITE": 0x0040, "GRANT": 0x0080,
"REVOKE": 0x0100, "AUDIT": 0x0200, "EMERGENCY": 0x0400, "DEBUG": 0x0800
};
const resourceCaps = {
"Sensor Data (READ)": 0x0001,
"Configuration (WRITE)": 0x0002,
"Device Control (EXECUTE)": 0x0004,
"System Logs (AUDIT)": 0x0200,
"User Management (ADMIN_WRITE)": 0x0040,
"Emergency Override (EMERGENCY)": 0x0400,
"Debug Console (DEBUG)": 0x0800,
"Firmware Update (ADMIN_WRITE + EXECUTE)": 0x0044
};
let maxCap = 0;
for (const c of userMaxCaps) {
maxCap = maxCap | (capMap[c] || 0);
}
const reqCap = resourceCaps[attemptedResource] || 0;
const forbidden = reqCap & ~maxCap;
const isEscalation = forbidden !== 0;
const MAX_ATTEMPTS = 5;
const isLockdown = isEscalation && escalationAttemptCount >= MAX_ATTEMPTS;
const allCaps = ["READ", "WRITE", "EXECUTE", "DELETE", "CREATE", "ADMIN_READ", "ADMIN_WRITE", "GRANT", "REVOKE", "AUDIT", "EMERGENCY", "DEBUG"];
const reqBits = allCaps.filter(c => (reqCap & capMap[c]) !== 0);
const forbiddenBits = allCaps.filter(c => (forbidden & capMap[c]) !== 0);
const capRows = allCaps.map(c => {
const bit = capMap[c];
const userHas = (maxCap & bit) !== 0;
const required = (reqCap & bit) !== 0;
const isForbidden = (forbidden & bit) !== 0;
let bg = "white";
if (isForbidden) bg = "#ffebee";
else if (required && userHas) bg = "#e8f5e9";
else if (required) bg = "#fff3e0";
return `<tr style="background:${bg}">
<td style="padding:2px 6px;font-family:monospace;font-size:0.85em">${c}</td>
<td style="padding:2px 6px;text-align:center">${userHas ? "Yes" : "---"}</td>
<td style="padding:2px 6px;text-align:center">${required ? "Yes" : "---"}</td>
<td style="padding:2px 6px;text-align:center;color:${isForbidden ? '#E74C3C' : '#16A085'};font-weight:bold">${isForbidden ? "FORBIDDEN" : required ? (userHas ? "OK" : "---") : "---"}</td>
</tr>`;
}).join("");
const statusColor = isLockdown ? "#E74C3C" : isEscalation ? "#E67E22" : "#16A085";
const statusBg = isLockdown ? "#ffebee" : isEscalation ? "#fef5e7" : "#e8f5e9";
const statusBorder = isLockdown ? "#E74C3C" : isEscalation ? "#E67E22" : "#16A085";
const statusText = isLockdown ? "SECURITY LOCKDOWN - Session Terminated" : isEscalation ? "ESCALATION ATTEMPT DETECTED - Access Denied" : "ACCESS GRANTED";
const statusDetail = isLockdown
? "After " + escalationAttemptCount + " escalation attempts (threshold: " + MAX_ATTEMPTS + "), the system has terminated the session and logged a critical security event."
: isEscalation
? "Attempted forbidden capabilities: " + forbiddenBits.join(", ") + ". Attempt " + escalationAttemptCount + " of " + MAX_ATTEMPTS + " before lockdown."
: "All required capabilities are within the user's allowed set.";
const barW = 300;
const filledW = Math.min(escalationAttemptCount / MAX_ATTEMPTS, 1) * barW;
return html`<div style="font-family:sans-serif">
<div style="background:${statusBg};border:2px solid ${statusBorder};border-radius:6px;padding:14px;margin:8px 0">
<div style="font-size:1.1em;font-weight:bold;color:${statusColor}">${statusText}</div>
<div style="color:#2C3E50;margin-top:4px;font-size:0.9em">${statusDetail}</div>
</div>
${isEscalation ? `<div style="margin:8px 0">
<div style="font-size:0.85em;color:#7F8C8D;margin-bottom:4px">Escalation attempts: ${escalationAttemptCount} / ${MAX_ATTEMPTS} (lockdown threshold)</div>
<svg width="${barW + 20}" height="24">
<rect x="0" y="2" width="${barW}" height="20" fill="#f0f0f0" rx="4"/>
<rect x="0" y="2" width="${filledW}" height="20" fill="${isLockdown ? '#E74C3C' : '#E67E22'}" rx="4"/>
<text x="${barW / 2}" y="16" text-anchor="middle" font-size="11" fill="${filledW > barW / 2 ? 'white' : '#2C3E50'}" font-weight="bold">${Math.round(escalationAttemptCount / MAX_ATTEMPTS * 100)}%</text>
</svg>
</div>` : ""}
<table style="border-collapse:collapse;width:100%;font-size:0.85em;margin-top:8px">
<tr style="background:#2C3E50;color:white">
<th style="padding:3px 6px;text-align:left">Capability</th>
<th style="padding:3px 6px;text-align:center">User Has</th>
<th style="padding:3px 6px;text-align:center">Required</th>
<th style="padding:3px 6px;text-align:center">Status</th>
</tr>
${capRows}
</table>
</div>`;
}