Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added check for resources greater than 100mb #1858

Merged
merged 2 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/core/src/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,13 @@ async function saveResponseResource(network, request, session) {
url,
responseStatus: response?.status
};
// Checing for content length more than 100MB, to prevent websocket error which is governed by
// maxPayload option of websocket defaulted to 100MB.
// If content-length is more than our allowed 25MB, no need to process that resouce we can return log.
let contentLength = parseInt(response.headers['Content-Length']);
if (contentLength > MAX_RESOURCE_SIZE) {
return log.debug('- Skipping resource larger than 25MB', meta);
}
let resource = network.intercept.getResource(url);

if (!resource || (!resource.root && !resource.provided && disableCache)) {
Expand All @@ -484,8 +491,6 @@ async function saveResponseResource(network, request, session) {
return log.debug('- Skipping remote resource', meta);
} else if (!body.length) {
return log.debug('- Skipping empty response', meta);
} else if (body.length > MAX_RESOURCE_SIZE) {
return log.debug('- Skipping resource larger than 25MB', meta);
} else if (!ALLOWED_STATUSES.includes(response.status)) {
return log.debug(`- Skipping disallowed status [${response.status}]`, meta);
} else if (!enableJavaScript && !ALLOWED_RESOURCES.includes(request.type)) {
Expand Down
35 changes: 35 additions & 0 deletions packages/core/test/discovery.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,41 @@ describe('Discovery', () => {
);
});

it('skips file greater than 100MB', async () => {
server.reply('/large.css', () => [200, 'text/css', 'A'.repeat(100_000_000)]);
percy.loglevel('debug');

await percy.snapshot({
name: 'test snapshot',
url: 'http://localhost:8000',
domSnapshot: testDOM.replace('style.css', 'large.css')
});

await percy.idle();

expect(captured[0]).toEqual([
jasmine.objectContaining({
attributes: jasmine.objectContaining({
'resource-url': jasmine.stringMatching(/^\/percy\.\d+\.log$/)
})
}),
jasmine.objectContaining({
attributes: jasmine.objectContaining({
'resource-url': 'http://localhost:8000/'
})
}),
jasmine.objectContaining({
attributes: jasmine.objectContaining({
'resource-url': 'http://localhost:8000/img.gif'
})
})
]);

expect(logger.stderr).toContain(
'[percy:core:discovery] - Skipping resource larger than 25MB'
);
});

it('does not capture duplicate root resources', async () => {
let reDOM = dedent`
<html><head></head><body>
Expand Down