santifer/career-ops · warning
⚠️ Font reference escapes fonts/, keeping original…
Error message
⚠️ Font reference escapes fonts/, keeping original reference: ${name} What it means
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.
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
Example fix
// before fontFamily: "../../Downloads/Inter.ttf" // after cp ~/Downloads/Inter.ttf fonts/ && fontFamily: "Inter.ttf"
Defensive patterns
Strategy: validation
Validate before calling
const { resolve, relative, isAbsolute } = require('path');
function fontIsSafe(fontsDir, name) {
const rel = relative(fontsDir, resolve(fontsDir, name));
return !rel.startsWith('..') && !isAbsolute(rel);
} Type guard
const isBareFontName = (name) => typeof name === 'string' && !name.includes('..') && !path.isAbsolute(name) && !name.includes('/'); Prevention
- 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
When it happens
Trigger: 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.
Common situations: Hand-edited templates referencing system fonts by absolute path ('/usr/share/fonts/...'), or typos like '../../myfont.ttf' in font config.
Understand the failure class
Background: Path traversal blocked: "path escapes the workspace" and "outside site root" errors when a path will not stay inside its allowed directory — this error's family across 26 libraries.
Related errors
- escapes the tracker workspace: (workspaceRoot= canonical=…
- local-parser: path escapes the project root
- output escapes the tracker workspace
- Refusing to write the PDF outside the tracker workspace
- Unsupported template format
AI-assisted analysis of santifer/career-ops@aac998c7ed (2026-09-16).
Data as JSON: /api/errors/086356fd03e12e12.
Report an issue: GitHub.
Appendix: source
Thrown at generate-pdf.mjs:1591
*
* @param {string} html - HTML that may reference url('./fonts/<file>').
* @returns {Promise<string>} HTML with local font references inlined.
*/
const _fontDataUrlCache = new Map();
export async function inlineLocalFonts(html) {
const FONT_REF = /url\(\s*(['"]?)\.\/fonts\/([^'")\s]+)\1\s*\)/g;
const MIME = { woff2: 'font/woff2', woff: 'font/woff', otf: 'font/otf', ttf: 'font/ttf' };
const fontsDir = resolve(__dirname, 'fonts');
const names = [...new Set([...html.matchAll(FONT_REF)].map((m) => m[2]))];
const dataUrls = new Map();
for (const name of names) {
// Containment check: ".." segments and absolute names (./fonts//etc/passwd)
// would otherwise resolve outside fonts/.
const fontPath = resolve(fontsDir, name);
const rel = relative(fontsDir, fontPath);
if (rel.startsWith('..') || isAbsolute(rel)) {
console.warn(`⚠️ Font reference escapes fonts/, keeping original reference: ${name}`);
continue;
}
if (_fontDataUrlCache.has(fontPath)) {
dataUrls.set(name, _fontDataUrlCache.get(fontPath));
continue;
}
try {
const buf = await readFile(fontPath);
const ext = name.slice(name.lastIndexOf('.') + 1).toLowerCase();
const dataUrl = `url('data:${MIME[ext] || 'application/octet-stream'};base64,${buf.toString('base64')}')`;
_fontDataUrlCache.set(fontPath, dataUrl);
dataUrls.set(name, dataUrl);
} catch (err) {
if (err?.code !== 'ENOENT') throw err;
console.warn(`⚠️ Font file not found, keeping original reference: fonts/${name}`);
}
}
return html.replace(FONT_REF, (match, _quote, name) => dataUrls.get(name) || match);View on GitHub (pinned to aac998c7ed)