Skip to content
Back to skills

Phoenix Knowledge Patch

ASecurity

Phoenix

  • 25 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added September 5, 2026
developmentjavascriptjavaapidatabasebackendsecurity

Works with

  • terminal
  • cli
  • api

Security analysis

A100/100

Pro scans all 6 files and shows the line behind each finding

Scanned December 1, 2026

npx -y skills add Nevaberry/nevaberry-plugins --skill phoenix-knowledge-patch --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Phoenix Knowledge Patch?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Phoenix Knowledge Patch
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/nevaberry-phoenix-knowledge-patch-nevaberry-plugins/badge)](https://www.skillsdirectory.com/skills/nevaberry-phoenix-knowledge-patch-nevaberry-plugins)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: phoenix-knowledge-patch
description: Phoenix
version: "1.8.x"
license: MIT
metadata:
  author: Nevaberry
---


# Phoenix knowledge patch

Load this skill when upgrading Phoenix, working with generated projects and
authentication, configuring scopes or verified routes, or diagnosing channels,
Presence, and JavaScript transport behavior.

## Reference index

| Reference | Topics |
| --- | --- |
| [Upgrades, security, and configuration](references/upgrades-security-and-configuration.md) | Security fixes, release selection, runtime requirements, endpoint configuration, browser headers, log filtering |
| [Generators, layouts, and projects](references/generators-layouts-and-projects.md) | Project creation, dependencies, templates, controllers, components, routing, certificates |
| [Scopes and authentication](references/scopes-and-authentication.md) | Scope configuration, nested routes, ownership, context calls, LiveView hooks, tests, authentication migration, delivery, privacy |
| [Runtime APIs and JavaScript](references/runtime-apis-and-javascript.md) | Assigns, channel limits, join references, LongPoll, reconnection, Presence, endpoint broadcasts |

## Breaking changes and deprecations

### Runtime and endpoint configuration

Phoenix 1.8 requires Erlang/OTP 25 or later.
Replace the injected endpoint `config` variable with `Application.compile_env/3`
at module scope. Keep settings read this way consistent between compilation and boot.

```elixir
@endpoint_config Application.compile_env(:my_app, __MODULE__, [])
```

### Controller declarations and layouts

Declare formats with `use Phoenix.Controller, formats: [:html]`, or use
`formats: []` when they are determined later. Replace deprecated `:namespace`
and `:put_default_views` options with explicit view configuration.
Pass the layout module with the layout name:

```elixir
put_layout(conn, html: {MyAppWeb.Layouts, :print})
```

### Routing restrictions

The router's `:trailing_slash` option is deprecated. Use verified routes for URL
generation, such as `~p"/posts/"` for a path that needs a trailing slash.
From 1.8.6, using `Phoenix.VerifiedRoutes` more than once in a module or
interpolating a list into a verified route raises.

Phoenix 1.8.14 raises at compile time if the `:router` option to
`use Phoenix.VerifiedRoutes` is not a compile-time literal. Pass the router
module directly:

```elixir
use Phoenix.VerifiedRoutes,
  endpoint: MyAppWeb.Endpoint,
  router: MyAppWeb.Router
```

### Browser security defaults

With no policy set, `put_secure_browser_headers` defaults to the CSP
`base-uri 'self'; frame-ancestors 'self';`. To embed the app on another origin,
set your own `frame-ancestors` policy and account for removal of the default
`x-frame-options` and `x-download-options` headers.
Phoenix filters parameters matching `token` in logs alongside `password`
starting in 1.8.7.

## Security upgrades and transport limits

Upgrade to Phoenix 1.8.17 for fixes to topic-wide denial of service caused by
channel serialization failures and a Presence tracker crash involving presence keys.
See the security reference for the advisory links and release-selection details.

The `max_channels_per_transport` option defaults to 100 in 1.8.9.
Starting in 1.8.16, configure the concurrent channel limit for a socket declaration
in `Phoenix.Endpoint.socket/3`:

```elixir
socket "/socket", MyAppWeb.UserSocket, max_channels_per_transport: 50
```

Phoenix 1.8.9 enforces a limit of 100 events per LongPoll request. If your
application may send larger batches, upgrade to 1.8.7 before deploying 1.8.9.
LongPoll is active by default in 1.8.0 and 1.8.1 and returns to opt-in in 1.8.2:

```elixir
socket "/socket", MyAppWeb.UserSocket, longpoll: true
```

## Scopes and generated resources

### Selecting ownership and route values

`mix phx.gen.auth` makes its generated user scope the default when the app has
no default scope. Schema, context, LiveView, HTML, and JSON generators
automatically use the single scope marked `default: true`.
Select a named scope with `--scope`:

```console
mix phx.gen.live Blog Post posts title:string --scope organization
```

Use `access_path` for the database ownership key and `route_access_path` for
the value interpolated into the generated route:

```elixir
config :my_app, :scopes,
  organization: [
    module: MyApp.Accounts.Scope,
    assign_key: :current_scope,
    access_path: [:organization, :id],
    schema_key: :org_id,
    schema_type: :id,
    schema_table: :organizations,
    route_prefix: "/organizations/:org",
    route_access_path: [:organization, :slug],
    test_data_fixture: MyApp.AccountsFixtures,
    test_setup_helper: :register_and_log_in_user_with_org
  ]
```

With `route_prefix` set and `route_access_path` omitted, the generator drops
the final key from `access_path`, keeping the original path if that would be empty.
For `[:organization, :id]`, it uses the organization struct, which can derive
`Phoenix.Param` with `@derive {Phoenix.Param, key: :slug}`.

### Context access and authentication hooks

Generated context functions take the scope struct as their first argument:

```elixir
scope = socket.assigns.current_scope
posts = Blog.list_posts(scope)
post = Blog.get_post!(scope, id)
```

`Blog.get_post!(scope, id)` raises `Ecto.NoResultsError` when the ID is outside
that scope; Phoenix renders it as a 404 with `debug_errors: false`.
Resolve nested-route organizations through the signed-in user's scope to enforce
membership. Populate the organization in `:current_scope` after
`fetch_current_scope_for_user` in the browser pipeline and in an `on_mount`
hook after the authentication scope hook in the `live_session`.

Put generated LiveView routes for user-owned resources in the authentication
generator's `:require_authenticated_user` live session. On routes that allow
anonymous visitors, use `{MyAppWeb.UserAuth, :mount_current_scope}` to load
`:current_scope`, which is `nil` for signed-out visitors.

### Migration types and test helpers

For table-backed scopes, `schema_type` sets the Ecto schema field type;
`schema_migration_type` sets the generated migration's foreign key type.
Omitting the latter uses the default migration foreign key type.
Set `schema_table: nil` for a plain ownership column with no backing table.

The `test_data_fixture` module is imported into context tests and must provide
a zero-argument fixture named after the scope, such as
`organization_scope_fixture/0`, returning a unique scope struct.
The `test_setup_helper` function must be available to generated controller and
LiveView tests as an ExUnit setup callback supplying `conn` and `scope`.

## Generated authentication

Generated authentication blocks unconfirmed accounts.
`UserAuth.require_sudo_mode` enforces recent authentication for sensitive routes.
`redirect_if_user_is_authenticated` is generated only for controller-based authentication.

Apps with authentication generated in Phoenix 1.7 or earlier can adopt scopes
independently of magic links. For passwordless registration, add a new migration
making `hashed_password` nullable with `null: true`; when retiring the old
password-recovery flow, clear `hashed_password` to `nil` for every unconfirmed account.

If the generated notifier logs account messages to the terminal, connect it to
your delivery backend to send confirmation and sign-in links. With the default
`mix phx.new` Swoosh setup, view delivered development mail at `/dev/mailbox`.
Generated registration reports already-registered email addresses. If account
membership must be private, account for response content and timing in
registration, sign-in, and other notification flows.

Authentication generated with Phoenix 1.8.12 clears the stored return path after
sign-in. If it persists across sign-ins in an existing app, update the generated code.

## Generators and routing conveniences

Phoenix 1.8.6 adds interactive project generation with `mix phx.new --interactive`.
The context, HTML, JSON, and LiveView generators can infer the context from the
schema's plural name: `mix phx.gen.html Post posts title:string` generates `Posts`.
Generators use Ecto 3.13's `Repo.transact/2` for generated transactions.
Use the `.eex` filename suffix for `phx.gen.*` templates starting in 1.8.6.

`mix phx.gen.auth` warns in projects without esbuild because its features expect
`phoenix_html.js` in the JavaScript bundle. Include that asset with another build setup.
Existing apps with an older `CoreComponents` need the hidden-input clause to use
`<.input field={@form[:return_to]} type="hidden" />`, restored in 1.8.2.

Starting in 1.8.3, enable deterministic verified-route query parameter order
in tests with `config :phoenix, :sort_verified_routes_query_params, true`
in `config/test.exs`. In 1.8.10, `pipe_through` accepts a plug and its options
as a tuple: `pipe_through [:browser, {MyAppWeb.RequireRole, :admin}]`.

## Assigns and JavaScript transport behavior

In 1.8.2, `Phoenix.Socket.assign/2` and `Phoenix.Controller.assign/2` accept a
function receiving existing assigns and returning updates to merge.
The controller API also accepts a map or keyword list directly.

```elixir
Phoenix.Socket.assign(socket, fn assigns -> %{count: Map.get(assigns, :count, 0) + 1} end)
```

The JavaScript socket pauses reconnection attempts while the page is hidden
starting in 1.8.2. In 1.8.17, allow these attempts with `reconnectWhenHidden: true`:

```javascript
import { Socket } from "phoenix"

const socket = new Socket("/socket", { reconnectWhenHidden: true })
socket.connect()
```

Starting in 1.8.16, WebSocket close code `1000` alone no longer suppresses
automatic reconnection; normal closures follow the client's usual reconnect rules.
Phoenix 1.8.12 accepts channel messages omitting `join_ref`; versions 1.8.3
through 1.8.11 can drop them. Messages with stale join references are dropped
starting in 1.8.3, so use the current join reference after rejoining a channel.
Phoenix 1.8.17 supports binary channel messages over LongPoll.

Files in this skill

  • SKILL.md9 KB
  • coverage.json523 B
  • references/generators-layouts-and-projects.md3.3 KB
  • references/runtime-apis-and-javascript.md4 KB
  • references/scopes-and-authentication.md5.3 KB
  • references/upgrades-security-and-configuration.md3.6 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.