mirror of
https://github.com/pbakaus/impeccable.git
synced 2026-09-17 16:46:31 +03:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
869c887372 | ||
|
|
d008dd98c3 |
@@ -1955,19 +1955,20 @@ function scanCssTextForGlow(content) {
|
||||
return results;
|
||||
}
|
||||
|
||||
// Decorative two-axis grid backgrounds drawn with hairline
|
||||
// Decorative grid or line-field backgrounds drawn with hairline
|
||||
// linear-gradient layers tiled by a fixed pixel cell. Shared by the HTML
|
||||
// pattern pass and the regex source engine so standalone CSS, component
|
||||
// styles, and inline styles receive the same coverage. Both signals must
|
||||
// co-occur in one declaration block; unrelated rules must not add up across
|
||||
// the file. A single hairline is a line, divider, or rail, not a grid, even
|
||||
// when tiled by a 2D px cell. Returns [{ index, snippet }], capped at one
|
||||
// finding per source to match the page-level HTML check's existing behavior.
|
||||
// the file. Returns [{ index, snippet }], capped at one finding per source to
|
||||
// match the page-level HTML check's existing behavior.
|
||||
function scanCssTextForGridBackground(content) {
|
||||
const hairlineRe = /\b\d{1,3}px\s*,\s*transparent\s+\d{1,3}px/gi;
|
||||
const invertedHairlineRe = /transparent\s+calc\(100%\s*-\s*\d{1,3}px\)/gi;
|
||||
const sizeDeclPxRe = /background-size\s*:[^;{}"']*\b\d{1,3}px\b/i;
|
||||
const sizeDeclPxPairRe = /background-size\s*:[^;{}"']*\b\d{1,3}px\s+\d{1,3}px/i;
|
||||
const shorthandPxAnyRe = /\/\s*\d{1,3}px\b/;
|
||||
const shorthandPxPairRe = /\/\s*\d{1,3}px\s+\d{1,3}px/;
|
||||
const bgDeclRe = /\bbackground(?:-image)?\s*:\s*([^;{}"']*)/gi;
|
||||
const blockRe = /\{([^{}]*)\}|style\s*=\s*"([^"]*)"|style\s*=\s*'([^']*)'/gi;
|
||||
let blk;
|
||||
@@ -1984,10 +1985,13 @@ function scanCssTextForGridBackground(content) {
|
||||
}
|
||||
if (hairlineCount === 0) continue;
|
||||
const hasPxCell = sizeDeclPxRe.test(block) || shorthandPxAnyRe.test(bgJoined);
|
||||
if (hairlineCount >= 2 && hasPxCell) {
|
||||
const hasPxPairCell = sizeDeclPxPairRe.test(block) || shorthandPxPairRe.test(bgJoined);
|
||||
if ((hairlineCount >= 2 && hasPxCell) || hasPxPairCell) {
|
||||
return [{
|
||||
index: blk.index,
|
||||
snippet: 'two-axis grid-line gradient background',
|
||||
snippet: hairlineCount >= 2
|
||||
? 'two-axis grid-line gradient background'
|
||||
: 'px-tiled hairline line-field background',
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -721,19 +721,20 @@ function scanCssTextForGlow(content) {
|
||||
return results;
|
||||
}
|
||||
|
||||
// Decorative two-axis grid backgrounds drawn with hairline
|
||||
// Decorative grid or line-field backgrounds drawn with hairline
|
||||
// linear-gradient layers tiled by a fixed pixel cell. Shared by the HTML
|
||||
// pattern pass and the regex source engine so standalone CSS, component
|
||||
// styles, and inline styles receive the same coverage. Both signals must
|
||||
// co-occur in one declaration block; unrelated rules must not add up across
|
||||
// the file. A single hairline is a line, divider, or rail, not a grid, even
|
||||
// when tiled by a 2D px cell. Returns [{ index, snippet }], capped at one
|
||||
// finding per source to match the page-level HTML check's existing behavior.
|
||||
// the file. Returns [{ index, snippet }], capped at one finding per source to
|
||||
// match the page-level HTML check's existing behavior.
|
||||
function scanCssTextForGridBackground(content) {
|
||||
const hairlineRe = /\b\d{1,3}px\s*,\s*transparent\s+\d{1,3}px/gi;
|
||||
const invertedHairlineRe = /transparent\s+calc\(100%\s*-\s*\d{1,3}px\)/gi;
|
||||
const sizeDeclPxRe = /background-size\s*:[^;{}"']*\b\d{1,3}px\b/i;
|
||||
const sizeDeclPxPairRe = /background-size\s*:[^;{}"']*\b\d{1,3}px\s+\d{1,3}px/i;
|
||||
const shorthandPxAnyRe = /\/\s*\d{1,3}px\b/;
|
||||
const shorthandPxPairRe = /\/\s*\d{1,3}px\s+\d{1,3}px/;
|
||||
const bgDeclRe = /\bbackground(?:-image)?\s*:\s*([^;{}"']*)/gi;
|
||||
const blockRe = /\{([^{}]*)\}|style\s*=\s*"([^"]*)"|style\s*=\s*'([^']*)'/gi;
|
||||
let blk;
|
||||
@@ -750,10 +751,13 @@ function scanCssTextForGridBackground(content) {
|
||||
}
|
||||
if (hairlineCount === 0) continue;
|
||||
const hasPxCell = sizeDeclPxRe.test(block) || shorthandPxAnyRe.test(bgJoined);
|
||||
if (hairlineCount >= 2 && hasPxCell) {
|
||||
const hasPxPairCell = sizeDeclPxPairRe.test(block) || shorthandPxPairRe.test(bgJoined);
|
||||
if ((hairlineCount >= 2 && hasPxCell) || hasPxPairCell) {
|
||||
return [{
|
||||
index: blk.index,
|
||||
snippet: 'two-axis grid-line gradient background',
|
||||
snippet: hairlineCount >= 2
|
||||
? 'two-axis grid-line gradient background'
|
||||
: 'px-tiled hairline line-field background',
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -936,15 +936,23 @@ function createRequestHandler({ detectScript, liveScriptParts }) {
|
||||
const filePath = url.searchParams.get('path');
|
||||
if (!filePath || filePath.includes('..')) { res.writeHead(400); res.end('Bad path'); return; }
|
||||
const absPath = path.resolve(process.cwd(), filePath);
|
||||
// Confine to the project root. A bare `startsWith(cwd)` string check lets a
|
||||
// sibling dir whose name extends the root name (projeto -> projeto-backup)
|
||||
// slip through; compare on the relative path instead (same pattern as
|
||||
// sessionFileMetadataFromPollReply below). An empty rel means the request
|
||||
// resolved to the root directory itself, which this file route never serves.
|
||||
const rel = path.relative(process.cwd(), absPath);
|
||||
let realRoot, realTarget;
|
||||
try {
|
||||
realRoot = fs.realpathSync(process.cwd());
|
||||
realTarget = fs.realpathSync(absPath);
|
||||
} catch {
|
||||
res.writeHead(404); res.end('File not found'); return;
|
||||
}
|
||||
// Confine to the project root after symlink resolution. A bare
|
||||
// `startsWith(cwd)` string check lets a sibling dir whose name extends the
|
||||
// root name (projeto -> projeto-backup) slip through; compare on the
|
||||
// relative path instead (same pattern as sessionFileMetadataFromPollReply
|
||||
// below). An empty rel means the request resolved to the root directory
|
||||
// itself, which this file route never serves.
|
||||
const rel = path.relative(realRoot, realTarget);
|
||||
if (!rel || rel.startsWith('..') || path.isAbsolute(rel)) { res.writeHead(403); res.end('Forbidden'); return; }
|
||||
let content;
|
||||
try { content = fs.readFileSync(absPath, 'utf-8'); }
|
||||
try { content = fs.readFileSync(realTarget, 'utf-8'); }
|
||||
catch { res.writeHead(404); res.end('File not found'); return; }
|
||||
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
|
||||
res.end(content);
|
||||
|
||||
@@ -1278,14 +1278,6 @@ describe('detectHtml — generated-UI tells', () => {
|
||||
}
|
||||
});
|
||||
|
||||
it('codex-grid-background: 1D dashed rules and px-pair line-fields stay legal', async () => {
|
||||
const f = await detectHtml(path.join(FIXTURES, 'codex-grid-1d-pass.html'));
|
||||
assert.equal(
|
||||
f.filter(r => r.antipattern === 'codex-grid-background').length, 0,
|
||||
`1D tiled hairlines must not flag, got: ${f.filter(r => r.antipattern === 'codex-grid-background').map(r => r.snippet).join('; ')}`,
|
||||
);
|
||||
});
|
||||
|
||||
it('gemini-tells: both flag cases surface by default and pass cases stay legal', async () => {
|
||||
const findings = await detectHtml(path.join(FIXTURES, 'gemini-tells.html'));
|
||||
// Two flag cases: a CSS img:hover{transform} rule and a Tailwind hover:scale on <img>.
|
||||
|
||||
@@ -1806,9 +1806,11 @@ describe('codex-grid-background variants', () => {
|
||||
expect(grids(css)).toHaveLength(1);
|
||||
});
|
||||
|
||||
test('keeps single-axis hairline tiled by a px pair cell legal', () => {
|
||||
test('flags single-axis hairline tiled by a px pair cell', () => {
|
||||
const css = `body { background: linear-gradient(90deg, rgba(23,25,24,.035) 1px, transparent 1px) 0 0 / 40px 40px, #f4f1ea; }`;
|
||||
expect(grids(css)).toHaveLength(0);
|
||||
const f = grids(css);
|
||||
expect(f).toHaveLength(1);
|
||||
expect(f[0].snippet).toContain('line-field');
|
||||
});
|
||||
|
||||
test('keeps percent-tiled single hairlines (data-viz track rules) legal', () => {
|
||||
@@ -1816,36 +1818,6 @@ describe('codex-grid-background variants', () => {
|
||||
expect(grids(css)).toHaveLength(0);
|
||||
});
|
||||
|
||||
test('keeps 1D dashed dot rules legal', () => {
|
||||
const css = `.dot-rule {
|
||||
height: 5px;
|
||||
background-image: linear-gradient(90deg, rgba(255,255,255,.75) 5px, transparent 5px);
|
||||
background-size: 10px 5px;
|
||||
background-repeat: repeat-x;
|
||||
}`;
|
||||
expect(grids(css)).toHaveLength(0);
|
||||
});
|
||||
|
||||
test('keeps 1D progress rails with dash-period px pair tiles legal', () => {
|
||||
const css = `.progress-rail {
|
||||
background-image: linear-gradient(90deg, #eee 1px, transparent 1px);
|
||||
background-size: 8px 4px;
|
||||
background-repeat: repeat-x;
|
||||
}`;
|
||||
expect(grids(css)).toHaveLength(0);
|
||||
});
|
||||
|
||||
test('regex source engine keeps 1D dot rules legal', () => {
|
||||
const css = `.dot-rule {
|
||||
height: 5px;
|
||||
background-image: linear-gradient(90deg, rgba(255,255,255,.75) 5px, transparent 5px);
|
||||
background-size: 10px 5px;
|
||||
background-repeat: repeat-x;
|
||||
}`;
|
||||
const findings = detectText(css, 'dot-rule.css');
|
||||
expect(findings.filter(f => f.antipattern === 'codex-grid-background')).toHaveLength(0);
|
||||
});
|
||||
|
||||
test('classic two-axis background-size form still flags', () => {
|
||||
const css = `.hero { background-image:
|
||||
linear-gradient(#eee 1px, transparent 1px),
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>codex-grid-background 1D pass cases</title>
|
||||
<style>
|
||||
body { font-family: system-ui, sans-serif; margin: 0; color: #1a1a1a; background: #fff; }
|
||||
.dot-rule { height: 5px; background-image: linear-gradient(90deg, rgba(255,255,255,.75) 5px, transparent 5px); background-size: 10px 5px; background-repeat: repeat-x; }
|
||||
.progress-rail { height: 4px; background-image: linear-gradient(90deg, #eee 1px, transparent 1px); background-size: 8px 4px; background-repeat: repeat-x; }
|
||||
.line-field { height: 80px; background: linear-gradient(90deg, rgba(23,25,24,.035) 1px, transparent 1px) 0 0 / 40px 40px, #f4f1ea; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h2>Dotted horizontal rule</h2>
|
||||
<div class="dot-rule"></div>
|
||||
<h2>Progress rail</h2>
|
||||
<div class="progress-rail"></div>
|
||||
<h2>Single-axis px-pair line field</h2>
|
||||
<div class="line-field"></div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -5,8 +5,8 @@
|
||||
|
||||
import { describe, it, before, after } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { existsSync, mkdtempSync, readFileSync, writeFileSync, mkdirSync, rmSync, realpathSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import { existsSync, mkdtempSync, readFileSync, writeFileSync, mkdirSync, rmSync, realpathSync, symlinkSync } from 'node:fs';
|
||||
import { join, relative } from 'node:path';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { execFileSync, execSync, spawn } from 'node:child_process';
|
||||
import {
|
||||
@@ -3319,6 +3319,102 @@ colors: {}
|
||||
}
|
||||
});
|
||||
|
||||
it('/source rejects a symlink that points outside the project root', async () => {
|
||||
const outsideDir = mkdtempSync(join(tmpdir(), 'impeccable-live-outside-'));
|
||||
const outsideFile = join(outsideDir, 'secret.txt');
|
||||
writeFileSync(outsideFile, 'OUTSIDE SECRET');
|
||||
const linkPath = join(serverCwd, 'linked.txt');
|
||||
symlinkSync(outsideFile, linkPath);
|
||||
try {
|
||||
const res = await fetch(`http://localhost:${server.port}/source?token=${server.token}&path=linked.txt`);
|
||||
await res.text().catch(() => {});
|
||||
assert.equal(res.status, 403);
|
||||
} finally {
|
||||
rmSync(linkPath, { force: true });
|
||||
rmSync(outsideDir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
it('/source serves a symlink whose target stays inside the project', async () => {
|
||||
const nestedDir = join(serverCwd, 'alias');
|
||||
mkdirSync(nestedDir, { recursive: true });
|
||||
const realFile = join(nestedDir, 'page.html');
|
||||
writeFileSync(realFile, '<h1>via alias</h1>\n');
|
||||
const linkPath = join(serverCwd, 'alias-link.html');
|
||||
symlinkSync(realFile, linkPath);
|
||||
try {
|
||||
const res = await fetch(`http://localhost:${server.port}/source?token=${server.token}&path=alias-link.html`);
|
||||
assert.equal(res.status, 200);
|
||||
const text = await res.text();
|
||||
assert.ok(text.includes('via alias'));
|
||||
} finally {
|
||||
rmSync(linkPath, { force: true });
|
||||
rmSync(nestedDir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
it('/source returns 404 for a broken symlink', async () => {
|
||||
const linkPath = join(serverCwd, 'broken-link.txt');
|
||||
symlinkSync(join(serverCwd, 'missing-target.txt'), linkPath);
|
||||
try {
|
||||
const res = await fetch(`http://localhost:${server.port}/source?token=${server.token}&path=broken-link.txt`);
|
||||
await res.text().catch(() => {});
|
||||
assert.equal(res.status, 404);
|
||||
} finally {
|
||||
rmSync(linkPath, { force: true });
|
||||
}
|
||||
});
|
||||
|
||||
it('/source rejects a directory symlink whose nested file is outside the project', async () => {
|
||||
const outsideDir = mkdtempSync(join(tmpdir(), 'impeccable-live-outside-dir-'));
|
||||
writeFileSync(join(outsideDir, 'cred.txt'), 'OUTSIDE SECRET');
|
||||
const linkPath = join(serverCwd, 'escape-dir');
|
||||
symlinkSync(outsideDir, linkPath);
|
||||
try {
|
||||
const res = await fetch(`http://localhost:${server.port}/source?token=${server.token}&path=escape-dir/cred.txt`);
|
||||
await res.text().catch(() => {});
|
||||
assert.equal(res.status, 403);
|
||||
} finally {
|
||||
rmSync(linkPath, { force: true });
|
||||
rmSync(outsideDir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
it('/source rejects a chained symlink that resolves outside the project', async () => {
|
||||
const outsideDir = mkdtempSync(join(tmpdir(), 'impeccable-live-outside-chain-'));
|
||||
const outsideFile = join(outsideDir, 'secret.txt');
|
||||
writeFileSync(outsideFile, 'OUTSIDE SECRET');
|
||||
const midPath = join(serverCwd, 'mid-link.txt');
|
||||
const linkPath = join(serverCwd, 'double-out.txt');
|
||||
symlinkSync(outsideFile, midPath);
|
||||
symlinkSync(midPath, linkPath);
|
||||
try {
|
||||
const res = await fetch(`http://localhost:${server.port}/source?token=${server.token}&path=double-out.txt`);
|
||||
await res.text().catch(() => {});
|
||||
assert.equal(res.status, 403);
|
||||
} finally {
|
||||
rmSync(linkPath, { force: true });
|
||||
rmSync(midPath, { force: true });
|
||||
rmSync(outsideDir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
it('/source rejects a relative symlink that points outside the project', async () => {
|
||||
const outsideDir = mkdtempSync(join(tmpdir(), 'impeccable-live-outside-rel-'));
|
||||
const outsideFile = join(outsideDir, 'secret.txt');
|
||||
writeFileSync(outsideFile, 'OUTSIDE SECRET');
|
||||
const linkPath = join(serverCwd, 'rel-out.txt');
|
||||
symlinkSync(relative(serverCwd, outsideFile), linkPath);
|
||||
try {
|
||||
const res = await fetch(`http://localhost:${server.port}/source?token=${server.token}&path=rel-out.txt`);
|
||||
await res.text().catch(() => {});
|
||||
assert.equal(res.status, 403);
|
||||
} finally {
|
||||
rmSync(linkPath, { force: true });
|
||||
rmSync(outsideDir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
it('/modern-screenshot.js serves the vendored UMD build', async () => {
|
||||
const res = await fetch(`http://localhost:${server.port}/modern-screenshot.js`);
|
||||
assert.equal(res.status, 200);
|
||||
|
||||
Reference in New Issue
Block a user