Skip to content

Commit 129b06b

Browse files
authored
fix: [SDK-4150] prevent prototype pollution in JSONP calls (#1442)
1 parent eac9542 commit 129b06b

5 files changed

Lines changed: 32 additions & 48 deletions

File tree

.cursor/rules/bun.md

Lines changed: 0 additions & 14 deletions
This file was deleted.

.cursor/rules/pr-conventions.md

Lines changed: 0 additions & 32 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
},
7878
{
7979
"path": "./build/releases/OneSignalSDK.page.es6.js",
80-
"limit": "41.94 kB",
80+
"limit": "41.96 kB",
8181
"gzip": true
8282
},
8383
{

src/shared/api/page.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const { mockJsonp } = vi.hoisted(() => ({
2+
mockJsonp: vi.fn(),
3+
}));
4+
5+
vi.mock('jsonp', () => ({ default: mockJsonp }));
6+
7+
describe('jsonpLib', () => {
8+
test('passes explicit options to prevent prototype pollution', async () => {
9+
vi.resetModules();
10+
const { jsonpLib } = await import('./page');
11+
12+
const fn = vi.fn();
13+
jsonpLib('https://example.com', fn);
14+
15+
expect(mockJsonp).toHaveBeenCalledWith(
16+
'https://example.com',
17+
expect.objectContaining({
18+
prefix: '__jp',
19+
param: 'callback',
20+
timeout: 60000,
21+
}),
22+
fn,
23+
);
24+
});
25+
});

src/shared/api/page.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ export function jsonpLib(
88
url: string,
99
fn: (err: Error | null, data: ServerAppConfig) => void,
1010
) {
11-
JSONP(url, undefined, fn);
11+
// Explicit opts prevent prototype pollution
12+
JSONP(
13+
url,
14+
{ prefix: '__jp', name: undefined, param: 'callback', timeout: 60000 },
15+
fn,
16+
);
1217
}
1318

1419
export async function downloadServerAppConfig(

0 commit comments

Comments
 (0)