fix: P0 hotfixes — API regression, code block parser, chmod override
Fixes #1394 — _combined_redact() crashes with TypeError on older hermes-agent builds that lack the 'force' kwarg in redact_sensitive_text(). Wrap the call in try/except to gracefully fall back. Fixes #1397 — Two bugs in the code block tree-view renderer: 1. Newlines in data-raw HTML attribute are collapsed to spaces by the browser (HTML spec). Encode \n as to preserve multi-line content. 2. jsyaml lazy-load was never triggered when the library wasn't loaded yet. Now defers init and retries after _loadJsyamlThen() completes. Fixes #1389 — fix_credential_permissions() now honors HERMES_SKIP_CHMOD=1 as a complete bypass, and when HERMES_HOME_MODE is set, only strips world bits (0o007) instead of forcing chmod 0600 — preserving intentional group access for Docker setups.
This commit is contained in:
@@ -165,7 +165,12 @@ def _build_redact_fn():
|
||||
# connection strings, Telegram bot tokens) run regardless of the user's
|
||||
# HERMES_REDACT_SECRETS opt-in. The local fallback then handles the
|
||||
# common short-prefix shapes the agent omits (ghp_, sk-, hf_, AKIA).
|
||||
return _fallback_redact(redact_sensitive_text(text, force=True))
|
||||
try:
|
||||
agent_redacted = redact_sensitive_text(text, force=True)
|
||||
except TypeError:
|
||||
# Older hermes-agent builds that predate the force kwarg.
|
||||
agent_redacted = redact_sensitive_text(text)
|
||||
return _fallback_redact(agent_redacted)
|
||||
|
||||
return _combined_redact
|
||||
|
||||
|
||||
@@ -14,7 +14,25 @@ _SENSITIVE_FILES = (
|
||||
|
||||
|
||||
def fix_credential_permissions() -> None:
|
||||
"""Ensure sensitive files in HERMES_HOME are chmod 600 (owner-only)."""
|
||||
"""Ensure sensitive files in HERMES_HOME have safe permissions.
|
||||
|
||||
Respects:
|
||||
- HERMES_SKIP_CHMOD=1 → bypass entirely
|
||||
- HERMES_HOME_MODE → group bits are allowed if set by the operator,
|
||||
only world-readable/world-writable files are fixed
|
||||
"""
|
||||
if os.environ.get('HERMES_SKIP_CHMOD', '').strip() in ('1', 'true'):
|
||||
return
|
||||
|
||||
# Parse operator-declared mode to know if group bits are intentional
|
||||
declared_mode = None
|
||||
raw_mode = os.environ.get('HERMES_HOME_MODE', '').strip()
|
||||
if raw_mode:
|
||||
try:
|
||||
declared_mode = int(raw_mode, 8)
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
hermes_home = Path(os.environ.get('HERMES_HOME', str(Path.home() / '.hermes')))
|
||||
if not hermes_home.is_dir():
|
||||
return
|
||||
@@ -24,9 +42,15 @@ def fix_credential_permissions() -> None:
|
||||
continue
|
||||
try:
|
||||
current = stat.S_IMODE(fpath.stat().st_mode)
|
||||
if current & 0o077: # group or other bits set
|
||||
fpath.chmod(0o600)
|
||||
print(f' [security] fixed permissions on {fpath.name} ({oct(current)} -> 0600)', flush=True)
|
||||
# If operator declared a mode, allow group bits but still fix world bits
|
||||
if declared_mode is not None:
|
||||
if current & 0o007: # other bits set (world-readable/writable)
|
||||
fpath.chmod(current & ~0o007)
|
||||
print(f' [security] removed world bits on {fpath.name} ({oct(current)} -> {oct(current & ~0o007)})', flush=True)
|
||||
else:
|
||||
if current & 0o077: # group or other bits set
|
||||
fpath.chmod(0o600)
|
||||
print(f' [security] fixed permissions on {fpath.name} ({oct(current)} -> 0600)', flush=True)
|
||||
except OSError:
|
||||
pass # best-effort; don't abort startup
|
||||
|
||||
|
||||
16
static/ui.js
16
static/ui.js
@@ -1331,8 +1331,11 @@ function renderMd(raw){
|
||||
// For JSON/YAML blocks, add tree-view placeholder with raw data
|
||||
} else if(lang==='json'||lang==='yaml'){
|
||||
const rawCode=esc(code.replace(/\n$/,''));
|
||||
// Encode newlines as to prevent HTML attribute normalization
|
||||
// (browsers collapse \n to spaces inside attribute values).
|
||||
const rawAttr=rawCode.replace(/"/g,'"').replace(/\n/g,' ');
|
||||
const blockId='tree-'+Math.random().toString(36).slice(2,10);
|
||||
_preBlock_stash.push(`<div class="code-tree-wrap" data-raw="${rawCode.replace(/"/g,'"')}" data-lang="${lang}" id="${blockId}">${h}<pre class="tree-raw-view"><code${langAttr}>${rawCode}</code></pre></div>`);
|
||||
_preBlock_stash.push(`<div class="code-tree-wrap" data-raw="${rawAttr}" data-lang="${lang}" id="${blockId}">${h}<pre class="tree-raw-view"><code${langAttr}>${rawCode}</code></pre></div>`);
|
||||
// CSV blocks → render as styled table
|
||||
} else if(lang==='csv'){
|
||||
const rows=code.replace(/\n$/,'').split('\n').filter(r=>r.trim());
|
||||
@@ -3927,7 +3930,6 @@ function _loadJsyamlThen(cb){
|
||||
|
||||
function initTreeViews(){
|
||||
document.querySelectorAll('.code-tree-wrap:not([data-tree-init])').forEach(wrap=>{
|
||||
wrap.setAttribute('data-tree-init','1');
|
||||
const rawText=wrap.dataset.raw;
|
||||
const lang=wrap.dataset.lang;
|
||||
let parsed=null;
|
||||
@@ -3939,10 +3941,16 @@ function initTreeViews(){
|
||||
if(typeof jsyaml!=='undefined'){
|
||||
try{ parsed=jsyaml.load(rawText); }catch(e){ parseFailed=true; }
|
||||
}else{
|
||||
// Trigger async load, leave as raw for now
|
||||
parseFailed=true;
|
||||
// Defer: remove init marker so we retry after load.
|
||||
// Note: if CDN load fails, s.onerror does NOT call back —
|
||||
// the wrap stays un-initialised (raw view only), which is safe.
|
||||
wrap.removeAttribute('data-tree-init');
|
||||
_loadJsyamlThen(initTreeViews);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Mark as initialised only after we've committed to a render decision
|
||||
wrap.setAttribute('data-tree-init','1');
|
||||
if(!parsed || typeof parsed!=='object'){
|
||||
if(parseFailed){
|
||||
const hint=wrap.querySelector('.tree-raw-view');
|
||||
|
||||
Reference in New Issue
Block a user