mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-12-03 00:59:33 +01:00
fix(html-view): apply the dot and extension rules to the resolved path
The serving route checked hidden segments and the asset allowlist on the requested name only; after realpath it checked containment and the blocklist. A symlink `cfg.json -> .git/config` inside the page's folder was therefore served as 200 application/json. The dot rule now also runs on the segments of relative(rootDir, resolvedPath), and the extension allowlist on the resolved file name, which also types the response. Both realpath calls on the request path (the mint of an out-of-workspace file and the serving route) are now `await fs.realpath` instead of realpathSync, so a slow mount stalls one request, not the event loop. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
ded7911d1e
commit
fe50ad0be3
4 files changed
+31
-11
No files matched your search
@@ -94,6 +94,21 @@ describe('html-view routes', () => {
|
||||
}
|
||||
});
|
||||
|
||||
it('applies the dot and extension rules to where a symlink lands, not only to its name', async () => {
|
||||
mkdirSync(join(workspace, '.git'));
|
||||
writeFileSync(join(workspace, '.git', 'config'), '[remote "origin"]');
|
||||
symlinkSync(join(workspace, '.git', 'config'), join(workspace, 'cfg.json'));
|
||||
symlinkSync(join(workspace, 'notes.sh'), join(workspace, 'notes.css'));
|
||||
// A link that stays inside the folder and lands on an asset still works.
|
||||
symlinkSync(join(workspace, 'data.json'), join(workspace, 'latest.json'));
|
||||
const base = (await openUrl()).replace(/index\.html$/, '');
|
||||
expect((await harness.app.inject({ method: 'GET', url: `${base}cfg.json` })).statusCode).toBe(404);
|
||||
expect((await harness.app.inject({ method: 'GET', url: `${base}notes.css` })).statusCode).toBe(404);
|
||||
const ok = await harness.app.inject({ method: 'GET', url: `${base}latest.json` });
|
||||
expect(ok.statusCode).toBe(200);
|
||||
expect(ok.headers['content-type']).toContain('application/json');
|
||||
});
|
||||
|
||||
it('refuses an unknown or revoked capability', async () => {
|
||||
const url = await openUrl();
|
||||
expect(
|
||||
|
||||
Reference in new issue
Block a user