qiick/laravel-http-basics
Larablocks Analysis
qiick/laravel-http-basics works with Laravel 12 and 13 (latest release v1.0.0-beta.1, Nov 27, 2026).
Recommendation checks
Use with careUse with care: meets 2 of 5 checks.
- Works with Laravel 13, the current version
- Pre-release in the last 12 months (Nov 27, 2026); no stable release yet
- First released under 90 days ago
- 1,153 downloads a month (needs 10,000)
- 0 GitHub stars (needs 100)
State
Too new to judge- Last release (pre-release): Nov 27, 2026.
- 1 release in the last 12 months, a pre-release.
- First released: Nov 27, 2026.
- Monthly downloads: 1,153.
- 1 open issue on GitHub.
Data from Packagist and GitHub, checked by Larablocks on Nov 29, 2026.
| Install | |
|---|---|
composer require qiick/laravel-http-basics:v1.0.0-beta.1 |
|
| Latest Version: | v1.0.0-beta.1 |
| PHP: | ^8.3 |
| Laravel: | 12 · 13 |
| License: | MIT |
| Last Updated: | Nov 28, 2026 |
| Links: | GitHub · Packagist |
qiick/laravel-http-basics
PHPStan at max and the existing CI checks cover PHP. CodeQL covers GitHub Actions and JavaScript/TypeScript.
The betas are for product integration and testing.
Shared HTTP runtime for qiick Laravel products: trusted X-Request-Id,
Accept-Language / Content-Language negotiation, configurable security headers,
and Idempotency-Key (middleware + store). Thin helpers for fleet error
augmentation and API route JSON classification — without owning product error
enums.
Part of the qiick fleet.
Status
The API and database schema remain provisional until 1.0.0. Follow the
installation and upgrade instructions for each beta in UPGRADING.md.
Requirements
- PHP
^8.4withext-fileinfo(upload MIME sniffing) - Illuminate cache / contracts / http / support
^12.0 \|\| ^13.0(neverlaravel/framework)
Install after the beta tag appears on Packagist
composer require qiick/laravel-http-basics:1.0.0-beta.2
php artisan vendor:publish --tag=http-basics-config
The optional idempotency migration loads with migrate only when
HTTP_BASICS_IDEMPOTENCY_STORE=database; HTTP_BASICS_MIGRATIONS_LOAD=true or
false overrides that. To own it in the product, run
php artisan vendor:publish --tag=http-basics-migrations and set
HTTP_BASICS_MIGRATIONS_LOAD=false; leaving both on runs the table twice.
Register request-id, locale and security middleware globally. Idempotency is
per-route after throttle / auth / scope / cost. Products wire
ExceptionErrorCodeAugmenter through their own bootstrap (no Foundation types in
this package).
Run php artisan http-basics:check during deployment and from the product's
upgrade command after migrations. It reports invalid settings and unreachable
idempotency stores and exits with status 1 when a check fails.
Fleet error shape (landed)
use Qiick\HttpBasics\Errors\ExceptionErrorCodeAugmenter;
use Qiick\HttpBasics\Errors\ApiRouteJson;
// shouldRenderJsonWhen — API routes only
$exceptions->shouldRenderJsonWhen(ApiRouteJson::whenCallback(['api/*', 'mcp', 'mcp/*']));
// respond() — add top-level `error` on API route JSON ≥400, never overwrite.
$exceptions->respond(fn ($response, $exception, $request) => app(ExceptionErrorCodeAugmenter::class)
->respond($response, $exception, $request));
With http-basics.errors.format=problem_details (chosen once per product), the
same binding renders every API route error response as RFC 9457
application/problem+json, an HTML error page included: type (about:blank,
or problem_type_base_uri plus the code), title, status, detail (the fleet
message), and instance when a ProblemInstanceResolverContract is bound. Every other
fleet member stays as an extension member: error (a product's own code is
kept), errors, documentation_url. Status and headers (Retry-After,
Allow) are kept. The golden shapes are in tests/Feature/golden/problem-details/.
Idempotency refusals already use ErrorRendererContract with translated message and a
stable error code from the shared ErrorCodeEnum (see docs/error-codes.md).
The augmenter covers framework and product exceptions the same way.
Request id (landed)
use Qiick\HttpBasics\RequestId\AssignRequestIdMiddleware;
use Qiick\HttpBasics\RequestId\RequestIdPropagator;
// bootstrap/app.php — OUTERMOST global middleware (prepend), so 401/404/405/419/429/503,
// maintenance and CORS preflight responses carry X-Request-Id.
$middleware->prepend(AssignRequestIdMiddleware::class);
// Outbound (only when http-basics.request_id.outbound.allowed_hosts is set)
app(RequestIdPropagator::class)->applyTo($pending, $url);
| Config / env | Default | Meaning |
|---|---|---|
HTTP_BASICS_REQUEST_ID_ACCEPT_FROM |
trusted_proxy |
Keep inbound id only from a trusted proxy hop (any / never also valid). |
HTTP_BASICS_TRUST_WILDCARD_PROXIES |
false |
When TrustProxies is * / ** (Cloud/Forge/Vapor), still reject client ids unless true. |
HTTP_BASICS_OUTBOUND_HOSTS |
empty | Comma-separated host or host:port; empty = never propagate; * = all hosts. |
http-basics.request_id.accept_pattern |
RequestId::PATTERN |
Boot checks compilation and absolute anchors \A and \z. Keep the alphanumeric requirement in custom patterns. |
http-basics.request_id.hidden_context_keys |
['http_basics.request_id'] |
Hidden Context aliases for product code that reads the bound ID. |
The id is stored in visible Context as request_id (Laravel logs it and queued jobs inherit it). Provenance (generated / trusted_proxy / client) stays in hidden Context.
Trust is computed by ConfigTrustedProxyDetector from the same sources as TrustProxies (TrustProxies::at() and trustedproxy.proxies) via IpUtils::checkIp on REMOTE_ADDR. It does not call $request->isFromTrustedProxy(), so middleware order and Octane static request state cannot flip the decision.
Locale (landed)
Locale cookie and user preference only work after EncryptCookies +
StartSession. Register on the web and api groups (Laravel 12 / 13
bootstrap/app.php). Prepend globally as well when maintenance / early errors
must carry Content-Language.
use Qiick\HttpBasics\Locale\SetLocaleMiddleware;
use Qiick\HttpBasics\Locale\LocaleNegotiator;
// bootstrap/app.php
->withMiddleware(function (Middleware $middleware) {
// Web: after EncryptCookies + StartSession (group defaults) so cookie / user work.
$middleware->web(append: [
SetLocaleMiddleware::class,
]);
// API routes: Accept-Language negotiation only (no cookie).
$middleware->api(append: [
SetLocaleMiddleware::class,
]);
// Optional but recommended: Content-Language on maintenance 503 and errors
// before group middleware (same reason AssignRequestId is prepended).
$middleware->prepend(SetLocaleMiddleware::class);
})
// After API-key / principal auth (inside the stack, before Content-Language):
app(LocaleNegotiator::class)->applyPrincipalLocale($request, $principal->locale);
Default API routes include api and api/* (so /api itself negotiates).
Vary: Accept-Language is set whenever that header was read on an API
route, not only when it won.
| Config / env | Default | Meaning |
|---|---|---|
HTTP_BASICS_SUPPORTED_LOCALES |
empty → app locale + fallback | Comma-separated supported tags (case-sensitive). |
HTTP_BASICS_LOCALE_MAX_HEADER_BYTES |
1024 |
Oversize Accept-Language is ignored (fall through). |
HTTP_BASICS_LOCALE_MAX_LANGUAGES |
20 |
Too many ranges (counted before dedupe) → treat header as absent. |
Security headers (landed)
Register globally with prepend (same reason as request-id / locale) so maintenance 503 and early errors still get the defense headers.
use Qiick\HttpBasics\Security\SetSecurityHeadersMiddleware;
// bootstrap/app.php — prepend globally so 401/404/405/419/429/503 and
// maintenance responses carry nosniff / Referrer / Permissions (and web XFO +
// CSP). API routes stay baseline-only.
$middleware->prepend(SetSecurityHeadersMiddleware::class);
| Config / env | Default | Meaning |
|---|---|---|
HTTP_BASICS_SECURITY_ENABLED |
true |
Master switch. |
HTTP_BASICS_CSP_MODE |
enforce |
enforce / report-only / off / both. |
HTTP_BASICS_CSP |
empty → Vite-friendly default | Full CSP override (verbatim). |
HTTP_BASICS_CSP_REPORT_URI |
empty | Appended to the built/override CSP string before set. |
HTTP_BASICS_CSP_PROFILE |
vite |
vite, or strict for the ASVS 5.0 Level 2 policy (below). |
HTTP_BASICS_CSP_NONCE |
false |
Strict CSP: a per-request nonce plus 'strict-dynamic' in the built script-src, no 'unsafe-eval'. The strict profile turns it on by itself. |
security.csp.script_hashes |
[] |
sha256-… / sha384-… / sha512-… hashes of allowed inline scripts; needs the nonce (HTTP_BASICS_CSP_NONCE=true or the strict profile), checked at boot. |
HTTP_BASICS_HSTS_MAX_AGE_SECONDS |
0 |
HSTS only when greater than 0 and the request is HTTPS; proxy usually owns this. |
HTTP_BASICS_BASELINE_ON_API_ROUTES |
true |
API routes still get nosniff / Referrer / Permissions. |
With HTTP_BASICS_CSP_NONCE=true the middleware takes the request's nonce from
CspNonceProviderContract before the handler runs and hands it to Vite::useCspNonce(), so
every tag @vite renders carries it. Other inline scripts need the same nonce
(nonce="{{ Vite::cspNonce() }}") or a hash in security.csp.script_hashes.
'unsafe-inline' stays in script-src only as the fallback for pre-CSP2 browsers,
which ignore nonces. style-src keeps 'unsafe-inline': a style nonce would block the
inline style attributes most front ends render. A full override (HTTP_BASICS_CSP) is
sent as written, without a nonce.
Before turning the nonce on, give every inline script in your layout the nonce. The
starter kits' appearance script in resources/views/app.blade.php, which applies the
dark theme before the page paints, is one: without the nonce it is blocked and the theme
flashes or does not apply.
<script nonce="{{ Vite::cspNonce() }}">
(function () { /* appearance script */ })();
</script>
Script hashes are refused at boot without the nonce: a hash makes CSP2+ browsers ignore
'unsafe-inline', so every other inline script would stop running. Do not keep pages
with a nonce in a shared cache (a full-page response cache, a CDN with
Cache-Control: public): every visitor would get the same nonce, and an injection that
knows it would run.
ASVS Level 2 policy (HTTP_BASICS_CSP_PROFILE=strict)
The strict profile (StrictCspPolicyBuilder) is the Vite-friendly policy with three
changes: the nonce is always on (whatever HTTP_BASICS_CSP_NONCE says); script-src
holds only 'nonce-…' 'strict-dynamic' and the configured hashes, with no
'unsafe-inline', 'unsafe-eval' or host sources; and base-uri 'none' replaces
base-uri 'self'. With object-src 'none', frame-ancestors 'none' and
form-action 'self' from the Vite profile, an enforced strict policy covers ASVS 5.0
requirement 3.4.3. Report-only mode only previews it and does not meet the requirement.
What keeps working, and what needs work in the app:
@vite/@viteReactRefreshtags carry the nonce, and'strict-dynamic'lets the scripts they load import further chunks.- Inertia's page data (
<script type="application/json">) is inert and needs no nonce. - Any other executable script needs the nonce (
nonce="{{ Vite::cspNonce() }}") or a hash insecurity.csp.script_hashes: the appearance script, analytics snippets, and scripts an SSR head renders. Inline event handlers (onclick="…") andjavascript:URLs stop working. - A page that renders a
<base>tag needs theviteprofile.
Roll it out in two steps. First set HTTP_BASICS_CSP_MODE=report-only (with
HTTP_BASICS_CSP_REPORT_URI) and fix what the reports show, then switch to enforce.
HTTP_BASICS_CSP and HTTP_BASICS_CSP_REPORT_ONLY are refused at boot with the strict
profile, because they would replace the strict policy on every route. Under strict, the
header(s) the mode sends (Content-Security-Policy for enforce, -Report-Only for
report-only, both for both) replace one already on the response (set by the handler
or another middleware), unless the request opted out. A header the mode does not send is
left as it is. To relax one route (a third-party widget, a
legacy page), set the attribute on that request and send the route's own policy:
use Qiick\HttpBasics\Security\CspNonceProviderContract;
use Qiick\HttpBasics\Security\SecurityHeaderBuilder;
$request->attributes->set(SecurityHeaderBuilder::KEEP_RESPONSE_CSP_ATTRIBUTE, true);
$nonce = app(CspNonceProviderContract::class)->nonceFor($request);
return response()->view('legacy.widget', ['nonce' => $nonce])
->header('Content-Security-Policy', "script-src 'nonce-{$nonce}' 'strict-dynamic' https://widgets.example; object-src 'none'; base-uri 'none'");
Adding host sources next to 'strict-dynamic' has no effect in CSP3 browsers. Load a
trusted third-party script from a tag that carries the nonce instead, and send a different
policy only where the route really needs one.
A browser applies the CSP of the HTML document it loaded, and Inertia visits replace the
page without loading a new document. A relaxed route reached through an Inertia visit
therefore still runs under the strict policy, and a strict page reached from a relaxed one
still runs under the relaxed policy. Cross the boundary with a full page load in both
directions: a plain <a href> (not <Link>), window.location, or
Inertia::location($url) on the server, which answers an Inertia visit with
409 + X-Inertia-Location so the client loads the page as a new document. Check both
directions in the app.
Existing HSTS / XFO / Referrer / Permissions / nosniff on the response are never
replaced. Under the vite profile, if the response already has either
Content-Security-Policy or Content-Security-Policy-Report-Only, this package adds
neither CSP header.
Idempotency (landed)
use Qiick\HttpBasics\Contracts\CredentialBucketResolverContract;
use Qiick\HttpBasics\Idempotency\HandleIdempotencyMiddleware;
// Per route, after throttle / auth / scope / cost:
Route::post('/api/items', ...)->middleware(HandleIdempotencyMiddleware::class);
// Non-replayable routes that issue secrets (API keys, invites, password reset):
Route::post('/api/keys', ...)->middleware(HandleIdempotencyMiddleware::class.':replayable=false');
// Product bucket from server state (never request input):
app()->bind(CredentialBucketResolverContract::class, MyCredentialBucketResolver::class);
| Config / env | Default | Meaning |
|---|---|---|
HTTP_BASICS_IDEMPOTENCY_STORE |
cache |
cache or database (see docs/reference-schema.md). |
HTTP_BASICS_IDEMPOTENCY_TTL_SECONDS |
86400 |
Completed record TTL from completion time, up to 24 hours. Must be greater than lock_ttl_seconds so the record outlives the active lock. |
HTTP_BASICS_IDEMPOTENCY_LOCK_TTL_SECONDS |
60 |
Must be > max_handler_seconds. |
HTTP_BASICS_IDEMPOTENCY_KEY_FORMAT |
uuid |
uuid or sf-string. Both read the RFC 9651 String of draft-ietf-httpapi-idempotency-key-header-09 ("8e03…", quotes and \" / \\ escapes removed before storage) or the same key bare; uuid then requires a UUID. |
HTTP_BASICS_IDEMPOTENCY_ANON_ENABLED |
false |
Public writes via HMAC bucket (ip, user_agent, route). |
HTTP_BASICS_IDEMPOTENCY_ANON_SECRET |
— | Required ≥32 bytes when anon is enabled. |
Refusals use fleet JSON (message + error): idempotency_key_required,
idempotency_key_invalid, idempotency_unsupported_media (415),
idempotency_payload_mismatch (422), idempotency_in_progress (409 + Retry-After),
idempotency_unavailable (503). Replays force the current X-Request-Id and strip
stale X-RateLimit-* headers.
A key is stored per bucket, not per route: the record is identified by
(bucket, key) (the database store's unique (bucket, key_hash)), and the method and
path live in the fingerprint. Reusing a key on another route therefore answers
idempotency_payload_mismatch (or 409 while the first is in flight); it never
replays another route's response. Clients should send a fresh key per operation.
A custom IdempotencyStoreContract receives an IdempotencyContext with every claim: the
key format, the fingerprint version, the request id, and room for a trace id, a
credential public id and namespaced metadata. The database store writes them to the
record (see docs/reference-schema.md). The cache store keeps only what a replay needs
and drops the rest, so an audit trail of idempotent operations (who, which request,
which trace) requires HTTP_BASICS_IDEMPOTENCY_STORE=database.
When the response cannot be stored, the store seals the key so a retry gets
idempotency_not_replayable instead of running the handler again. If the record
itself cannot be written either (a database outage, a cache item too large), a
separate :sealed cache entry carries the seal; only when that write fails too does
the request end with a 503 whose key can run again once it goes stale.
Handlers must be atomic. A 5xx, a 429 or an exception frees the key, so a retry runs the handler again. That is only safe when a failing handler leaves nothing behind: wrap its writes in one database transaction, make no external call (payment, email, webhook) before the point where it can still fail, or make those calls idempotent themselves (pass the same key downstream). A handler that writes or calls out and then throws will run twice.
A handler slower than its budget can run twice. PHP-FPM cannot stop a running
handler, so max_handler_seconds is checked after it returns. Past the budget the lock
may have expired, and another request may have claimed the key and run the handler
again. The middleware then seals the key (retries get idempotency_not_replayable) and
answers 503 instead of the handler's response, though the handler's work is done. Keep
the effect itself idempotent: write it in one transaction keyed by the operation (a
unique column the second run hits), or record it in an outbox table in that
transaction and let a worker perform it once.
The database adapter schedules http-basics:prune-idempotency hourly with
onOneServer() and withoutOverlapping(). Run the Laravel scheduler and use a
shared cache for the scheduler's locks. Expired rows stay in the database until
pruning succeeds. If the product owns the schedule, set
http-basics.idempotency.schedule to false and schedule the prune in the product.
--dry-run counts what would be deleted. --hours keeps records that expired
more recently than the specified number of hours. model:prune against
Qiick\HttpBasics\Idempotency\IdempotencyRecord can also prune expired records.
On API routes the fingerprint includes the locale the response is served in, so
a retry that negotiates to the same locale replays (it-CH,it;q=0.9 and it; an
unsupported fr, no header and en when en is the default). The database store
treats an expires_at it cannot read as never expiring, so such a row keeps
answering instead of letting the handler run again.
The fingerprint includes the media type in lower case with parameters removed.
JSON and JSON Merge Patch represent distinct operations. A known limit of
JSON_BIGINT_AS_STRING is that a JSON integer outside the native integer range
and a JSON string containing the same digits have the same fingerprint.
Personal data erasure
Resolve Qiick\HttpBasics\Erasure\HttpBasicsEraser from Laravel's container in the
product's erasure orchestrator.
Revoke the subject's access and let in-flight requests finish before erasing their records.
use Qiick\HttpBasics\Erasure\HttpBasicsEraser;
$report = app(HttpBasicsEraser::class)->erase(
userId: (string) $user->getAuthIdentifier(),
userPublicId: $user->public_id,
mode: HttpBasicsEraser::DELETE,
publicIds: $principalAndApiKeyPublicIds,
);
Run idempotency after authentication so the database adapter can record the user's
key. For a principal or API key, set the trusted request attribute
HandleIdempotencyMiddleware::CREDENTIAL_PUBLIC_ID_ATTRIBUTE to its UUID. An
invalid value raises InvalidArgumentException before the store is called. Set
HandleIdempotencyMiddleware::ORGANISATION_ID_ATTRIBUTE from trusted server state
for organisation-scoped requests, and pass the same organisation key to
erase(organisationId: ...). Direct adapter callers supply these values through
IdempotencyContext. Supply an organisation UUID for both capture and scoped
erasure. Both boundaries normalize it to lowercase.
DELETE and ANONYMISE both remove every personal value and leave a detached
tombstone until the record's expiration time, so a retry of an erased key is refused
instead of run again; prune deletes it after expiry. The tombstone is an HMAC keyed
with APP_KEY (old keys in APP_PREVIOUS_KEYS still match), and erasure requires it
(docs/stored-formats.md). A dryRun: true
predicts the counts. Real runs forget matching database fallback seals and dispatch
SubjectErasedEvent after commit. The default cache adapter defers the event when
the caller has a transaction on Laravel's default connection. The user's own row
belongs to the product.
Database records with neither a user key nor a credential UUID can contain
personal data from requests such as sign-up or guest checkout. The database section
of the erasure report counts only records linked to the subject by user key or
credential UUID. Unlinked records stop replaying after the configured TTL of up to
24 hours. The next successful hourly run of http-basics:prune-idempotency deletes
them. Avoid replayable responses that contain personal data on routes that cannot
record an owner.
The cache-only adapter expires replay entries within 24 hours. It reports one
retained cache store with reason: cache_ttl because it cannot count entries by
subject, and throws OrganisationScopeUnsupportedException for an organisation-only
request. Database-adapter locks and any seals whose rows have already been pruned
also expire by TTL. After a persistent cache deletion failure, the event reports
the affected seals as kept with cache_ttl, and expiry removes them. For immediate
subject erasure, use the database adapter with recorded owners.
Pre-1.0 installations using the database adapter must republish the updated create migration and rebuild the idempotency table. Its records are transient, and rebuilding the table removes replay protection for outstanding keys, so schedule that change after existing keys have expired.
Threat model (short)
| Topic | Contract |
|---|---|
| Log injection / header smuggling | Charset + single-value X-Request-Id (≥1 alphanumeric); provenance in hidden Context only (generated / trusted_proxy / client). |
| Correlation spoofing | Default inbound accept_from=trusted_proxy; outbound host allowlist empty by default (no propagation). |
Wildcard TrustProxies (* / **) |
Common on Cloud/Forge/Vapor. Client ids are not trusted under * unless trust_wildcard_proxies=true (default false). |
| Outbound leak | Allowlist decides at send time from the real URI; cross-host/port redirects strip X-Request-Id; caller-supplied header wins (no duplicate). |
| Cross-credential replay | Server-side credential bucket + owner lease; unique (bucket, key_hash); never a request-controlled bucket. |
| Digest change | key_hash and fingerprints name their version and algorithm (v2:sha256:…); a form this release cannot read is never replayed nor re-run, and an erased key keeps a tombstone until it expires (docs/stored-formats.md). |
| Anonymous bucket | Best-effort de-duplication, not an identity boundary; HMAC secret rotatable with an expiry drain (rotation invalidates anon records, see docs/stored-formats.md); depends on TrustProxies. |
| Secret replay | Route replayable=false + header deny-list + text/JSON only; API-key issuance must be non-replayable. |
| Retry storms / double execution | 409 while lock held; lease-conditional complete. A cache store that evicts or loses the in-progress marker or the :sealed entry (an LRU cache under memory pressure, a restart without persistence) lets a retry run the handler again: use a shared, persistent cache (Redis with persistence and no eviction of these keys) or the database store for idempotency. Config requires max_handler_seconds strictly less than store lock_ttl_seconds so a route cannot claim a handler budget that outlives the lock. Soft overrun remains possible: max_handler_seconds is checked after $next returns, so a hung or wall-clock-skewed handler can still hold the request past lock expiry; once the lock and stale_after elapse, another worker may claim New (crash-recovery takeover by design). Bound handlers and keep lock TTL above real p99 latency. |
| Cache poisoning | Vary: Accept-Language whenever Accept-Language was read on an API route; authenticated responses documented Cache-Control: private. |
| Proxy trust | Same configured proxies as TrustProxies, evaluated independently of middleware order / request static state. |
CORS (fleet)
Use Laravel's HandleCors (Fruitcake). Prepend
Qiick\HttpBasics\Cors\ConfigureCorsMiddleware so a product
AllowedOriginsResolverContract can overwrite cors.allowed_origins per request
(externa's pattern). With supports_credentials true, the provider refuses to
boot on any origin containing *, any allowed_origins_patterns entry, and
* in allowed_headers or exposed_headers. That includes subdomain
wildcards: https://*.example.com is forbidden with credentials, so list each
origin (https://app.example.com, https://admin.example.com), or return them
per request from the resolver. The check always runs at boot; there is no
switch to turn it off. The middleware applies the origin guard again on every
credentialed request, to resolver output and to config alike. Resolver
responses get Vary: Origin, merged into every existing Vary line; a shared
cache in front must honour it.
The middleware writes the request's origins into config('cors.*') and puts the
configured lists back once the response is built, even when the handler throws, so a
persistent worker with shared configuration restores the default origins before it handles
the next request. Octane provides additional isolation through its per-request configuration
sandbox. Concurrent requests in one process require an isolated configuration per request.
Merge CorsHeaderCatalog::exposedHeaders() / allowedRequestHeaders() into
config/cors.php. Catalog includes X-Request-Id, X-RateLimit-*,
Retry-After, Deprecation, Sunset, Content-Language, Vary, Link,
Location, and Idempotent-Replayed. Origin enforcement with API keys stays
in the product.
Uploads (floor)
Qiick\HttpBasics\Uploads\UploadValidator (or the SafeUpload rule) checks an
upload against http-basics.uploads.contexts.<context>: the hard floor on every
filename suffix and on the sniffed MIME, the extension and MIME allowlists,
max_bytes, magic bytes, the archive budget, and the bound MalwareScannerContract.
The storage name is a random id plus an extension chosen from the sniffed MIME,
never the client suffix.
SVG is refused unless a context sets allows_svg: true, and then the package does
not sanitize it: an SVG can carry <script>, event handlers and links that run
in your origin when the file is opened. With allows_svg, serve uploaded SVGs as a
download (Content-Disposition: attachment), or from a separate origin with no
cookies (a storage bucket domain), or sanitize them in the product before storing.
Never serve them inline from the app's own origin.
Archives are refused by default. A context accepts them only with
allows_archives: true; otherwise a name with an archive suffix (zip, 7z,
tar.gz, docx, xlsx, odt, epub, apk, deb, rpm, …, see
HardFloor::archiveExtensions()), a sniffed archive MIME
(HardFloor::archiveMimeTypes(), plus every OOXML and OpenDocument type), or a
file libzip opens as a ZIP (a PDF+ZIP polyglot included) is refused with
upload_forbidden_type. This holds even when both archive budgets are null.
Brotli, shar and uuencoded tar have no magic bytes, so only their suffix can
catch them.
With allows_archives, the package checks an archive's structure; it does not
make extracting it safe. A product must never extract uploaded archives with a
streaming reader (libarchive or bsdtar from a pipe, Java's ZipInputStream,
Node's unzipper): read them through the central directory, as libzip does, and
validate every extracted file as its own upload. Safe extraction is out of scope
for 1.0.
Archive budget: any file libzip opens as a ZIP (docx, jar and polyglots
included) is inflated in streaming and its real bytes are counted, because the
sizes in its headers are attacker-controlled. Reading stops at size × max_uncompressed_ratio, capped by max_uncompressed_bytes; either limit works
alone, a zero or negative limit allows nothing, and leaving both null turns
the budget off where archives are allowed. An archive over 10 000 entries is
refused before any entry is read. Only ZIP is measured: with archives allowed, a
.gz, .7z or .tar.xz bomb is not.
Streaming readers walk the local headers instead of the central directory libzip
reads, so the two must describe the same bytes. Every local header must sit
exactly at the offset its directory entry gives, the headers must follow each
other with no byte left over from byte 0 to the central directory, every local
header must agree with its entry, every data descriptor must repeat the entry's
CRC and sizes, the directory must end where the only end record starts, and that
record's comment must run to the end of the file. A stored entry with a data
descriptor is refused outright, because only the descriptor marks where its data
ends. A local header hidden in another one's extra field or data, a contradicting
local name, data before the first entry or after the end record, and a second end
record are refused with upload_content_mismatch, as are a corrupt archive, a CRC
mismatch, and an encrypted entry. Two kinds of honest archive are refused too,
because their layout cannot be told apart from a crafted one: Info-ZIP output
written to or from a pipe (… | zip - -, which adds a ZIP64 end record next to a
classic one) and bsdtar --format=zip written to stdout (zero padding after the
end record). Re-create such archives with a seekable writer.
A file libzip cannot open is refused with upload_content_mismatch when its
last 64 KiB hold an end record that a tolerant reader (unzip, Python's
zipfile) would follow: one with a central directory right before it, or a
ZIP64 one. A stray PK\x05\x06 in an ordinary file is not refused. Residual
risk: a polyglot followed by more than 64 KiB of trailing data is not measured;
unzip, bsdtar and Python's zipfile all refuse to open such a file.
Entry names with a .. segment, an absolute or drive path, or a control
character, and symbolic link entries, are refused with upload_forbidden_type.
Nested archives are counted by their compressed bytes and are not opened. The
floor does not check entry names against the extension floor (shell.php
inside a zip passes): a product that unpacks an archive must validate every
extracted file as its own upload.
A floor cannot catch polyglots (GIF89a<?php …, a PNG header followed by
HTML). Serve uploads with X-Content-Type-Options: nosniff and
Content-Disposition: attachment, or from a cookieless domain, and re-encode
images a browser will render inline.
Development
composer update
composer test # Pest
composer lint # Pint
composer analyse # PHPStan level max
No composer.lock is committed (library). CI resolves with --prefer-lowest and
stable across PHP 8.3/8.4/8.5 × Laravel 12/13. Every changed source class
runs through pest --mutate (per-class MSI ≥ 95%).
Public API
docs/public-api.md lists what is public: classes, interfaces and enums marked
@api, config keys, environment variables, Artisan commands, publish tags, the
migration and the wire formats. Everything else in src/ is @internal.
Deprecation policy
See the public API deprecation policy for notice periods, release rules, and upgrade guidance.
Security
Private vulnerability reporting: see SECURITY.md.
License
MIT. See LICENSE.
Alternatives to qiick/laravel-http-basics
Idempotency-Key replays that compare the request body, and JSON:API errors from...
Safe request retries for Laravel APIs via the Idempotency-Key header.
Version History
Pre-releases (1)
| Version | Released | PHP | Laravel | License |
|---|---|---|---|---|
| v1.0.0-beta.1 | ^8.3 | ^12.0 || | MIT |