Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Guard Laravel Package

rennf93/laravel-guard

Laravel Guard is a lightweight package for adding configurable guard-based access control to Laravel apps. It integrates with Laravel’s authentication system, making it easy to define guards, manage providers, and protect routes with simple configuration.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Shipping JSON/API-first Laravel surfaces with a security guard in front. Before v1.6.0, GuardMiddleware::finish() was typed Illuminate\Http\Response, so any route returning response()->json(...), a redirect, or a streamed download could throw a TypeError on the pass-through path. That made the package effectively unsafe for the API and file-download routes most products actually expose. With the signature widened to Symfony\Component\HttpFoundation\Response, "adopt guard middleware on the whole HTTP surface, not just HTML pages" becomes a defensible roadmap decision rather than a gamble.
  • Whether to build vs buy request-level protection (WAF-lite, IP lists, rate limiting, pattern scanning). This adapter is a thin layer over guard-core-php; the engine owns the detection semantics. Buying this means inheriting a reference-driven rule engine and a documented agent extension path (rennf93/guard-agent-php) instead of owning regex scanning, IP canonicalization, and list precedence logic ourselves — a strong argument for build-vs-buy on the "we'll just write middleware" option.
  • Global security-header and CSP strategy. SecurityConfig::customResponseModifier now runs on pass-through responses, including excluded paths and all-checks-bypass responses, and never double-applies. That turns a single config hook into the product-wide mechanism for injecting CSP nonces, HSTS, or per-tenant headers onto every response — including the ones we deliberately exclude from detection. That is a product-level decision (one header contract across authenticated APIs, static assets, and bypassed routes), not an implementation detail.
  • Launch readiness for multi-response-type products. The regression coverage (JSON, redirect, streamed responses, plus the modifier on a JsonResponse) gives a credible "verified for our response types" statement for a release gate — directly usable in a go/no-go review for a customer-facing API launch.
  • Observability and incident-response roadmap. The new per-request scan budget detectionMaxScanSeconds (default 10.0, 0.1–60.0) produces a weighted pattern_timeout threat when exhausted. That is a new, actionable signal: expensive requests get flagged instead of silently scanned to completion. It also opens a tuning decision — cap CPU on hot endpoints vs. accept slower scans — and a logging decision, since passive-mode log wording changed and any log-based alerting/dashboards we own must be updated.
  • Agent-based dynamic rules as a scoped initiative, not a default. Documentation now covers enableAgent, enableDynamicRules, dynamicRuleInterval, enableEnrichment, and lifecycle hooks. But the engine now requires enableAgent: true for dynamic rules and enrichment. So "turn on adaptive rules" becomes a planned feature with a dependency (an agent handler) rather than a config flag someone flips in a PR.
  • Pricing/tiering and abuse-handling policy. IP list precedence is now reference-faithful (whitelist decides alone; blacklist only when no whitelist exists; route whitelist skips global lists; route blacklist consulted only absent a route whitelist). Dynamic ip_blacklist rules are now timed bans for ipBanDuration seconds rather than merges into the static list. These are policy semantics — who gets blocked, for how long, and whether a route can override the global list — that product and support must agree on, and they affect ban-appeal and false-positive handling.

When to Consider This Package

Consider adoption when:

  • The product is Laravel/PHP and needs request-level protection at the middleware layer — pattern scanning, IP allow/deny, rate limiting, security headers — without standing up an external WAF or edge vendor.
  • The HTTP surface is mixed: JSON APIs, redirects, streamed/file responses, plus HTML. The v1.6.0 TypeError fix is the specific precondition here; on any earlier release, treat JSON/streamed routes as unsupported until validated.
  • You want a single, enforced contract for response headers across all responses (including paths excluded from detection), via customResponseModifier. This is the strongest reason to take 1.6.0 specifically.
  • You are on PHP 8.5-era runtime and value the verification story: composer validate --strict, composer audit clean, 168/168 harness checks, 100% line coverage gate.
  • You can absorb the engine floor bump to guard-core-php ^4.4.0. This is mandatory, not optional — applyResponseModifier() and the 4.4.0 config validation do not exist in earlier engines.
  • You need progressive hardening: start passive/log-only, then enable an agent for dynamic rules and enrichment once a handler exists.

Look elsewhere or defer when:

  • You require stable, frozen semantics and cannot take behavior changes in the current cycle. This release carries several engine-level changes (see below) that can alter verdicts without any adapter API change: IP whitelist/blacklist precedence, client-IP canonicalization (ports stripped from X-Forwarded-For, mapped peers inside a trusted IPv4 CIDR no longer trusted, list entries canonicalized), dynamic rule versions no longer stacking, ip_blacklist dynamic rules becoming timed bans, and new pattern_timeout flags on expensive requests.
  • Any SecurityConfig sets enableDynamicRules or enableEnrichment without enableAgent: true — this now fails validation and the engine throws at build time. Blocking upgrade work until configs are corrected.
  • You depend on exact passive-mode log strings. The [PASSIVE MODE] Suspicious activity detected from <ip>: ... - Reason: <reason> - Headers: ... format changed; log-based detectors, dashboards, or SIEM parsers must be updated in lockstep.
  • You need response-body rewriting. The modifier cannot read Set-Cookie, cannot change a body that isn't string-readable (status and headers only), preserves original header value lists when unchanged, and leaves the response untouched if the modifier throws. It is a header/status hook, not a transformation layer.
  • You need first-class support guarantees rather than a community/reference-aligned package. Note rennf93/guard-agent-php is only under suggest, so agent paths are optional-by-design and not a hard dependency.
  • Edge/CDN-level blocking, bot management, or DDoS absorption is the actual requirement — this is in-process middleware, not an edge control.

How to Pitch It (Stakeholders)

For executives (one paragraph): v1.6.0 makes our Laravel security middleware safe to run on the entire product surface, including JSON APIs, redirects, and file downloads — previously these could fail outright with a TypeError, which quietly restricted where we could deploy it. The same release lets us enforce one response-header policy (CSP, HSTS, tenant headers) uniformly, even on routes we deliberately exclude from scanning, and adds a CPU-time budget so a single pathological request can be flagged rather than silently consuming the worker. Cost is a mandatory engine bump plus a short config-and-logging migration. Verdict: adopt before the next API launch; it converts a partial-coverage tool into a whole-surface control.

For engineering leads: The change is small in our code and non-trivial in behavior. Two signatures moved from Illuminate\Http\Response to Symfony\Component\HttpFoundation\Response, which fixes pass-through for JsonResponse, RedirectResponse, and StreamedResponse; the block path still returns Illuminate\Http\Response from the translator, so block-handling callers are unaffected. finish() now calls GuardEngine::applyResponseModifier() between the engine security headers and the CORS verdict headers, so the modifier applies to pass-through responses and never twice to an engine-modified one. Nothing is read from the response when no modifier is configured. Plan work for: (1) adding enableAgent: true wherever enableDynamicRules or enableEnrichment is set, (2) reviewing IP list configuration against the new precedence rules, (3) re-baselining any ban or rate-limit expectations now that client-IP canonicalization is stricter — some clients will match where they previously didn't, (4) auditing dynamic rule assumptions now that versions no longer stack and ip_blacklist rules are timed bans, and (5) updating passive-mode log matchers to the new wording. Verification is credible: 168/168 checks green including the three response-kind regressions and the modifier-on-JsonResponse case, composer validate --strict and composer audit clean, 100% line coverage.

For security and support: Two policy-visible shifts. First, list precedence is now reference-faithful — a configured whitelist decides alone, blacklist applies only when no whitelist exists, a route whitelist skips the global lists for that request, and a route blacklist is consulted only when the route has no whitelist. Second, client-IP canonicalization changed: X-Forwarded-For entries lose their port, mapped peers inside an IPv4 CIDR of trustedProxies are no longer trusted, and list matching canonicalizes entries. Expect a small number of verdict changes on the first deploy; treat it as a config review and an appeal-handling note, not an outage. Also note detectionMaxScanSeconds can now flag a request as pattern_timeout where it previously completed scanning — decide the default per route tier rather than leaving 10.0 everywhere by accident.

Recommendation: Upgrade to v1.6.0, gate it on a config audit (agent flags, IP lists, trusted proxies) and a log-parser update, and treat the response-modifier coverage as the enabling feature for a uniform security-header standard across all response types. Do not advertise response-body transformation — the modifier is header-and-status only, cannot see Set-Cookie, and no-ops on non-string bodies and on modifier exceptions.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
jinas/dhivatar
store-doc/laravel-storage-driver
plus-it/laravel-translation-manager
diephp/perhaps
diephp/telegraph
osmaviation/spreadsheet
microsoft/fluentui-system-icons
mmccook/php-json-canonicalization-scheme
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console
pnscripts/filament-broadquill-lite
pnscripts/laravel-sentfold-lite
vleap/mx-sdk-laravel-internal
twidpay/utils
htetmyathlaing/scout-elasticsearch-driver
artisan-toolbox/front-awesome
ls/client-assistant
users-au/laravel-client
cgv/localized-resource