Przejdź do treści
Biblioteka skilli
Programowanie · Budowanie i kod

security

/security

Buduje i wzmacnia uwierzytelnianie w Phoenix: logowanie OAuth, hashowanie haseł, sesje, RBAC, limity żądań i CSRF.

Licencja
MIT
Ostatnia zmiana repozytorium
22.10.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
8
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
0
Przestarzałość

Brak sygnałów. Repozytorium zmienione 22.10.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Buduje i wzmacnia uwierzytelnianie w Phoenix: logowanie OAuth, hashowanie haseł, sesje, RBAC, limity żądań i CSRF.

Oryginalny opis (EN)

Build and harden Phoenix auth and security — OAuth login, password hashing, sessions, RBAC, rate limiting, CSRF, XSS, SQL injection, secrets. Use when adding login flows or permissions, or handling user input.

Jak działa

  1. Iron Laws — Never Violate These
  2. Quick Patterns
  3. Quick Decisions
  4. Anti-patterns
  5. References
Sekcje z nagłówków SKILL.md, w oryginale · 108 linii, 516 słów
Podgląd SKILL.md
---
name: security
description: "Build and harden Phoenix auth and security — OAuth login, password hashing, sessions, RBAC, rate limiting, CSRF, XSS, SQL injection, secrets. Use when adding login flows or permissions, or handling user input."
effort: medium
user-invocable: false
paths:
  - "**/*auth*.ex"
  - "**/*session*.ex"
  - "**/*password*.ex"
---

# Elixir/Phoenix Security Reference

> **Ash projects**: `AshAuthentication` has its own strategy/token patterns — use the `ash-framework` skill. CSRF, XSS, and secret management patterns below still apply.

Quick reference for security patterns in Elixir/Phoenix.

## Iron Laws — Never Violate These

1. **VALIDATE AT BOUNDARIES** — Never trust client input. All data through changesets
2. **NEVER INTERPOLATE USER INPUT** — Use Ecto's `^` operator, never string interpolation
3. **NO String.to_atom WITH USER INPUT** — Atom exhaustion DoS. Use `to_existing_atom/1`
4. **AUTHORIZE EVERYWHERE** — Check in contexts AND re-validate in LiveView events
5. **ESCAPE BY DEFAULT** — Never use `raw/1` with untrusted content
6. **SECRETS NEVER IN CODE** — All secrets in `runtime.exs` from env vars
7. **LIVEVIEW EVENT PARAMS ARE UNTRUSTED** — Users can alter forms, hooks, and every `phx-value-*` in DevTools. Validate and authorize against server-side state before acting

## Quick Patterns

### Timing-Safe Authentication

```elixir
def authenticate(email, password) do
  user = Repo.get_by(User, email: email)

  cond do
    user && Argon2.verify_pass(password, user.hashed_password) ->
      {:ok, user}
    user ->
      {:error, :invalid_credentials}
    true ->
      Argon2.no_user_verify()  # Timing attack prevention
      {:error, :invalid_credentials}
  end
end
```

### LiveView Authorization (CRITICAL)

```elixir
# `id` is client input even when it came from phx-value-id.
# RE-AUTHORIZE IN EVERY EVENT HANDLER
def handle_event("delete", %{"id" => id}, socket) do
  post = Blog.get_post!(id)

  # Don't trust that mount authorized this action!
  with :ok <- Bodyguard.permit(Blog, :delete_post, socket.assigns.current_user, post) do
    Blog.delete_post(post)
    {:noreply, stream_delete(socket, :posts, post)}
  else
    _ -> {:noreply, put_flash(socket, :error, "Unauthorized")}
  end
end
```

Rendered LiveView events can expose IDs in HTML and websocket payloads. That is
not automatically a vulnerability: treat IDs as public identifiers, never as
proof of access. Use opaque references only when the identifier itself must not
be disclosed, and still perform server-side authorization.

### SQL Injection Prevention

```elixir
# ✅ SAFE: Parameterized queries
from(u in User, where: u.name == ^user_input)

# ❌ VULNERABLE: String interpolation
from(u in User, where: fragment("name = '#{user_input}'"))
```

## Quick Decisions

### What to validate?

- **All user input** → Ecto changesets
- **File uploads** → Extension + magic bytes + size
- **Paths** → `Path.safe_relative/2` for traversal
- **Atoms** → `String.to_existing_atom/1` only

### What to escape?

- **HTML output** → Auto-escaped by default (`<%= %>`)
- **User HTML** → HtmlSanitizeEx with scrubber
- **Never** → `raw/1` with untrusted content

## Anti-patterns

| Wrong | Right |
|-------|-------|
| `"SELECT * FROM users WHERE name = '#{name}'"` | `from(u in User, where: u.name == ^name)` |
| `String.to_atom(user_input)` | `String.to_existing_atom(user_input)` |
| `<%= raw @user_comment %>` | `<%= @user_comment %>` |
| Hardcoded secrets in config | `runtime.exs` from env vars |
| Auth only in mount | Re-auth in every `handle_event` |
| Trusting `phx-value-*` or hidden IDs | Load server-side state and authorize it |

## References

For detailed patterns, see:

- `${CLAUDE_SKILL_DIR}/references/authentication.md` - phx.gen.auth, MFA, sessions
- `${CLAUDE_SKILL_DIR}/references/authorization.md` - Bodyguard, scopes, LiveView auth
- `${CLAUDE_SKILL_DIR}/references/input-validation.md` - Changesets, file uploads, paths
- `${CLAUDE_SKILL_DIR}/references/security-headers.md` - CSP, CSRF, rate limiting, headers
- `${CLAUDE_SKILL_DIR}/references/oauth-linking.md` - OAuth account linking, token management
- `${CLAUDE_SKILL_DIR}/references/rate-limiting.md` - Composite key strategies, Hammer patterns
- `${CLAUDE_SKILL_DIR}/references/advanced-patterns.md` - SSRF prevention, secrets management, supply chain
Pliki w paczce (8)
  • SKILL.md 4 KB
  • references/advanced-patterns.md 7 KB
  • references/authentication.md 2 KB
  • references/authorization.md 2 KB
  • references/input-validation.md 3 KB
  • references/oauth-linking.md 4 KB
  • references/rate-limiting.md 6 KB
  • references/security-headers.md 2 KB

Wersje

RepozytoriumWynikLicencja
Ta strona · oliver-kriska/claude-elixir-phoenix100MIT
flavien-ia/hypervibe-craft100Apache-2.0
boshu2/agentops100Apache-2.0
iamalisson/landspec100MIT
asckye/tia_portal_openness_mcp100MIT
Esposter/Esposter100Apache-2.0
event4u-app/agent-config100MIT
motormetrics/motormetrics100MIT
motormetrics/motormetrics100MIT

Migawka bazy z 13.11.2026 · wersja paczki 2fbb09fb1901 (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 100security-patterns
    Wdraża wzorce uwierzytelniania, autoryzacji, szyfrowania i zarządzania sekretami: JWT, OAuth, hashowanie haseł, klucze API i RBAC.
  • 90ck:better-auth
    Dodaje uwierzytelnianie w TypeScript przez Better Auth: e-mail i hasło, logowanie OAuth, 2FA, passkeye, sesje i role.
  • 95better-auth
    Wdraża uwierzytelnianie i autoryzację w TypeScript przez Better Auth: logowanie e-mailem, OAuth, 2FA, passkeys, sesje, RBAC, limity żądań i adaptery baz danych.
  • 100php-session-auth
    Pomaga zbudować logowanie, rejestrację i sesje w czystym PHP z tokenami CSRF, hashowaniem haseł i blokadą po nieudanych próbach.
  • 95engineering-betterauth-integration
    Wdraża logowanie, OAuth, sesje JWT i kontrolę ról w grach przy użyciu BetterAuth.
  • 81PHP Security Patterns
    Pokazuje wzorce bezpieczeństwa PHP: walidację danych, ochronę przed SQL injection i XSS, tokeny CSRF, hasła i sesje.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.