Download the PHP package laikait/laika-shield without Composer

On this page you can find all versions of the php package laikait/laika-shield. 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 laika-shield

๐Ÿ›ก๏ธ Laika Shield

Laika Shield is the firewall layer for the Laika PHP Framework โ€” IP and country filtering, rate limiting, SQL injection and XSS detection, and request filtering.

Tests PHP


โœจ Features

Feature Description
๐ŸŒ Country Blocking Block or allowlist entire countries via MaxMind GeoLite2
๐Ÿšซ IP Blocking Block individual IPs or CIDR ranges
โœ… IP Allowlisting Restrict access to specific IPs/ranges only
๐Ÿ”ข IP Version Filtering Allow only IPv4 or only IPv6 connections
โฑ๏ธ Rate Limiting Limit requests per IP per time window
๐Ÿ’‰ SQL Injection Detection Block common SQLi attack payloads
๐Ÿ› XSS Detection Block cross-site scripting attempts
๐Ÿ” Request Filtering Filter by HTTP method, URI, User-Agent, headers, and body size

๐Ÿ“ฆ Installation

Laika Shield ships as part of the framework โ€” laikait/laika-framework already requires it, so there is usually nothing to install.

To pull it into a project directly:

Requires PHP 8.1+ and geoip2/geoip2. Country blocking additionally needs a MaxMind GeoLite2-Country database, which is not bundled โ€” see Country Blocking.


๐Ÿš€ Quick Start

1. Register the pipeline

Add ShieldPipeline to your route pipeline stack โ€” first, ahead of everything else. It is only a firewall if nothing has run yet.

There is no config file to publish โ€” the defaults are already complete, so the line above gives you a working firewall.

2. Adjust the configuration

A blocked request emits its JSON body and terminates. It never reaches the rest of the chain, so no downstream pipeline โ€” auth, logging, database writes โ€” runs for a request the firewall rejected.

Upgrading from 1.2.x: Laika\Shield\Http\ShieldMiddleware has been removed. It fell through its own catch block and let blocked requests reach the application. Replace it with ShieldPipeline as above.

3. Or use the static API

4. Or use the fluent builder


โš™๏ธ Configuration Reference

Every option lives on a typed object with a fluent accessor: call it with no argument to read, with one to write. Defaults are declared on the properties themselves.

Accessors chain, and reading is the same method without an argument:

The six section accessors โ€” ip(), rateLimit(), sqlInjection(), xss(), requestFilter(), country() โ€” are static because there is only one configuration. The three top-level scalars (trustProxy, trustedProxies, ipVersion) stay on the instance: they are declared as instance methods, and PHP will not let a method be both static and non-static under one name.

Nullable options can be set back to null โ€” storageDir, contentLengthMax, contentLengthMin and ipVersion all accept it as a real value.

Arrays still work

ShieldPipeline and Shield::fromConfig() accept a plain array, which is applied over the defaults rather than replacing them. Supplying one option in a section leaves the rest of that section alone:

Shield::boot() takes no arguments at all โ€” it always reads the shared ShieldConfig instance, so configure that first with ShieldConfig::add() or ShieldConfig::instance().

Note the difference in where the defaults come from: fromConfig() layers an array over a fresh set of defaults and never touches global state, which keeps it predictable and testable. ShieldPipeline layers an array over the shared instance, so pipeline options combine with whatever the application configured.


ShieldConfig is a singleton

ShieldConfig has no public constructor. There is exactly one shared configuration, and that is what Shield::boot() and ShieldPipeline read:

The static section accessors are shortcuts onto that same shared instance โ€” ShieldConfig::rateLimit() is exactly ShieldConfig::instance()->rateLimit.

If you need a throwaway configuration โ€” for a test, or to run one request under different rules โ€” ShieldConfig::make() gives you a detached object. boot() will not see it, so run it explicitly:

โš ๏ธ The static accessors always resolve the shared instance. If you are holding a detached config, reach its sections through the object ($config->rateLimit) โ€” ShieldConfig::rateLimit() would configure the shared one instead.

Call Returns Seen by Shield::boot()
ShieldConfig::instance() the shared configuration โœ… yes
ShieldConfig::make() a new detached configuration โŒ no โ€” use fromConfig()
ShieldConfig::fromArray([...]) a detached configuration from an array โŒ no โ€” use fromConfig()
ShieldConfig::rateLimit() etc. a section of the shared configuration โœ… yes
new ShieldConfig() โ€” Error: constructor is not public

๐Ÿ”ง ShieldConfig Class

ShieldConfig also exposes a static, array-keyed API over one shared instance. It is kept for compatibility โ€” the ShieldConfig relay is bound to it โ€” and remains handy for one-off tweaks during bootstrap. New code should prefer the object API above.

ShieldConfig API

Method Description
ShieldConfig::add(string $key, mixed $value) Set or merge a top-level config key
ShieldConfig::add(string $key, string $subKey, mixed $value) Set or merge a specific sub-key
ShieldConfig::get() Return the full config array
ShieldConfig::get(string $key) Return the value of a single key
ShieldConfig::has(string $key) Check if a key exists
ShieldConfig::keys() Return all top-level config keys
ShieldConfig::reset() Reset the shared instance back to defaults
ShieldConfig::instance() The shared ShieldConfig object behind the static API

๐Ÿ—๏ธ Architecture


๐Ÿ”Œ Writing Custom Rules

Implement RuleInterface to create your own firewall rules:


๐Ÿงช Running Tests


๐ŸŒ IP Version Detection

Shield exposes IpHelper for standalone IP utilities:


๐Ÿ” Trusting Proxies

Forwarded headers are attacker-controlled. Anyone can send X-Forwarded-For: 8.8.8.8, so believing the wrong one turns every IP rule into a suggestion.

Shield only consults them when trust.proxy is on, and:

If your app is not behind a proxy, leave trust.proxy => false.


๐ŸŒ Country Blocking

The GeoLite2 database is not distributed with this package โ€” it is MaxMind-licensed and roughly 9.5 MB. Fetch it with your own licence key:

Then point the config at it:

A missing or unreadable database does not block anyone and does not raise an error โ€” requests simply pass the country check.


๐ŸŽฏ Tuning The Detectors

The detectors match SQL and HTML syntax, not vocabulary. Words like select, sleep, drop table or #42 in ordinary prose are not treated as attacks.

strict mode adds keyword-only SQL patterns. It will flag normal sentences, so enable it only for fields that never carry free text:

For rich-text or markup-bearing fields, use skip.keys rather than weakening the patterns for everything.


๐Ÿ“„ License

MIT ยฉ Laika IT

GeoLite2 data, if you use it, is ยฉ MaxMind and governed by the GeoLite2 End User Licence Agreement.


All versions of laika-shield with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
ext-json Version *
geoip2/geoip2 Version ^3
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 laikait/laika-shield contains the following files

Loading the files please wait ...