Download the PHP package pivotphp/security without Composer

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

PivotPHP Security

PHP Version PSR-15

Security middlewares for PivotPHP and any PSR-15 pipeline.

The only required dependencies are the PSR interfaces. Each adapter needs its library, installed on demand:

Middleware Library Install
Cors\CorsMiddleware — —
Proxy\TrustedProxyMiddleware — —
Headers\SecurityHeadersMiddleware bepsvpt/secure-headers composer require bepsvpt/secure-headers
Csrf\CsrfMiddleware yiisoft/csrf composer require yiisoft/csrf
Jwt\JwtAuthMiddleware, Jwt\JwtIssuer firebase/php-jwt composer require firebase/php-jwt
RateLimit\RateLimitMiddleware symfony/rate-limiter composer require symfony/rate-limiter

Installation

Middlewares that build responses take a PSR-17 ResponseFactoryInterface (e.g. PivotPHP\Http\Factory\Psr17Factory or Nyholm\Psr7\Factory\Psr17Factory).

Recommended order

CORS

Option Default Notes
allowedOrigins [] Exact scheme://host[:port], lower case, no path. ['*'] allows any origin.
allowedMethods GET, POST, PUT, PATCH, DELETE
allowedHeaders Content-Type, Authorization Request headers accepted in preflight.
exposedHeaders [] Response headers readable by the browser.
allowCredentials false
maxAge 600 Preflight cache in seconds; null omits the header.

Behaviour:

⚠️ Security: * with allowCredentials: true is rejected at configuration. The null origin (sandboxed iframes, file://) cannot be allowed. CORS does not protect the server — it only tells browsers what other origins may read; authenticate and authorize every request.

Trusted proxies

Option Default Notes
trustedProxies [] IPv4/IPv6 addresses or CIDR ranges.
header X-Forwarded-For Comma-separated IP chain.
attribute client_ip Attribute receiving the resolved IP.

The forwarding header is honoured only when REMOTE_ADDR is a trusted proxy. The chain is read right to left, skipping trusted proxies; the first untrusted address is the client. A malformed entry stops the walk. The attribute is not set when REMOTE_ADDR is missing or invalid.

⚠️ Security: never trust X-Forwarded-For from the internet. List only the proxies you run (load balancer, reverse proxy).

Security headers

Default headers (JSON API, OWASP REST guidance):

Option Default Notes
hsts, hstsMaxAge, hstsIncludeSubDomains, hstsPreload true, 31536000, true, false Preload requires subdomains and max-age ≥ 1 year.
frameOptions deny deny or sameorigin.
referrerPolicy strict-origin-when-cross-origin Any standard value.
contentSecurityPolicy default-src 'none'; frame-ancestors 'none' bepsvpt/secure-headers CSP array; null disables.
overrides [] Raw bepsvpt/secure-headers config (Permissions-Policy, COOP/COEP/CORP, reporting...).

Headers already set by the application are kept. The deprecated X-XSS-Protection is not sent. CSP nonces are not supported (the library keeps them in static state shared across requests).

⚠️ Security: an HTML application needs a CSP that matches its assets; the default is meant for APIs. Enable HSTS only on HTTPS-only hosts.

CSRF

Needed when the API authenticates with cookies (session or JWT in a cookie). Pure bearer-token APIs are not exposed to CSRF.

Token strategies come from yiisoft/csrf: SynchronizerCsrfToken (random token in a storage, e.g. the session) or HmacCsrfToken (stateless, bound to an identity such as the session id). Wrap either in MaskedCsrfToken when the token is rendered in HTML (BREACH mitigation).

Option (CsrfConfig) Default Notes
parameterName _csrf Form field.
headerName X-CSRF-Token Header (SPA/AJAX).
safeMethods GET, HEAD, OPTIONS POST/PUT/PATCH/DELETE cannot be declared safe.
attribute csrf_token Attribute holding the token object.
failureStatus 403 Any 4xx.

Every other method needs a valid token in the body field or header; otherwise the response is the failure status and the handler is not called.

⚠️ Security: keep GET free of side effects — safe methods are never checked. Combine with SameSite cookies.

JWT authentication

Option Default Notes
key — Secret (HS) or public key / PEM (RS, PS256, ES*, EdDSA).
algorithm HS256 Exactly one algorithm is accepted.
publicPaths [] fnmatch patterns that skip authentication.
cookieName null Cookie read when Authorization is absent.
issuer null Required iss.
audience [] Accepted aud values (any match).
leeway 0 Clock skew in seconds.
attribute user Attribute receiving the claims.

Signature, exp, nbf and iat are verified by firebase/php-jwt (non-numeric time claims are rejected); iss/aud are verified here. Failures return 401 with WWW-Authenticate: Bearer.

⚠️ Security: empty secrets, secrets shorter than the hash output (32/48/64 bytes) and unknown algorithms are rejected at configuration. Load keys from the environment or a secret store, never from source code.

Issuing tokens

JwtIssuer shares the JwtConfig used by the middleware, so issued tokens always match what is verified (algorithm, iss, aud):

iat, nbf and exp come from the clock and iss/aud from the configuration; passing them in the claims throws InvalidConfigurationException. Generate HMAC secrets with bin2hex(random_bytes(32)). Refresh tokens are an application concern (issue a second token with a longer ttl and a typ claim, and check it in your refresh endpoint).

Rate limiting

Option (RateLimitConfig) Default Notes
keyPrefix '' One prefix per limit/route group.
clientIpAttribute client_ip Set by TrustedProxyMiddleware; falls back to REMOTE_ADDR.
exposeHeaders true X-RateLimit-Limit/X-RateLimit-Remaining on accepted responses.

A fourth constructor argument accepts a custom key resolver (fn (ServerRequestInterface $r): ?string, e.g. an API key). Over the limit: 429 with Retry-After, X-RateLimit-Limit and X-RateLimit-Remaining: 0; the handler is not called. Use one middleware instance per limit (e.g. a stricter one on /login).

⚠️ Security: with InMemoryStorage or without a LockFactory, limits are per process and concurrent requests can exceed them. Use a shared storage and a lock in production.

Testing

License

MIT — see LICENSE.


All versions of security with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
psr/http-factory Version ^1.0
psr/http-message Version ^1.1|^2.0
psr/http-server-handler Version ^1.0
psr/http-server-middleware Version ^1.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 pivotphp/security contains the following files

Loading the files please wait ...