You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+26-12Lines changed: 26 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,7 @@ It helps you enforce consistent file upload rules by checking:
7
7
- File size limits
8
8
- File signatures (magic numbers) to detect spoofed types
9
9
- Specification conformance for Office Open XML / Open Document Formats (`.docx`, `.xlsx`, `.pptx`, `.odt`)
10
+
- Malware scan result using a varity of scanners (_requires the addition of a specific ByteGuard.FileValidator scanner package_)
10
11
11
12
> ⚠️ **Important:** This library should be part of a **defense-in-depth** strategy.
12
13
It does not replace antivirus scanning, sandboxing, or other security controls.
@@ -17,6 +18,7 @@ It does not replace antivirus scanning, sandboxing, or other security controls.
17
18
- ✅ Validate files by **size**
18
19
- ✅ Validate files by **signature (_magic-numbers_)**
19
20
- ✅ Validate files by **specification conformance** for archive-based formats (_Open XML and Open Document Formats_)
21
+
- ✅ **Ensure no malware** through a variety of antimalware scanners
20
22
- ✅ Validate using file path, `Stream`, or `byte[]`
21
23
- ✅ Configure which file types to support
22
24
- ✅ Configure whether to **throw exceptions** or simply return a boolean
@@ -25,23 +27,26 @@ It does not replace antivirus scanning, sandboxing, or other security controls.
25
27
## Getting Started
26
28
27
29
### Installation
28
-
This package is published and installed via NuGet.
30
+
This package is published and installed via [NuGet](https://www.nuget.org/packages/ByteGuard.FileValidator).
29
31
30
32
Reference the package in your project:
31
33
```bash
32
34
dotnet add package ByteGuard.FileValidator
33
35
```
34
36
37
+
### Antimalware scanners
38
+
In order to use the antimalware scanning capabilities, ensure you have a ByteGuard.FileValidator antimalware package referenced as well. Youo can find the relevant scanner package on NuGet under the namespace `ByteGuard.FileValidator.Scanners`.
@@ -132,9 +141,10 @@ The following file extensions are supported by the `FileValidator`:
132
141
133
142
`IsValidFile` always validates:
134
143
135
-
- File extension (against `SupportedFileTypes`)
136
-
- File size (against `FileSizeLimit`)
137
-
- File signature (magic number)
144
+
- File extension (_against `SupportedFileTypes`_)
145
+
- File size (_against `FileSizeLimit`_)
146
+
- File signature (_magic number_)
147
+
- Malware scan result (_if an antimalware scanner has been configured_)
138
148
139
149
For some formats, additional checks are performed:
140
150
@@ -143,11 +153,13 @@ For some formats, additional checks are performed:
143
153
- File size
144
154
- Signature
145
155
- Specification conformance
156
+
- Malware scan result
146
157
147
158
-**Other binary formats** (e.g. images, audio, video such as `.jpg`, `.png`, `.mp3`, `.mp4`):
148
159
- Extension
149
160
- File size
150
161
- Signature
162
+
- Malware scan result
151
163
152
164
## Configuration Options
153
165
@@ -158,6 +170,7 @@ The `FileValidatorConfiguration` supports:
158
170
|`SupportedFileTypes`| Yes | N/A | A list of allowed file extensions (e.g., `.pdf`, `.jpg`).<br>Use the predefined constants in `FileExtensions` for supported types. |
159
171
|`FileSizeLimit`| Yes | N/A | Maximum permitted size of files.<br>Use the static `ByteSize` class provided with this package, to simplify your limit. |
160
172
|`ThrowExceptionOnInvalidFile`| No |`true`| Whether to throw an exception on invalid files or return `false`. |
173
+
|`AntimalwareScanner`| No | N/A | An antimalware scanner used to scan the given file for potential malware. |
161
174
162
175
### Exceptions
163
176
@@ -171,6 +184,7 @@ When `ThrowExceptionOnInvalidFile` is set to `true`, validation functions will t
171
184
|`InvalidSignatureException`| Thrown when the file's signature does not match the expected signature for its type. |
172
185
|`InvalidOpenXmlFormatException`| Thrown when the internal structure of an Open XML file is invalid (`.docx`, `.xlsx`, `.pptx`, etc.). |
173
186
|`InvalidOpenDocumentFormatException`| Thrown when the specification conformance of an Open Document Format file is invalid (`.odt`, etc.). |
187
+
|`MalwareDetectedException`| Thrown when the configured antimalware scanner detected malware in the file from a scan result. |
<Description>ByteGuard File Validator is a security-focused .NET library for validating user-supplied files, providing a configurable API to help you enforce safe and consistent file handling across your applications.</Description>
0 commit comments