{"record":{"id":"086356fd03e12e12","repo":"santifer/career-ops","slug":"font-reference-escapes-fonts-keeping-origina","errorCode":null,"errorMessage":"⚠️  Font reference escapes fonts/, keeping original reference: ${name}","messagePattern":"⚠️  Font reference escapes fonts/, keeping original reference: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"generate-pdf.mjs","lineNumber":1591,"sourceCode":" *\n * @param {string} html - HTML that may reference url('./fonts/<file>').\n * @returns {Promise<string>} HTML with local font references inlined.\n */\nconst _fontDataUrlCache = new Map();\n\nexport async function inlineLocalFonts(html) {\n  const FONT_REF = /url\\(\\s*(['\"]?)\\.\\/fonts\\/([^'\")\\s]+)\\1\\s*\\)/g;\n  const MIME = { woff2: 'font/woff2', woff: 'font/woff', otf: 'font/otf', ttf: 'font/ttf' };\n  const fontsDir = resolve(__dirname, 'fonts');\n  const names = [...new Set([...html.matchAll(FONT_REF)].map((m) => m[2]))];\n  const dataUrls = new Map();\n  for (const name of names) {\n    // Containment check: \"..\" segments and absolute names (./fonts//etc/passwd)\n    // would otherwise resolve outside fonts/.\n    const fontPath = resolve(fontsDir, name);\n    const rel = relative(fontsDir, fontPath);\n    if (rel.startsWith('..') || isAbsolute(rel)) {\n      console.warn(`⚠️  Font reference escapes fonts/, keeping original reference: ${name}`);\n      continue;\n    }\n    if (_fontDataUrlCache.has(fontPath)) {\n      dataUrls.set(name, _fontDataUrlCache.get(fontPath));\n      continue;\n    }\n    try {\n      const buf = await readFile(fontPath);\n      const ext = name.slice(name.lastIndexOf('.') + 1).toLowerCase();\n      const dataUrl = `url('data:${MIME[ext] || 'application/octet-stream'};base64,${buf.toString('base64')}')`;\n      _fontDataUrlCache.set(fontPath, dataUrl);\n      dataUrls.set(name, dataUrl);\n    } catch (err) {\n      if (err?.code !== 'ENOENT') throw err;\n      console.warn(`⚠️  Font file not found, keeping original reference: fonts/${name}`);\n    }\n  }\n  return html.replace(FONT_REF, (match, _quote, name) => dataUrls.get(name) || match);","sourceCodeStart":1573,"sourceCodeEnd":1609,"githubUrl":"https://github.com/santifer/career-ops/blob/aac998c7ed7248ea853b720ceeb1fdbeb322fc5d/generate-pdf.mjs#L1573-L1609","documentation":"When inlining fonts as data URLs, generate-pdf.mjs resolves each referenced font name against the fonts/ directory and verifies containment via relative(). If the resolved path escapes fonts/ (a '..' segment or absolute-style name like './fonts//etc/passwd'), it warns and skips embedding, keeping the original font reference in the HTML instead. This is a path-traversal guard, not an exception.","triggerScenarios":"A CV template or config references a font by a name containing '..' path segments, an absolute path, or any string that resolve(fontsDir, name) places outside fontsDir.","commonSituations":"Hand-edited templates referencing system fonts by absolute path ('/usr/share/fonts/...'), or typos like '../../myfont.ttf' in font config.","solutions":["Move the font file into the fonts/ directory and reference it by bare filename","Remove '..' segments or absolute paths from the font reference","Verify the font name matches a file actually present in fonts/","Re-run PDF generation and confirm the warning is gone"],"exampleFix":"// before\nfontFamily: \"../../Downloads/Inter.ttf\"\n// after\ncp ~/Downloads/Inter.ttf fonts/ && fontFamily: \"Inter.ttf\"","handlingStrategy":"validation","validationCode":"const { resolve, relative, isAbsolute } = require('path');\nfunction fontIsSafe(fontsDir, name) {\n  const rel = relative(fontsDir, resolve(fontsDir, name));\n  return !rel.startsWith('..') && !isAbsolute(rel);\n}","typeGuard":"const isBareFontName = (name) => typeof name === 'string' && !name.includes('..') && !path.isAbsolute(name) && !name.includes('/');","tryCatchPattern":null,"preventionTips":["Always place custom fonts inside fonts/ and reference bare filenames","Never use absolute paths or '..' segments in font config","Verify font references resolve with a quick existence check before building the PDF"],"tags":["path-traversal","fonts","security","pdf-generation"],"backgroundTag":"path-traversal-blocked","analyzedSha":"aac998c7ed7248ea853b720ceeb1fdbeb322fc5d","analyzedAt":"2026-09-16T06:35:29.214Z","contentChangedAt":"2026-09-16T06:35:29.214Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}