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

#3825 - Virus Scanning - Empty File Check #3862

Merged
merged 3 commits into from
Oct 31, 2024

Conversation

andrewsignori-aot
Copy link
Collaborator

@andrewsignori-aot andrewsignori-aot commented Oct 31, 2024

When starting a socket to send a file content to clamav using the passthrough and no content is sent, the connection stays open for an indefinite amount of time (over 5 minutes).
Changed queue-consumers to throw an error and remove the job, same behavior when the file is not found.

We can have a separate ticket to apply validation for the file upload to avoid accepting empty files, but I considered it outside this hotfix issue.

ClamAV debug log when a empty file is send for scanning.

2024-10-31 08:32:55 node-clam: Initially testing socket/tcp connection to clamscan server.
2024-10-31 08:32:55 node-clam: Attempting to establish socket/TCP connection for "_ping"
2024-10-31 08:32:55 node-clam: using remote server: 172.18.0.6:3310
2024-10-31 08:32:55 node-clam: Established connection to clamscan server!
2024-10-31 08:32:55 node-clam: PONG!
2024-10-31 08:32:55 node-clam: Established connection to clamscan server!
2024-10-31 08:32:55 node-clam: Done with the full pipeline.
2024-10-31 08:32:55 node-clam: Socket/Host connection closed.
2024-10-31 08:33:00 node-clam: ClamAV has been scanning for 5 seconds...
...
2024-10-31 08:35:25 node-clam: ClamAV has been scanning for 150 seconds...
...
2024-10-31 08:45:30 node-clam: ClamAV has been scanning for 755 seconds...
...

@andrewsignori-aot andrewsignori-aot self-assigned this Oct 31, 2024
@andrewsignori-aot andrewsignori-aot changed the title #3825 - Added a check for the EMPTY_FILE #3825 - Virus Scanning - Empty File Check Oct 31, 2024
@andrewsignori-aot andrewsignori-aot marked this pull request as ready for review October 31, 2024 01:08
@andrewsignori-aot andrewsignori-aot marked this pull request as draft October 31, 2024 15:29
@andrewsignori-aot andrewsignori-aot marked this pull request as ready for review October 31, 2024 15:37
@guru-aot guru-aot self-requested a review October 31, 2024 16:00
studentFile.uniqueFileName,
);
if (contentLength === 0) {
Copy link
Collaborator

@guru-aot guru-aot Oct 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 , the contentLength was already available in the objectStorageService. Good

Copy link
Collaborator

@guru-aot guru-aot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, nice work @andrewsignori-aot

@@ -36,7 +39,7 @@ export class VirusScanProcessor {
} catch (error: unknown) {
if (error instanceof CustomNamedError) {
const errorMessage = error.message;
if (error.name === FILE_NOT_FOUND) {
if ([FILE_NOT_FOUND, EMPTY_FILE].includes(error.name)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very minor. please update the comment underneath.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, updated.

Comment on lines +59 to +63
// Empty files are not suitable for virus scanning using passthrough.
throw new CustomNamedError(
`File ${uniqueFileName} has no content to be scanned.`,
EMPTY_FILE,
);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

*/
export function createFakeGetObjectResponse(fileContent: string): jest.Mock {
return jest.fn(() => {
const buffer = Buffer.from(fileContent);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Collaborator

@dheepak-aot dheepak-aot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking care of this scenario. One very minor comment.

Copy link

Copy link

Backend Unit Tests Coverage Report

Totals Coverage
Statements: 21.9% ( 3495 / 15961 )
Methods: 9.89% ( 197 / 1991 )
Lines: 25.59% ( 3081 / 12040 )
Branches: 11.24% ( 217 / 1930 )

Copy link

E2E Workflow Workers Coverage Report

Totals Coverage
Statements: 58.64% ( 509 / 868 )
Methods: 52.88% ( 55 / 104 )
Lines: 62.27% ( 411 / 660 )
Branches: 41.35% ( 43 / 104 )

Copy link

E2E Queue Consumers Coverage Report

Totals Coverage
Statements: 86.09% ( 1058 / 1229 )
Methods: 87.3% ( 110 / 126 )
Lines: 87.08% ( 903 / 1037 )
Branches: 68.18% ( 45 / 66 )

Copy link

E2E SIMS API Coverage Report

Totals Coverage
Statements: 65.62% ( 5524 / 8418 )
Methods: 63.14% ( 680 / 1077 )
Lines: 69.75% ( 4367 / 6261 )
Branches: 44.17% ( 477 / 1080 )

@andrewsignori-aot andrewsignori-aot merged commit ebd646a into hotfix/v1.14.1 Oct 31, 2024
20 checks passed
@andrewsignori-aot andrewsignori-aot deleted the fix/#3825-clamav-empty-files-issue branch October 31, 2024 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Queue Consumers Security-related Issues related to security
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants