/nette:nette-httpfrom nette
Covers Nette HTTP layer: Request (URL, query, POST, cookies, headers, security checks), Response (cookies, headers, redirects), sessions, CSRF/Same-Origin protection, SSRF guards, and file uploads.
Ships in nette. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Installed with composer require nette/http. The framework registers http.request (Nette\Http\Request), http.response (Nette\Http\Response), http.requestFactory and session.session (Nette\Http\Session). All autowired – inject Nette\Http\IRequest / Nette\Http\IResponse / Nette\Http\Session by type; in presenters use $this->getHttpRequest(), $this->getHttpResponse(), $this->getSession() / $this->getSession('sectionName').
Nette\Http\Request is immutable; RequestFactory::fromGlobals() strips control characters and invalid UTF-8 from GET/POST/COOKIE and the URL.
$url = $httpRequest->getUrl(); // UrlScript, not a string
$httpRequest->getQuery(); // all GET params; getQuery('id') for one (null if missing)
$httpRequest->getPost('name'); // POST param or null
$httpRequest->getCookie('lang'); // ?string; getCookies() for all
$httpRequest->getHeader('User-Agent'); // ?string, case-insensitive; getHeaders() keys are lowercase
$httpRequest->isSecured(); // HTTPS?
$httpRequest->isAjax(); // X-Requested-With: XMLHttpRequest
$httpRequest->getRemoteAddress(); // ?string
$httpRequest->getBasicCredentials(); // ?array – since 3.2 NOT in $url->getUser()/getPassword()
getRemoteAddress() and isSecured() are wrong behind a reverse proxy until you list the proxy, otherwise you get the load balancer's IP and http for a TLS-terminated request:
http:
proxy: 127.0.0.1 # IP, CIDR range, or a list of them
forceHttps: true # 3.3.4+; proxy does not send X-Forwarded-Proto at all
getReferer() and getRemoteHost() are deprecated (getRemoteHost() always returns null). Use getOrigin(): ?UrlImmutable – scheme+host+port from the Origin header, absent for plain navigation and same-origin GET.
File uploads – always index with getFile(), never walk the getFiles() tree, because the client controls its shape:
$file = $httpRequest->getFile(['my-form', 'details', 'avatar']); // ?FileUpload
if ($file?->hasFile()) {
$file->getUntrustedName(); // as sent by the user – never use as a path
$file->getSanitizedName(); // safe filename
$file->move($dest);
}
getFile() returns null when the field was submitted empty (UPLOAD_ERR_NO_FILE), so always
use ?->. It is the form control that hands you a dummy object instead: UploadControl
returns a FileUpload carrying that error unless setNullable() is on — that is where
hasFile() (did the user pick a file?) and isOk() (did it arrive intact?) differ.
Every setter throws Nette\InvalidStateException once headers are out; isSent() tells you. setHeader() replaces (and null deletes), addHeader() appends another line of the same name.
$httpResponse->setCode(IResponse::S404_NotFound);
$httpResponse->setExpiration('1 hour'); // Cache-Control + Expires; null = no cache at all
$httpResponse->sendAsFile('invoice.pdf');
$httpResponse->redirect($url); // does NOT terminate the script
In a presenter use $this->redirect() / $this->getHttpResponse()->redirect(); $this->terminate(); – Response::redirect() only sets Location and echoes a fallback link.
$httpResponse->setCookie('lang', 'en', '100 days'); // expiration: interval string, date, or null = session cookie
$httpResponse->setCookie('t', 'dark', '1 year', sameSite: SameSite::None, partitioned: true);
$httpResponse->deleteCookie('lang');
SameSite is now the enum Nette\Http\SameSite (Lax/Strict/None); the IResponse::SameSiteLax constants are deprecated. Defaults: sameSite = Lax, httpOnly = true, secure from http: cookieSecure (auto). SameSite=None and partitioned force Secure on regardless of what you pass. Passing an absolute UNIX timestamp as $expire is deprecated – a number means relative seconds; a session cookie is null, not 0.
Never call session_start(), $_SESSION or session_regenerate_id() yourself – Nette configures the hardening ini directives (use_only_cookies, use_strict_mode, cookie_httponly, no trans-sid), namespaces data under $_SESSION['__NF'], and expires per-section/per-variable metadata at start. A hand-started session bypasses all of it.
The session starts lazily on the first read or write (autoStart: smart). Start it explicitly with $session->start() if you know you need it and output may already be flowing.
$section = $session->getSection('cart'); // SessionSection; $this->getSession('cart') in a presenter
$section->set('items', $items);
$section->set('flash', $msg, '30 seconds'); // 3rd arg = per-variable expiration
$section->get('items'); // null when missing
$section->remove('items'); // no argument = drop the whole section
$section->setExpiration('20 minutes'); // whole section; ($expire, $variables) for selected keys
$section->removeExpiration('flash');
set($name, null) is a remove, not a write of null.get() takes exactly one argument – get('key', $default) throws ArgumentCountError. Use $section->get('key') ?? $default.$section->items), isset(), unset() and ArrayAccess are all deprecated. The magic read in particular goes through &__get(), so it starts the session for writing and materialises the key even on a pure read; ArrayAccess reads and isset() do not. That is why set()/get() exist.session: expiration:), otherwise you get a warning and the data dies with the session anyway.session:
expiration: 14 days # inactivity timeout, default '3 hours'
autoStart: smart # smart (default) | always | never
cookieSamesite: Lax # Lax (default) | Strict | None
name: MYID # any PHP session directive in camelCase, e.g. savePath
handler: @myHandler
debugger: true # session panel in Tracy Bar
Login/logout session-id regeneration is handled by nette/security – see nette-security.
Since nette/http 3.4 the protection is based on the Sec-Fetch-* request headers (Fetch Metadata), which the browser sets itself and page JavaScript can neither forge nor strip. It replaced the older SameSite=Strict cookie check (Request::isSameSite(), now deprecated).
Request::isFrom(FetchSite|array $site, FetchDest|array|null $dest = null, ?bool $user = null): bool
FetchSite cases: SameOrigin, SameSite, CrossSite, None (direct navigation – typed URL, bookmark, link in an e-mail). FetchDest describes the resource kind (Document, Empty, Image, …); $user = true requires a genuine user gesture. All given conditions must match.
if (!$httpRequest->isFrom(FetchSite::SameOrigin, FetchDest::Document, user: true)) {
$this->error();
}
What this means in practice:
POST forms and presenter signals are protected automatically – Nette\Forms\Form::receiveHttpData() and UI\Form::signalReceived() require FetchSite::SameOrigin, and every handle*() method implicitly gets #[Requires(sameOrigin: true)].
$form->addProtection() is deprecated (nette/forms 3.3) – the built-in protection is sufficient, and unlike a token it needs no session. Do not add it to new forms.
To allow a legitimate cross-origin POST: $form->allowCrossOrigin() (this replaced disableSameSiteProtection()).
Behavior change in 3.4: direct navigation is no longer treated as same-site. A signal reached from a link in an e-mail (Sec-Fetch-Site: none) now fails. Mark it explicitly:
#[Requires(sameOrigin: false)]
public function handleUnsubscribe(string $token): void
Safari < 16.4 sends no Sec-Fetch-*; Nette falls back to the SameSite=Strict cookie _nss, sent only to such browsers since 3.4. It can only prove "not cross-site", so a check that also demands $dest or $user returns false there. http: disableNetteCookie: true switches the cookie off — and with it the only fallback, which breaks every POST from those browsers.
Any non-browser client fails the check, not just old Safari: curl, a mobile app, a webhook or server-to-server traffic sends no Sec-Fetch-* and no _nss, so isFrom(SameOrigin) is false. The failure is quiet — the form reports "not submitted" rather than an error. API endpoints therefore need #[Requires(sameOrigin: false)] (or allowCrossOrigin() on a form) plus authentication of their own, typically a token.
Form-side details live in nette-forms; authentication in nette-security.
New in nette/http 3.4. Validate every user-supplied URL before the server fetches it – otherwise an attacker reaches your loopback, private network or cloud metadata at 169.254.169.254.
use Nette\Http\UrlValidator;
if (!(new UrlValidator)->allows($userUrl)) {
return; // unsafe
}
The default policy is deliberately strict: https only, port 443 only, and every DNS-resolved A/AAAA address must be publicly routable. Loosen it through constructor named arguments – schemes, ports (null = any), allowPrivateIps, allowLoopback, allowLinkLocal, allowReserved, allowUserinfo, hostAllowlist, hostBlocklist. Multicast is rejected unconditionally. Host patterns are exact or *.example.com (any subdomain depth, not the apex – list both).
allowsWithoutDns() – same checks minus DNS resolution and IP ranges; a cheap pre-filter only.getResolvedIPs() – returns the validated IPs ([] on failure). Pin the fetch to them (CURLOPT_RESOLVE) to close the DNS-rebinding race between validation and download.Nette\Http\IPAddress is the value object behind it: new IPAddress($s) (throws), IPAddress::tryFrom(), isValid(), predicates isPublic(), isPrivate(), isLoopback(), isLinkLocal(), isMulticast(), isReserved(), plus isInRange('10.0.0.0/8'). IPv4-mapped IPv6 (::ffff:127.0.0.1) is normalized, so isLoopback() sees through that classic filter bypass.
Url is mutable (setters), UrlImmutable returns new instances from with*() withers, and UrlScript extends UrlImmutable adding the notion of where the application root sits. Request::getUrl() returns a UrlScript with those parts already filled in – don't construct one by hand.
For http://nette.org/admin/script.php/pathinfo/?name=param#footer with script path /admin/script.php:
| Method | Value |
|---|---|
getScriptPath() | /admin/script.php |
getBasePath() | /admin/ |
getBaseUrl() | http://nette.org/admin/ |
getRelativeUrl() | script.php/pathinfo/?name=param#footer |
getPathInfo() | /pathinfo/ |
When generating links or asset paths by hand, prefix with getBasePath() – a bare /css/style.css breaks as soon as the app lives in a subdirectory. getBasePath(), getBaseUrl() and getRelativeUrl() on plain Url are deprecated (3.1); they belong to UrlScript. $url->getFragment() on a request URL is always empty – browsers never send the fragment.
The full Nette documentation for this topic is bundled with the plugin. Read a page when you need details beyond this skill:
http: and session: sectionsWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub nette/agent-plugins --plugin nette20 skills in this plugin
/frontend-developmentProvides frontend development guidelines for Nette. Use when working with Vite, SCSS, JavaScript/TypeScript, Nette Assets ({asset} tag, asset mapping), ESLint with @nette/eslint-plugin, Naja AJAX library, frontend entry points, npm packages in Nette context, Tailwind CSS with Latte templates, nette-forms npm package, HMR, build commands (npm run dev/build), or passing data from PHP to JavaScript./latte-templatesInvoke before creating or modifying .latte files, even for single-line changes. Provides Latte syntax, tags, filters, n:attributes, layouts, template inheritance, AJAX snippets, extensions, and Nette integration. Also trigger when user mentions Latte by name./neon-formatInvoke before creating or modifying .neon files. Provides NEON syntax and Nette configuration conventions. Use when writing or editing .neon config files, asking about NEON syntax (entities, multiline strings, inline notation, special values, escaping), converting YAML to NEON, parsing or encoding NEON in PHP (Neon::decode, Neon::encode), running neon-lint, or debugging NEON syntax errors. For phpstan.neon, use the phpstan-analysis skill (from nette-dev plugin) instead. Do not trigger for Nette DI concepts like autowiring and service registration without .neon file context./nette-architectureInvoke before designing presenters, modules, or application structure in web application. Use when asking about directory structure (app/ folder organization), presenter organization (modules, Admin/Front/Api, BasePresenter), domain-driven placement (Core/ vs Model/), component and factory placement, presenter lifecycle (action/render/template), CLI tasks, Accessory placement, project skeleton, or refactoring architecture. Also trigger when starting a new Nette project./nette-cachingInvoke before writing or reviewing code that uses nette/caching. Covers the Cache object and namespaces, load() with a generator callback, save(), remove(), clean(), the dependency array (Cache::Expire, Cache::Tags, Cache::Files, Cache::Items, Cache::Priority, Cache::Sliding, Cache::Callbacks), the Journal requirement for tags and priorities, bulkLoad(), output capture, storages (FileStorage, MemcachedStorage, SQLiteStorage, MemoryStorage, DevNullStorage) and the {cache} Latte tag. Also trigger for cache.storage or cache.journal in NEON, invalidation by tag, cache stampede, or disabling the cache in tests. Not for the Latte template cache or the DI container cache, which are separate mechanisms./nette-command-lineInvoke before writing or reviewing a PHP command-line script or tool that uses nette/command-line 2.0. Covers Command with addFlag(), addOption(), addArgument() and addCommand(), the Parser and its ParseResult, standalone --help and --version, negatable flags, optional values, defaults, enum, repeatable parameters, Normalizers, commands and subcommands dispatched with match, HelpRenderer, ParseException and ParseFailure, and the Console (colors and ColorDepth, NO_COLOR and FORCE_COLOR, links, setStatus() progress lines) with Ansi for measuring text. Also trigger for bin/ scripts, CLI argument parsing, "print the help", colored terminal output or progress bars in PHP. Also trigger when upgrading from 1.x, for code using new Parser($help), addFromHelp(), addSwitch(), parseOnly() or Parser::normalizeRealPath(), and for errors such as "Call to undefined method Parser::addFromHelp()" or "Too few arguments to function Parser::parse()".Other plugins' skills for the same job