Download the PHP package attachmentav/virus-scan-sdk without Composer

On this page you can find all versions of the php package attachmentav/virus-scan-sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package virus-scan-sdk

attachmentav-sdk-php

Packagist Version PHP Version Tests

An SDK to integrate virus and malware scan capabilities into PHP applications. Scan files for viruses, trojans, and other kinds of malware with attachmentAV powered by Sophos.

Getting started

First, install the package attachmentav/virus-scan-sdk from Packagist with Composer.

The SDK needs a PSR-18 HTTP client. Laravel already includes Guzzle. Symfony applications can use symfony/http-client together with nyholm/psr7. If your project has no HTTP client yet, the php-http/discovery Composer plugin installs one for you, or you can install one yourself: composer require guzzlehttp/guzzle.

Second, get an API key by subscribing to the attachmentAV API (SaaS).

Third, send a scan request. Replace <API_KEY_PLACEHOLDER> with your API key.

The scan result looks like this:

What is attachmentAV?

attachmentAV offers antivirus for SaaS and cloud platforms. Scan your files and attachments stored in the cloud for viruses, worms, and trojans. attachmentAV detects malware in real-time. Supports Amazon S3, Atlassian, Cloudflare R2, Salesforce, WordPress, and more.

The attachmentAV Virus and Malware Scan API provides a REST API that allows you to integrate malware scans into your application. The solution comes in two variants:

attachmentAV raises the bar for information security. Our solution is ISO 27001 certified and GDPR compliant. We are establishing, implementing, maintaining, and continually improving an information security management system (ISMS). Sensitive data is encrypted in transit as well as at rest and deleted immediately after processing. More than 1,000 customers trust our malware protection technology.

Configure SDK

Configure SDK (SaaS)

An active subscription and API key are required. The region must match the region selected for the subscription. The default is Region::EU.

Region Constant API endpoint
Europe Region::EU https://eu.developer.attachmentav.com/v1
United States of America Region::US https://us.developer.attachmentav.com/v1
Canada Region::CANADA https://canada.developer.attachmentav.com/v1
India Region::INDIA https://india.developer.attachmentav.com/v1
Australia Region::AUSTRALIA https://australia.developer.attachmentav.com/v1

The SDK sends the API key in the x-api-key header.

Configure SDK (self-hosted on AWS)

When you followed the setup guide, you set the ApiKeys parameter of the CloudFormation stack. Replace <API_KEY_PLACEHOLDER> with one of those keys. Replace attachmentav.yourcompany.com with the domain name of your attachmentAV API installation.

The SDK sends the API key as a bearer token (Authorization: Bearer ...). If you pass only the domain (https://attachmentav.yourcompany.com), the SDK appends /api/v1.

The self-hosted variant supports the sync actions: scanSyncBinary(), scanSyncFile(), scanSyncDownload(), and scanSyncS3(). Async scans, callbacks, getUsage(), whoami(), and test() are only available for the SaaS variant.

Advanced configuration

If Guzzle or Symfony HttpClient is installed, the SDK creates the HTTP client with the configured timeout. If the API asks to wait longer than 30 seconds before retrying (Retry-After), the SDK throws a RateLimitException instead of blocking the request.

You can also pass your own PSR-18 client, e.g. to use a proxy. In that case, configure the timeout on your client:

You can also create the configuration from an array, for example from environment variables or framework configuration:

Empty values, such as environment variables that are set but blank, are treated as missing. So ATTACHMENTAV_REGION= falls back to eu.

Examples

Sync Scan: File

Upload a file to the attachmentAV Virus Scan API and get the scan result back.

SaaS: the maximum file size is 10 MB and the request timeout is 60 seconds.

The SDK always scans the whole content, from the start. A stream resource you pass stays open and is rewound afterwards, so you can keep using it, for example to store the file after a clean scan.

Find the full example: examples/sync-binary.php

Sync Scan: Download

Send a URL to the attachmentAV Virus Scan API. attachmentAV downloads the file and returns the scan result right away.

SaaS: the maximum file size is 200 MB and the request timeout is 60 seconds.

Find the full example: examples/sync-download.php

Sync Scan: S3

Send an S3 bucket name and object key to the attachmentAV Virus Scan API. attachmentAV downloads the object and returns the scan result right away.

SaaS: a bucket policy is required to grant attachmentAV access to the S3 objects. The maximum file size is 200 MB and the request timeout is 60 seconds.

Find the full example: examples/sync-s3.php

Async Scan: Download (SaaS)

Send a URL to the attachmentAV Virus Scan API. attachmentAV downloads and scans the file in the background. The maximum file size is 5 GB.

There are two ways to get the scan result: callback or polling.

Callback: attachmentAV sends the scan result to your callback URL with an HTTPS POST request. See Verify Callbacks.

Polling: pass a trace ID and poll getAsyncResult(). It returns null until the scan result is available. Scan results are stored for 24 hours. Each poll counts against your monthly quota.

Find the full example: examples/async-download-polling.php

Async Scan: S3 (SaaS)

Send an S3 bucket name and object key to the attachmentAV Virus Scan API. attachmentAV downloads and scans the object in the background. A bucket policy is required. The maximum file size is 5 GB.

Find the full example: examples/async-s3-callback.php

Callback failures (SaaS)

If attachmentAV cannot deliver a scan result to your callback URL after several retries, it records a callback failure. Callback failures are kept for 30 days.

Usage and account (SaaS)

Each of these requests counts against your monthly quota.

Find the full example: examples/usage.php

Verify Callbacks

attachmentAV signs every callback. Verify the signature before you trust the scan result. You need your tenant ID, which you can get once with $api->whoami()->getTenantId(). The SDK includes the public keys of all regions.

Use $verifier->verify(...) to get a bool instead of an exception. Use $verifier->verifyRequest($psr7Request, $callbackUrl) with PSR-7 requests (Slim, Mezzio, ...).

Find the full example: examples/verify-callback.php

Error handling

Every exception thrown by the SDK implements AttachmentAV\Exception\ExceptionInterface.

Exception When
AuthenticationException 401/403: invalid API key, or the API endpoint does not match the region of the subscription.
RateLimitException 429: throttled (isThrottled(), retried automatically) or monthly quota exceeded (isQuotaExceeded()).
NotFoundException 404
ApiException Any other non-2xx response; parent class of the three exceptions above. Use getStatusCode(), getErrorMessage(), getResponseBody().
TransportException Network error, e.g. DNS failure or timeout.
UnexpectedResponseException The response cannot be parsed.
InvalidArgumentException Invalid input, detected before a request is sent.

Laravel

Try it: examples/laravel is a complete upload form you can run with docker compose up.

Laravel registers the service provider and the AttachmentAV facade automatically. Add the configuration to your .env file:

Optionally, publish the config file to config/attachmentav.php:

Validate uploads with the VirusFree rule (Laravel 10+). It fails if the file is infected, cannot be scanned, or if the API cannot be reached:

Options:

Use the facade, or inject AttachmentAV\AttachmentAVApi:

Verify callbacks in a route. Exclude the route from CSRF protection:

Symfony

Try it: examples/symfony is a complete upload form you can run with docker compose up.

Register the client as a service in config/services.yaml. If symfony/http-client and nyholm/psr7 are installed, Symfony's HTTP client is used.

Then inject AttachmentAV\AttachmentAVApi with autowiring:

Other frameworks and plain PHP

AttachmentAVApi is a plain PHP class with no framework dependencies. Create it once and register it in your framework's container, for example a CodeIgniter service, a Yii component, a Laminas factory, or a PHP-DI definition. To use a specific HTTP client, pass any PSR-18 client and PSR-17 factories:

Development

See DEV.md.

License

MIT


All versions of virus-scan-sdk with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
ext-json Version *
php-http/discovery Version ^1.15
psr/http-client Version ^1.0
psr/http-client-implementation Version ^1.0
psr/http-factory Version ^1.0
psr/http-factory-implementation Version ^1.0
psr/http-message Version ^1.1 || ^2.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package attachmentav/virus-scan-sdk contains the following files

Loading the files please wait ...