hermes-control-interface icon indicating copy to clipboard operation
hermes-control-interface copied to clipboard

[BUG] Skills Hub UI Fix

Open stamandster opened this issue 7 months ago • 1 comments

Problem The Skills Hub page always showed "Install" button for all skills, even those already installed. Users couldn't tell which skills were already installed, and the UI didn't update after installation.

Root Cause
The frontend was not fetching/checking the list of installed skills when rendering the browse page - it only had the browse/search functionality but no state tracking for what's already installed.

Files Modified
- src/js/main.js
- server.js (security fixes from earlier audit)



Fix 1: Security - Path Traversal in sanitizeProfileName()
File: server.js
Lines: ~890-900

javascript
// BEFORE (vulnerable)
function sanitizeProfileName(name) {
  return String(name).replace(/\s+/g, '').slice(0, 64);
}

// AFTER (fixed)
function sanitizeProfileName(name) {
  const sanitized = String(name).replace(/\s+/g, '').slice(0, 64);
  // Prevent path traversal attacks
  if (sanitized.includes('..') || sanitized.includes('/') || sanitized.includes('\\')) {
    return '';
  }
  return sanitized;
}


Fix 2: Security - Command Injection in Skills Install
File: server.js
Lines: ~3400-3404

javascript
// Added input validation before execHermes call
if (!/^[\w.\-]+$/.test(skill)) {
  return res.status(400).json({ ok: false, error: 'invalid skill name' });
}


Fix 3: Security - Replace shell() with execHermes()
File: server.js
Locations: Lines 3335, 3389, 3448, 2031, 3717, 4242

javascript
// BEFORE
const output = await shell(hermes skills browse --page ${page} 2>&1, '15s');

// AFTER
const output = await execHermes(['skills', 'browse', '--page', String(page)], 15000);


Fix 4: Security - Prompt Validation in Cron Create
File: server.js
Lines: ~4302-4308

javascript
// Added validation for prompt parameter
if (prompt && prompt.length > 10000) {
  return res.status(400).json({ ok: false, error: 'prompt too long (max 10000 chars)' });
}
if (prompt && !/^[\w\s.,!?;:'"()-]*$/i.test(prompt)) {
  return res.status(400).json{ ok: false, error: 'invalid prompt characters' };
}


Fix 5: UI - Load Installed Skills on Page Load
File: src/js/main.js
Lines: ~3340-3365

javascript
// NEW: Track installed skills
let installedSkills = new Set();

// Load profiles and active profile's installed skills
try {
  const profRes = await api('/api/profiles');
  if (profRes.ok) profiles = profRes.profiles || [];
  // Find active profile and load its installed skills
  const activeProfile = profiles.find(p => p.active) || { name: 'default' };
  try {
    const instRes = await api(/api/skills/list/${activeProfile.name});
    if (instRes.ok && instRes.output) {
      const lines = instRes.output.split('\n');
      for (const line of lines) {
        const match = line.match(/[│┃]\s([^\s│┃][^\s│┃])\s*[│┃]/);
        if (match) installedSkills.add(match[1].trim());
      }
    }
  } catch {}
} catch {}


Fix 6: UI - Show Correct Button State
File: src/js/main.js
Lines: ~3402-3415 (browse), ~3457-3479 (search)

javascript
// BEFORE
<button class="btn btn-primary btn-sm" onclick="window.installSkill('${escapeHtml(s.name)}')">⬇️ Install</button>

// AFTER
const isInstalled = installedSkills.has(s.name);
const installBtn = isInstalled
  ? <button class="btn btn-ok btn-sm" disabled style="cursor:default;">✅ Installed</button>
  : <button class="btn btn-primary btn-sm" onclick="window.installSkill('${escapeHtml(s.name)}')">⬇️ Install</button>;


Fix 7: UI - Auto-refresh After Install
File: src/js/main.js

javascript
// BEFORE
setTimeout(() => overlay?.remove(), 2000);

// AFTER
setTimeout(() => {
  overlay?.remove();
  // Refresh skills page to update button states
  const skillsTab = document.querySelector('.tab[data-tab="skills"]');
  if (skillsTab) skillsTab.click();
}, 1500);

stamandster avatar Apr 23 '26 15:04 stamandster

✅ Fixed — commit fcc9743

Changes

server.js

  • execHermes() — added optional stdin param for piping data (e.g. confirmation prompts)
  • Skills uninstall — replaced unsafe shell(\echo y | hermes ...`)→execHermes([...args], 15000, 'y\n')` (Fix 3: Command Injection)

src/js/main.js

  • Skills Hub now fetches installed skills list on page init via /api/skills/list/:profile
  • Browse + Search pages show ✅ Installed (disabled) for already-installed skills instead of always showing Install button
  • After successful install, page auto-refreshes to update button states

Fixes Addressed

  • ✅ Fix 3: Replace shell() with execHermes() in skills uninstall
  • ✅ Fix 5: Load installed skills on page load
  • ✅ Fix 6: Show correct button state (Installed vs Install)
  • ✅ Fix 7: Auto-refresh after install

Fixes 1, 2, 4 were already implemented in the codebase.

Merged to main + deployed to staging.

xaspx avatar May 03 '26 17:05 xaspx