Skip to content

Commit dab7c86

Browse files
fix: proxy direct APNs HTTP2 sessions
1 parent ca85fde commit dab7c86

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

src/infra/push-apns-http2.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,25 @@ describe("connectApnsHttp2Session", () => {
123123
expect(connectSpy).toHaveBeenCalledWith("https://api.push.apple.com");
124124
});
125125

126+
it("rejects APNs authorities with non-origin URL components", async () => {
127+
const { connectApnsHttp2Session, probeApnsHttp2ReachabilityViaProxy } =
128+
await import("./push-apns-http2.js");
129+
130+
await expect(
131+
connectApnsHttp2Session({
132+
authority: "https://token@api.push.apple.com",
133+
timeoutMs: 10_000,
134+
}),
135+
).rejects.toThrow("Unsupported APNs authority");
136+
await expect(
137+
probeApnsHttp2ReachabilityViaProxy({
138+
authority: "https://api.sandbox.push.apple.com/3/device/abc",
139+
proxyUrl: "http://proxy.example:8080",
140+
timeoutMs: 10_000,
141+
}),
142+
).rejects.toThrow("Unsupported APNs authority");
143+
});
144+
126145
it("uses an HTTP CONNECT tunnel when managed proxy is active", async () => {
127146
const registration = registerActiveManagedProxyUrl(new URL("http://proxy.example:8080"));
128147
const { connectApnsHttp2Session } = await import("./push-apns-http2.js");

src/infra/push-apns-http2.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ function assertApnsAuthority(authority: string): ApnsAuthority {
4141
} catch {
4242
throw new Error(`Unsupported APNs authority: ${authority}`);
4343
}
44+
if (
45+
parsed.username ||
46+
parsed.password ||
47+
parsed.pathname !== "/" ||
48+
parsed.search ||
49+
parsed.hash
50+
) {
51+
throw new Error(`Unsupported APNs authority: ${authority}`);
52+
}
4453
const port = parsed.port && parsed.port !== APNS_DEFAULT_PORT ? `:${parsed.port}` : "";
4554
const normalized = `${parsed.protocol}//${parsed.hostname}${port}`;
4655
if (!APNS_AUTHORITIES.has(normalized)) {

0 commit comments

Comments
 (0)