Allow loopback origins on any port when configured (http://127.0.0.1:*)
An app installed through Even Hub is served by the Even phone app from http://127.0.0.1:<port>, and the port changed between two launches on a real phone (40315, then another). An exact-origin allow-list therefore cannot admit it. HERMEVEN_ALLOWED_ORIGINS now accepts one wildcard form, the port of a loopback address over http (127.0.0.1, localhost, [::1]), off unless configured. No other wildcard is accepted. CORS remains advisory: every route still requires the device credential. Tests: 224 unit/integration. Not reviewed, not deployed. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
@@ -39,6 +39,28 @@ describe('configuration', () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it('the only origin wildcard is the port of a loopback address over http', () => {
|
||||
const c = loadConfig({ ...base, HERMEVEN_ALLOWED_ORIGINS: 'https://a.example, http://127.0.0.1:*' });
|
||||
expect(c.allowedOrigins).toEqual(['https://a.example']);
|
||||
expect(c.allowedLoopbackAnyPort).toEqual(['127.0.0.1']);
|
||||
expect(loadConfig(base).allowedLoopbackAnyPort).toEqual([]);
|
||||
for (const bad of [
|
||||
'*',
|
||||
'http://*',
|
||||
'http://*:8080',
|
||||
'https://127.0.0.1:*', // https wildcard not offered
|
||||
'http://192.168.1.20:*', // LAN
|
||||
'http://10.0.0.5:*',
|
||||
'http://example.com:*',
|
||||
'https://*.example.com',
|
||||
'http://127.0.0.1:*/', // trailing slash: not the exact form
|
||||
'http://127.0.0.2:*',
|
||||
'http://127.0.0.1.example.com:*',
|
||||
]) {
|
||||
expect(() => loadConfig({ ...base, HERMEVEN_ALLOWED_ORIGINS: bad }), bad).toThrow(ConfigError);
|
||||
}
|
||||
});
|
||||
|
||||
it('derives the audio byte cap from the capture cap and never puts secrets in error text', () => {
|
||||
const config = loadConfig({ ...base, HERMEVEN_CAPTURE_MAX_SECONDS: '10' });
|
||||
expect(config.limits.audioMaxBytes).toBe(11 * 32000);
|
||||
|
||||
Reference in New Issue
Block a user