{"record":{"id":"2eabcc71d374ce3f","repo":"ruvnet/RuView","slug":"brain-line-index-1-error-message","errorCode":null,"errorMessage":"brain line ${index + 1}: ${error.message}","messagePattern":"brain line (.+?): (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"harness/homecore/src/brain.js","lineNumber":82,"sourceCode":"  if (canonical && record.reviewed !== true) errors.push('canonical records must be reviewed');\n  const combined = `${record.title || ''}\\n${record.content || ''}`;\n  if (SECRET.test(combined)) errors.push('record appears to contain a secret');\n  if (INJECTION.test(combined)) errors.push('record contains instruction-like prompt injection');\n  return errors;\n}\n\nexport function loadBrain(path = CORPUS_PATH) {\n  const raw = readFileSync(path, 'utf8').replace(/\\r\\n/g, '\\n');\n  if (Buffer.byteLength(raw) > 1_048_576) throw new Error('brain corpus exceeds 1 MiB');\n  const records = raw.split('\\n').filter(Boolean).map((line, index) => {\n    if (Buffer.byteLength(line) > 16_384) {\n      throw new Error(`brain line ${index + 1}: exceeds 16 KiB`);\n    }\n    let record;\n    try {\n      record = JSON.parse(line);\n    } catch (error) {\n      throw new Error(`brain line ${index + 1}: ${error.message}`);\n    }\n    const errors = validateBrainRecord(record, { canonical: true });\n    if (errors.length) throw new Error(`brain line ${index + 1}: ${errors.join('; ')}`);\n    return Object.freeze(record);\n  });\n  if (records.length > 1000) throw new Error('brain corpus exceeds 1000 records');\n  const ids = new Set();\n  for (const record of records) {\n    if (ids.has(record.id)) throw new Error(`duplicate brain id: ${record.id}`);\n    ids.add(record.id);\n  }\n  return { records, digest: sha256(raw), bytes: Buffer.byteLength(raw) };\n}\n\nfunction terms(value) {\n  return new Set(String(value).toLowerCase().match(/[a-z0-9][a-z0-9_-]{1,}/g) || []);\n}\n","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/ruvnet/RuView/blob/4685618388a5e49fad5b3005806f3bdd6a7c25c3/harness/homecore/src/brain.js#L64-L100","documentation":"_authenticate_request (auth.py:249) raises AuthenticationError('Missing authorization header') when the request carries no Authorization header at all AND _requires_auth() is true, i.e. the path starts with /api/ or /ws/. Requests to other paths without a header pass through unauthenticated.","triggerScenarios":"curl http://host/api/anything with no -H 'Authorization: ...'; a WebSocket client connecting to /ws/feed without a token in the header; a frontend that stores the token in a variable but forgets to attach it to fetch/axios calls; browser preflight/introspection calls that strip headers.","commonSituations":"Client not yet logged in but already calling protected endpoints; proxy (nginx) or CORS configuration stripping the Authorization header; token attach code conditioned on a flag that is false; curl scripts missing the header.","solutions":["Send the header: Authorization: Bearer <access_token> obtained from the login endpoint","If the header is sent but still missing server-side, check reverse-proxy/CORS config for header stripping","Confirm the endpoint really requires auth - only /api/* and /ws/* prefixes do"],"exampleFix":"# before\nresp = requests.get(\"http://host/api/users\")\n# after\nresp = requests.get(\"http://host/api/users\", headers={\"Authorization\": f\"Bearer {token}\"})","handlingStrategy":"validation","validationCode":"def protected_call_ready(path: str, headers: dict) -> bool:\n    \"\"\"Paths under /api/ or /ws/ need an Authorization header.\"\"\"\n    needs_auth = path.startswith(\"/api/\") or path.startswith(\"/ws/\")\n    return (not needs_auth) or bool(headers.get(\"Authorization\"))","typeGuard":"def has_bearer_header(headers: dict) -> bool:\n    return isinstance(headers.get(\"Authorization\"), str) and bool(headers[\"Authorization\"].strip())","tryCatchPattern":"from src.middleware.auth import AuthenticationError\n\ntry:\n    user = await middleware._authenticate_request(request)\nexcept AuthenticationError as e:\n    if str(e) == \"Missing authorization header\":\n        return PlainTextResponse(\"Bearer token required\", status_code=401,\n                                 headers={\"WWW-Authenticate\": \"Bearer\"})\n    raise","preventionTips":["Centralize header attachment in one HTTP client wrapper","Verify proxies forward the Authorization header","Login before any /api/* call in scripts and tests"],"tags":["auth","http-headers","fastapi"],"backgroundTag":null,"analyzedSha":"4685618388a5e49fad5b3005806f3bdd6a7c25c3","analyzedAt":"2026-08-16T06:09:40.886Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}