Phone UI and touch precision overhaul, proxy fixes, Orbital Uplink, four new maps
Phone panels (reviewed + QA'd, matrix of 22 layouts with real taps/bounding boxes): - selected-tower action bar over the board (Upgrade/Sell/Target/close), info panel updated in place so taps are never lost, scrollable palette for 7+ towers, overlays with pinned footers (Help "Got it", Play solo, Join always visible), tappable room chip to invite, reduced-motion/contrast/forced-colors fixes, paused state, partner cursor labels, bigger level pips and owner flags - touch input rewritten around "pointerdown commits nothing": pinch never builds, 10px tap slop, palm-proof pinch, long-press pings with any tool armed, nudge arrows for precise placement, hotkey repeat guard, proportional wheel zoom - new e2e: select/sell, info-panel stability, UI states, touch precision; camera unit tests Proxy/server (reproduced against real nginx 1.26 with NPM v2.16 config): - Origin check works when the proxy drops a non-default port, TRUSTED_PROXIES for proxies on global IPv6/CGNAT addresses, service worker no longer serves nginx's 502 page, DEPLOY.md corrected (NPM default read timeout is 90 s, Advanced-tab limits, path-prefix, cookie size, per-IP cap behaviour) Content: - Orbital Uplink: 4-level endgame tower (450 + 500/800/1200 credits): piercing armour-ignoring beam, blast and lingering slow, ground+air, range 11-14; glyph, beam effect, sound, help text, unit tests - Maps: The Canyon, Archipelago, Fortress, Pinwheel (7 maps total) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tb8pW2KAN4oFkh1aK1BfD8
This commit is contained in:
parent
dad0382e10
commit
a5bd09d505
22 changed files with 2423 additions and 405 deletions
|
|
@ -1156,6 +1156,143 @@ test('per-IP socket cap uses X-Forwarded-For behind a private/loopback peer; 429
|
|||
});
|
||||
});
|
||||
|
||||
// ================================================================ proxy findings (docs/review-2026-10-09, proxy-*)
|
||||
test('Origin check: a trusted proxy that drops the port from Host (nginx $host, nginx Proxy Manager) on a non-default public port', () => {
|
||||
const req = (h, peer) => ({ headers: h, socket: { remoteAddress: peer || '10.0.0.2' } });
|
||||
const o = { trustProxy: 'auto', allowedOrigins: [] };
|
||||
// https://game.example.com:8443 -> proxy -> Host: game.example.com (no port), Origin keeps :8443
|
||||
const stripped = { host: 'game.example.com', origin: 'https://game.example.com:8443' };
|
||||
assert.equal(netx.originAllowed(req(stripped), o), true, 'private proxy peer');
|
||||
assert.equal(netx.originAllowed(req(stripped, '::ffff:127.0.0.1'), o), true, 'loopback proxy peer');
|
||||
assert.equal(netx.originAllowed(req({ host: 'game.example.com', origin: 'http://GAME.example.com:8080' }), o), true, 'http on 8080');
|
||||
assert.equal(netx.originAllowed(req({ host: 'game.example.com', origin: 'https://game.example.com' }), o), true, 'default port still works');
|
||||
// ...and must stay closed everywhere else
|
||||
assert.equal(netx.originAllowed(req(stripped, '203.0.113.9'), o), false, 'public peer is not a proxy: Host must match exactly');
|
||||
assert.equal(netx.originAllowed(req(stripped), { trustProxy: false, allowedOrigins: [] }), false, 'TRUST_PROXY=0');
|
||||
assert.equal(netx.originAllowed(req(stripped, '203.0.113.9'), { trustProxy: true, allowedOrigins: [] }), true, 'TRUST_PROXY=1 believes any peer');
|
||||
assert.equal(netx.originAllowed(req({ host: 'game.example.com', origin: 'https://evil.example.com:8443' }), o), false, 'another host name');
|
||||
assert.equal(netx.originAllowed(req({ host: 'game.example.com', origin: 'https://game.example.com.evil.net:8443' }), o), false, 'name suffix trick');
|
||||
assert.equal(netx.originAllowed(req({ host: 'game.example.com:8080', origin: 'https://game.example.com:8443' }), o), false,
|
||||
'Host WITH a port (a direct connection, or a proxy that keeps it) must match exactly');
|
||||
assert.equal(netx.originAllowed(req({ host: '127.0.0.1:8080', origin: 'http://127.0.0.1:9999' }, '127.0.0.1'), o), false, 'direct loopback, other port');
|
||||
assert.equal(netx.originAllowed(req({ host: 'game.example.com' }), o), true, 'no Origin');
|
||||
assert.equal(netx.originAllowed(req({ host: '[2001:db8::7]', origin: 'https://[2001:db8::7]:8443' }), o), true, 'IPv6 literal');
|
||||
assert.equal(netx.originAllowed(req({ host: '[2001:db8::7]', origin: 'https://[2001:db8::8]:8443' }), o), false, 'other IPv6 literal');
|
||||
assert.equal(netx.hostParts('Game.Example.com:8443').port, '8443');
|
||||
assert.equal(netx.hostParts('https://game.example.com:443').port, '');
|
||||
assert.equal(netx.hostParts('a b'), null);
|
||||
});
|
||||
|
||||
test('Origin check over a real upgrade: Host without port + Origin with port is accepted from a trusted proxy peer only', async () => {
|
||||
await withServer({}, async (S) => { // the test peer is loopback = a trusted proxy under auto
|
||||
const ok = (host, origin) => probe(S.url, { headers: { Host: host }, origin });
|
||||
assert.equal((await ok('highport.test', 'https://highport.test:8332')).ok, true);
|
||||
assert.equal((await ok('highport.test', 'http://highport.test:8330')).ok, true);
|
||||
assert.equal((await ok('highport.test', 'https://evil.test:8332')).status, 403);
|
||||
assert.equal((await ok('highport.test:8330', 'https://highport.test:8332')).status, 403, 'Host has a port: exact match only');
|
||||
});
|
||||
await withServer({ trustProxy: false }, async (S) => {
|
||||
assert.equal((await probe(S.url, { headers: { Host: 'highport.test' }, origin: 'https://highport.test:8332' })).status, 403);
|
||||
});
|
||||
});
|
||||
|
||||
test('TRUSTED_PROXIES: parseTrustedProxies accepts IPs and CIDRs (v4 + v6) and rejects typos', () => {
|
||||
const t = netx.parseTrustedProxies(' 100.64.0.0/10, 2001:db8::6 ,2001:db8:1::/48,,192.0.2.1 ');
|
||||
assert.deepEqual(t.list, ['100.64.0.0/10', '2001:db8::6', '2001:db8:1::/48', '192.0.2.1']);
|
||||
for (const ip of ['100.64.1.1', '100.127.255.254', '::ffff:100.64.0.1', '2001:db8::6', '2001:DB8::6', '2001:db8:1:ffff::9', '192.0.2.1'])
|
||||
assert.equal(t.has(ip), true, ip);
|
||||
for (const ip of ['100.63.255.255', '100.128.0.1', '2001:db8::7', '2001:db8:2::1', '192.0.2.2', '8.8.8.8', 'junk', ''])
|
||||
assert.equal(t.has(ip), false, ip);
|
||||
assert.deepEqual(netx.parseTrustedProxies(['10.1.1.1', '2001:db8::/32']).list, ['10.1.1.1', '2001:db8::/32']);
|
||||
for (const v of [undefined, null, '', ' , ', []]) assert.equal(netx.parseTrustedProxies(v), null);
|
||||
for (const bad of ['nonsense', '100.64.0.0/33', '2001:db8::/129', '1.2.3.4/', '1.2.3.4/x', '1.2.3', '::ffff:10.0.0.0/104', '100.64.0.0/10, oops'])
|
||||
assert.throws(() => netx.parseTrustedProxies(bad), /invalid TRUSTED_PROXIES entry/, bad);
|
||||
});
|
||||
|
||||
test('TRUSTED_PROXIES: a proxy on a global IPv6 / CGNAT address is believed (isTrustedPeer, clientIp, Origin) once it is listed', async () => {
|
||||
const req = (peer, h) => ({ headers: h || {}, socket: { remoteAddress: peer } });
|
||||
const xff = { 'x-forwarded-for': '198.51.100.7' };
|
||||
const t = netx.parseTrustedProxies('100.64.0.0/10,2001:db8::6');
|
||||
// before: the built-in private list does not know these addresses, every player is "the proxy"
|
||||
assert.equal(netx.clientIp(req('2001:db8::6', xff), 'auto'), '2001:db8::6');
|
||||
assert.equal(netx.clientIp(req('100.64.1.1', xff), 'auto'), '100.64.1.1');
|
||||
assert.equal(netx.isTrustedPeer(req('2001:db8::6'), 'auto'), false);
|
||||
// after
|
||||
assert.equal(netx.clientIp(req('2001:db8::6', xff), 'auto', t), '198.51.100.7');
|
||||
assert.equal(netx.clientIp(req('::ffff:100.64.1.1', xff), 'auto', t), '198.51.100.7');
|
||||
assert.equal(netx.isTrustedPeer(req('2001:db8::6'), 'auto', t), true);
|
||||
assert.equal(netx.clientIp(req('2001:db8::7', xff), 'auto', t), '2001:db8::7', 'an unlisted neighbour is still not believed');
|
||||
assert.equal(netx.clientIp(req('203.0.113.5', xff), 'auto', t), '203.0.113.5');
|
||||
assert.equal(netx.clientIp(req('10.0.0.2', xff), 'auto', t), '198.51.100.7', 'the private ranges stay trusted: the list is an addition');
|
||||
assert.equal(netx.clientIp(req('2001:db8::6', xff), false, t), '2001:db8::6', 'TRUST_PROXY=0 wins over the list');
|
||||
assert.equal(netx.clientIp(req('2001:db8::6', xff), true), '198.51.100.7');
|
||||
const o = { trustProxy: 'auto', allowedOrigins: [], trustedProxies: t };
|
||||
const fwd = { host: 'x', origin: 'https://c.d', 'x-forwarded-host': 'c.d' };
|
||||
assert.equal(netx.originAllowed(req('2001:db8::6', fwd), { trustProxy: 'auto', allowedOrigins: [] }), false);
|
||||
assert.equal(netx.originAllowed(req('2001:db8::6', fwd), o), true, 'X-Forwarded-Host from a listed proxy');
|
||||
assert.equal(netx.originAllowed(req('2001:db8::6', { host: 'game.example.com', origin: 'https://game.example.com:8443' }), o), true);
|
||||
assert.equal(netx.originAllowed(req('2001:db8::7', { host: 'game.example.com', origin: 'https://game.example.com:8443' }), o), false);
|
||||
// the server option: bad list stops the start, a good one is kept
|
||||
await assert.rejects(createServer({ port: 0, host: '127.0.0.1', log: noop, trustedProxies: '100.64.0.0/40' }), /invalid TRUSTED_PROXIES entry/);
|
||||
await withServer({ trustedProxies: '100.64.0.0/10, 2001:db8::6' }, async (S) => {
|
||||
assert.deepEqual(S.srv.options.trustedProxies.list, ['100.64.0.0/10', '2001:db8::6']);
|
||||
assert.equal((await probe(S.url, { headers: { 'X-Forwarded-For': '198.51.100.7' } })).ok, true);
|
||||
});
|
||||
});
|
||||
|
||||
// public/sw.js run in a vm with a fake Cache Storage, to see what a navigation gets while nginx answers 502 for a stopped app
|
||||
function loadServiceWorker(net) {
|
||||
const vm = require('vm');
|
||||
const src = fs.readFileSync(path.join(__dirname, '..', 'public', 'sw.js'), 'utf8');
|
||||
const BASE = 'https://game.test/';
|
||||
const handlers = {}, store = new Map(), puts = [];
|
||||
store.set(BASE, R(200, 'cached game')); store.set(BASE + 'index.html', R(200, 'cached shell'));
|
||||
store.set(BASE + 'js/main.js', R(200, 'cached main.js'));
|
||||
const caches = {
|
||||
match: async (r) => store.get(typeof r === 'string' ? new URL(r, BASE + 'sw.js').href : r.url),
|
||||
open: async () => ({ put: async (r, res) => { puts.push(r.url + ' ' + res.status); store.set(r.url, res); }, addAll: async () => {} }),
|
||||
keys: async () => [], delete: async () => true,
|
||||
};
|
||||
const self = { location: new URL(BASE + 'sw.js'), skipWaiting() {}, clients: { claim() {} }, addEventListener: (t, f) => { handlers[t] = f; } };
|
||||
vm.runInNewContext(src, { self, caches, fetch: net, URL, Response, Promise, Set, console });
|
||||
return {
|
||||
BASE, puts,
|
||||
async get(url, mode) {
|
||||
let out; const request = { method: 'GET', url, mode: mode || 'no-cors' };
|
||||
handlers.fetch({ request, respondWith: (p) => { out = p; } });
|
||||
const res = await out;
|
||||
await new Promise((r) => setImmediate(r)); // the cache.put is fire-and-forget
|
||||
return res;
|
||||
},
|
||||
};
|
||||
}
|
||||
function R(status, body) { return { status, body, ok: status >= 200 && status < 300, type: 'basic', clone() { return R(status, body); } }; }
|
||||
|
||||
test('service worker: 502/503/504 from the proxy fall back to the cache instead of showing nginx\'s error page', async () => {
|
||||
for (const code of [502, 503, 504]) {
|
||||
const sw = loadServiceWorker(async () => R(code, 'nginx error page'));
|
||||
const B = sw.BASE;
|
||||
assert.equal((await sw.get(B, 'navigate')).body, 'cached game', code + ': cached page, not the proxy error page');
|
||||
assert.equal((await sw.get(B + '?room=ABCD', 'navigate')).body, 'cached shell', code + ': invite link -> cached app shell');
|
||||
assert.equal((await sw.get(B + 'js/main.js')).body, 'cached main.js', code + ': cached script');
|
||||
assert.equal((await sw.get(B + 'assets/music/battle.mp3')).status, code, code + ': never cached -> the real error, not index.html');
|
||||
assert.deepEqual(sw.puts, [], code + ': an error response is never stored');
|
||||
}
|
||||
const down = loadServiceWorker(async () => { throw new TypeError('Failed to fetch'); });
|
||||
assert.equal((await down.get(down.BASE, 'navigate')).body, 'cached game', 'network failure: cached page (unchanged behaviour)');
|
||||
assert.equal((await down.get(down.BASE + '?room=ABCD', 'navigate')).body, 'cached shell');
|
||||
assert.equal((await down.get(down.BASE + 'assets/music/battle.mp3')).type, 'error', 'a missing file is a network error, not index.html');
|
||||
});
|
||||
|
||||
test('service worker: only complete 200 responses are cached (not a 206 range response, not a 404)', async () => {
|
||||
const sw = loadServiceWorker(async (r) => R(r.url.endsWith('/range.mp3') ? 206 : r.url.endsWith('/missing.png') ? 404 : 200, 'fresh'));
|
||||
const B = sw.BASE;
|
||||
assert.equal((await sw.get(B + 'js/main.js')).body, 'fresh', 'healthy upstream: network first');
|
||||
assert.equal((await sw.get(B + 'assets/range.mp3')).status, 206, 'a range response is passed through');
|
||||
assert.equal((await sw.get(B + 'missing.png')).status, 404, 'a 404 is the upstream\'s answer');
|
||||
assert.deepEqual(sw.puts, [B + 'js/main.js 200'], 'only the complete 200 is cached (not 206, not 404)');
|
||||
});
|
||||
|
||||
// ================================================================ dual stack
|
||||
test('listenDual: IPv6 fallback logic (stub server)', async () => {
|
||||
const stub = (failWith) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue