fix: exclude source repository lookups from captured paths

This commit is contained in:
Thomas Durieux committed 2026-11-15 00:08:12 +00:00
1 parent 953767b2cd
commit 7d044525ce
6 files changed
+39 -10

No files matched your search

+15 -1
View File
@@ -23,7 +23,7 @@ describe('safe actionable exception diagnostics',()=>{
expect(safeRedisLog({ts:record.timestamp,level:'error',module:'route',raw:[record]}).raw[0]).include({requestPath,repoId:'demo-123'});
});
it('preserves anonymous endpoints at all outcomes through both API projections',async()=>{
for(const suffix of ['', '/', '/zip', '/files', '/files/docs/nested%20folder/', '/files/counts', '/files/search', '/options', '/refresh', '/coauthors', '/extend', '/file/README.md']){
for(const suffix of ['', '/', '/zip', '/files', '/files/counts', '/files/search', '/options', '/refresh', '/coauthors', '/extend', '/file/README.md']){
const requestPath='/api/repo/demo-123'+suffix;
expect(requestReproduction(requestPath+'?token=SECRET')).deep.equal({requestPath,repoId:'demo-123'});
for(const status of [200,304,404,500]){
@@ -35,6 +35,20 @@ describe('safe actionable exception diagnostics',()=>{
for(const suffix of ['/files/../secret','/files/%2fsecret','/files/%0aSECRET','/files/%252e%252e/secret','/zip?token=SECRET'])
expect(safeReproductionPath('/api/repo/demo-123'+suffix)).equal(undefined);
});
it('rejects upstream lookups for repositories named files at every logging boundary',()=>{
for(const action of ['readme','branches','tree','file']){
const requestPath='/api/repo/private-owner/files/'+action;
for(const suffix of ['', '/', '?token=SECRET']){
expect(requestReproduction(requestPath+suffix)).deep.equal({});
for(const status of [200,403,500]){
const row=logContext.run({requestPath:requestPath+suffix},()=>logRecord('error','route',['failure',{httpStatus:status}]));
expect(row).not.have.property('requestPath');expect(row).not.have.property('repoId');
const redis=safeRedisLog({ts:row.timestamp,level:'error',module:'route',raw:[{...row,requestPath:requestPath+suffix,repoId:'private-owner'}]});
expect(redis.raw[0]).not.have.property('requestPath');expect(redis.raw[0]).not.have.property('repoId');
}
}
}
});
it('preserves dotted allowlisted source files and anonymous/named async frames',()=>{
const error=new Error(secret);
error.stack='Error: '+secret+'\n at async '+path.resolve('src/server/routes/repository-public.ts')+':224:23\n at async printError ('+path.resolve('src/server/routes/route-utils.ts')+':200:7)\n at '+path.resolve('src/core/model/owner-alert-lifecycle.schema.ts')+':12:3\n at async https://'+secret+':1:2';
+16 -3
View File
@@ -48,13 +48,26 @@ describe("bounded request monitoring", function () {
});
it("records the actual listing path on successful requests while keeping metrics templated", async function () {
app.get('/api/repo/:repoId/files/*path',(_req,res)=>res.json([]));
await listen(); await fetch(server,'/api/repo/demo-123/files/docs/nested%20folder/?token=SECRET');
expect(logs[0][1]).include({status:200,requestPath:'/api/repo/demo-123/files/docs/nested%20folder/',repoId:'demo-123'});
app.get('/api/repo/:repoId/files',(_req,res)=>res.json([]));
await listen(); await fetch(server,'/api/repo/demo-123/files?path=docs%2Fnested&token=SECRET');
expect(logs[0][1]).include({status:200,requestPath:'/api/repo/demo-123/files',repoId:'demo-123'});
expect(JSON.stringify(logs)).not.include('SECRET');
expect(JSON.stringify(metrics.drain())).not.include('demo-123');
});
it("never captures upstream identities from files-named source repository handlers", async function () {
const {logRecord}=require('../src/core/log-record');
const records=[];
for(const action of ['readme','branches','tree','file'])
app.get('/api/repo/:owner/:repo/'+action,(_req,res)=>{
records.push(logRecord('error','route',['failure',{httpStatus:403}]));res.status(403).end();
});
await listen();
for(const action of ['readme','branches','tree','file'])
await fetch(server,'/api/repo/private-owner/files/'+action);
expect(JSON.stringify([...records,...logs])).not.include('private-owner');
});
it("keeps labels bounded and removes source identities and query values", function () {
expect(requestRoute("/api/repo/private-name/file/secret.txt?token=abc", "api")).to.equal("/api/repo/:repoId/file/:path");
expect(requestRoute("/api/repo/secret-owner/secret-repo/readme?branch=secret", "api")).to.equal("/api/repo/:owner/:repo/readme");