Repository navigation
Expand file tree
/
Copy pathvalidate-released.js
More file actions
156 lines (140 loc) · 6.63 KB
/
Copy pathvalidate-released.js
File metadata and controls
156 lines (140 loc) · 6.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/usr/bin/env node
/**
* Post-release validation: verifies artifacts/subs/all.yaml (published file)
* - All VMess have alterId
* - No invalid auth values (null/None/empty strings)
* - No metadata field leakage
* - YAML parses cleanly
* - Node stats (kept / rejected / rejection reasons)
* Run: node validate-released.js
*/
const fs = require('fs');
const path = require('path');
const yaml = require('js-yaml');
const scraper = require('./scraper');
const ALL_YAML = path.join(__dirname, 'artifacts', 'subs', 'all.yaml');
const MIHOMO_YAML = path.join(__dirname, 'artifacts', 'subs', 'mihomo.yaml');
let errors = [];
let warnings = [];
// ---------- all.yaml ----------
console.log('=== Validating ' + ALL_YAML + ' ===');
const allRaw = fs.readFileSync(ALL_YAML, 'utf8');
let doc;
try {
doc = yaml.load(allRaw);
} catch (e) {
console.error('FATAL: all.yaml YAML parse error:', e.message);
process.exit(1);
}
if (!doc || !Array.isArray(doc.proxies)) {
console.error('FATAL: all.yaml has no proxies array');
process.exit(1);
}
const proxies = doc.proxies;
console.log('Total proxies in all.yaml:', proxies.length);
// --- Check 0: exact standard-Clash type set (SOCKS5 is socks5, HTTPS is http+tls) ---
const STANDARD_CLASH_TYPES = new Set(['ss', 'vmess', 'trojan', 'http', 'socks5']);
const invalidTypes = proxies.filter(p => !STANDARD_CLASH_TYPES.has(p.type));
if (invalidTypes.length > 0) {
errors.push('all.yaml: unsupported proxy types: ' + [...new Set(invalidTypes.map(p => p.type))].join(', '));
} else {
console.log('✓ all.yaml contains only standard Clash proxy types');
}
// Count by type
const byType = {};
for (const p of proxies) byType[p.type] = (byType[p.type] || 0) + 1;
console.log('By type:', JSON.stringify(byType, null, 2));
// --- Check 1: all VMess have alterId ---
const vmessMissingAlterId = proxies.filter(p => p.type === 'vmess' && (p.alterId === undefined || p.alterId === null || p.alterId === ''));
if (vmessMissingAlterId.length > 0) {
errors.push('all.yaml: ' + vmessMissingAlterId.length + ' VMess proxies missing alterId: ' + vmessMissingAlterId.slice(0, 5).map(p => p.name).join(', '));
} else {
console.log('✓ All ' + (byType['vmess'] || 0) + ' VMess proxies have alterId');
}
// --- Check 2: no invalid auth values ---
const invalidAuth = [];
for (const p of proxies) {
for (const f of ['password', 'username']) {
if (p[f] !== undefined) {
const s = String(p[f]).trim().toLowerCase();
if (['null', 'none', 'undefined', ''].includes(s)) {
invalidAuth.push({ name: p.name, field: f, value: p[f] });
}
}
}
}
if (invalidAuth.length > 0) {
errors.push('all.yaml: ' + invalidAuth.length + ' proxies with invalid auth values, e.g.: ' + JSON.stringify(invalidAuth.slice(0, 3)));
} else {
console.log('✓ No invalid auth values (null/None/empty) in all.yaml');
}
// --- Check 3: no metadata leakage ---
const META_FIELDS = ['_region', 'speed', 'latency', 'qualityScore', 'fraudScore', 'detectLevel', '_orig'];
const metaLeak = proxies.filter(p => META_FIELDS.some(f => p[f] !== undefined));
if (metaLeak.length > 0) {
errors.push('all.yaml: ' + metaLeak.length + ' proxies with metadata field leakage: ' + metaLeak.slice(0, 3).map(p => p.name + '[' + META_FIELDS.find(f => p[f] !== undefined) + ']').join(', '));
} else {
console.log('✓ No metadata fields leaked to all.yaml');
}
// --- Check 4: VMess required fields (uuid, server, port) ---
const vmessIncomplete = proxies.filter(p => p.type === 'vmess' && (!p.uuid || !p.server || !Number.isInteger(p.port) || p.port < 1 || p.port > 65535));
if (vmessIncomplete.length > 0) {
errors.push('all.yaml: ' + vmessIncomplete.length + ' VMess proxies missing uuid/server/valid port');
} else {
console.log('✓ All VMess proxies have valid uuid/server/port');
}
// --- Check 5: SS/Trojan have password ---
const ssNoPass = proxies.filter(p => p.type === 'ss' && !p.password);
const trojanNoPass = proxies.filter(p => p.type === 'trojan' && !p.password);
if (ssNoPass.length > 0) errors.push('all.yaml: ' + ssNoPass.length + ' SS proxies without password');
if (trojanNoPass.length > 0) errors.push('all.yaml: ' + trojanNoPass.length + ' Trojan proxies without password');
console.log('✓ SS (' + ssNoPass.length + ') / Trojan (' + trojanNoPass.length + ') missing password (should be 0)');
// ---------- mihomo.yaml (spot check) ----------
console.log('\n=== Spot-checking ' + MIHOMO_YAML + ' ===');
const mihomoRaw = fs.readFileSync(MIHOMO_YAML, 'utf8');
const mihomoDoc = yaml.load(mihomoRaw);
if (!mihomoDoc?.proxies) {
errors.push('mihomo.yaml: no proxies array');
} else {
const mVmess = mihomoDoc.proxies.filter(p => p.type === 'vmess');
const INVALID_MI_TYPES = mihomoDoc.proxies.filter(p => p.type === 'socks' || p.type === 'https');
if (INVALID_MI_TYPES.length > 0) errors.push('mihomo.yaml: non-canonical proxy types socks/https found: ' + INVALID_MI_TYPES.length);
else console.log('✓ mihomo.yaml: no non-canonical socks/https proxy types');
const mMissing = mVmess.filter(p => p.alterId === undefined || p.alterId === null);
if (mMissing.length > 0) {
errors.push('mihomo.yaml: ' + mMissing.length + ' VMess missing alterId');
} else {
console.log('✓ mihomo.yaml: all ' + mVmess.length + ' VMess have alterId (' + mihomoDoc.proxies.length + ' total proxies)');
}
const mMetaLeak = mihomoDoc.proxies.filter(p => META_FIELDS.some(f => p[f] !== undefined));
if (mMetaLeak.length > 0) {
errors.push('mihomo.yaml: ' + mMetaLeak.length + ' proxies with metadata leakage');
} else {
console.log('✓ mihomo.yaml: no metadata leakage');
}
}
// ---------- Summary ----------
console.log('\n' + '='.repeat(60));
if (errors.length > 0) {
console.log('VALIDATION FAILED:');
for (const e of errors) console.log(' ✗ ' + e);
process.exit(1);
} else {
console.log('VALIDATION PASSED: all checks OK ✓');
}
// ---------- Node stats (compare baseline hash) ----------
const baselineFile = path.join(__dirname, 'baseline-subs-hash.json');
if (fs.existsSync(baselineFile)) {
const baseline = JSON.parse(fs.readFileSync(baselineFile, 'utf8'));
const crypto = require('crypto');
const current = {};
for (const f of ['all.yaml', 'mihomo.yaml', 'base64.txt', 'byxiaoxi.txt', 'kooker.jp.txt']) {
const p = path.join(__dirname, 'artifacts', 'subs', f);
if (fs.existsSync(p)) current[f] = crypto.createHash('md5').update(fs.readFileSync(p)).digest('hex');
}
console.log('\n=== File change vs baseline ===');
for (const [f, h] of Object.entries(current)) {
const changed = baseline[f] !== h;
console.log(' ' + (changed ? '✓ CHANGED ' : ' same ') + f + ': ' + h + (baseline[f] ? ' (was ' + baseline[f].substring(0, 8) + '...)' : ''));
}
}