fix(git): SSRF-Prüfung via net.BlockList, Pull unter Lock neu lesen, Autosave 60 s für Git-Brews
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e8d6e215e8
commit
de3f157e18
7 files changed
+44
-18
No files matched your search
@@ -343,8 +343,10 @@ export const createGitService = ({ cfg, getStorage, api, splitTextStyleAndMetada
|
||||
},
|
||||
|
||||
async pull(account, editId) {
|
||||
const brew = await loadEditableBrew(editId, account);
|
||||
return svc.locks.withKey(brew.id, async ()=>{
|
||||
const first = await loadEditableBrew(editId, account);
|
||||
return svc.locks.withKey(first.id, async ()=>{
|
||||
// Brew und Link unter dem Lock neu lesen, damit ein gleichzeitiger Save nicht überschrieben wird
|
||||
const brew = await loadEditableBrew(editId, account);
|
||||
const link = await storage().brewGitLinks.findByBrewId(brew.id);
|
||||
if(!link) throw new GitError('G08', 'Der Brew ist nicht mit Git verknüpft.');
|
||||
const conn = await storage().gitConnections.findById(link.connectionId);
|
||||
|
||||
@@ -81,7 +81,7 @@ describe('URL-Policy (SSRF)', ()=>{
|
||||
await expect(assertUrlAllowed('https://git.example.test:8443/a/b.git', cfg, { lookup: pub })).resolves.toBeDefined();
|
||||
});
|
||||
|
||||
test.each(['127.0.0.1', '10.1.2.3', '172.16.0.1', '172.31.255.255', '192.168.1.1', '169.254.169.254', '100.64.0.1', '0.0.0.0', '::1', 'fd00::1', 'fe80::1', '::ffff:127.0.0.1', '224.0.0.1'])('%s gilt als intern', (ip)=>{
|
||||
test.each(['127.0.0.1', '10.1.2.3', '172.16.0.1', '172.31.255.255', '192.168.1.1', '169.254.169.254', '100.64.0.1', '0.0.0.0', '::1', 'fd00::1', 'fe80::1', '::ffff:127.0.0.1', '::ffff:7f00:1', '::ffff:a9fe:a9fe', '::ffff:10.0.0.1', '0:0:0:0:0:ffff:7f00:1', '64:ff9b::7f00:1', '224.0.0.1'])('%s gilt als intern', (ip)=>{
|
||||
expect(isPrivateAddress(ip)).toBe(true);
|
||||
});
|
||||
test.each(['8.8.8.8', '93.184.216.34', '172.32.0.1', '2606:4700::1111'])('%s gilt als öffentlich', (ip)=>{
|
||||
|
||||
@@ -18,19 +18,22 @@ export const parseRepoUrl = (value, { allowHttp = false } = {})=>{
|
||||
|
||||
const hostMatches = (host, pattern)=>pattern.startsWith('*.') ? host.endsWith(pattern.slice(1)) && host.length > pattern.length - 1 : host === pattern;
|
||||
|
||||
const v4Private = (ip)=>{
|
||||
const [a, b] = ip.split('.').map(Number);
|
||||
return a === 0 || a === 10 || a === 127 || (a === 100 && b >= 64 && b <= 127) || (a === 169 && b === 254)
|
||||
|| (a === 172 && b >= 16 && b <= 31) || (a === 192 && b === 168) || a >= 224;
|
||||
};
|
||||
const blocked = new net.BlockList();
|
||||
[
|
||||
['0.0.0.0', 8], ['10.0.0.0', 8], ['100.64.0.0', 10], ['127.0.0.0', 8], ['169.254.0.0', 16],
|
||||
['172.16.0.0', 12], ['192.0.0.0', 24], ['192.168.0.0', 16], ['198.18.0.0', 15], ['224.0.0.0', 3]
|
||||
].forEach(([n, p])=>blocked.addSubnet(n, p, 'ipv4'));
|
||||
[
|
||||
['::', 128], ['::1', 128], ['fc00::', 7], ['fe80::', 10], ['ff00::', 8],
|
||||
// IPv4-gemappte Adressen (::ffff:a.b.c.d / ::ffff:a9fe:a9fe) prüft BlockList selbst gegen die IPv4-Regeln
|
||||
['64:ff9b::', 96], // NAT64
|
||||
['2002::', 16] // 6to4
|
||||
].forEach(([n, p])=>blocked.addSubnet(n, p, 'ipv6'));
|
||||
|
||||
export const isPrivateAddress = (address)=>{
|
||||
let ip = address.toLowerCase();
|
||||
if(ip.startsWith('::ffff:') && net.isIPv4(ip.slice(7))) ip = ip.slice(7);
|
||||
if(net.isIPv4(ip)) return v4Private(ip);
|
||||
if(net.isIPv6(ip)) {
|
||||
return ip === '::' || ip === '::1' || /^f[cd]/.test(ip) || /^fe[89ab]/.test(ip) || ip.startsWith('ff');
|
||||
}
|
||||
const ip = String(address).toLowerCase().replace(/^\[|\]$/g, '').split('%')[0];
|
||||
if(net.isIPv4(ip)) return blocked.check(ip, 'ipv4');
|
||||
if(net.isIPv6(ip)) return blocked.check(ip, 'ipv6');
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user