security

yaml
# === Vault Agent Injector: Auto-inject secrets into pods ===
apiVersion: apps/v1
kind: Deployment
metadata:
  name: api-server
  namespace: production

HashiCorp Vault for secrets management in Kubernetes

vault secrets kubernetes
by Ryan Nakamura 1 tab
go
package middleware

import (
  "net/http"
)

CORS allowlist middleware (no wildcard surprises)

go http security
by Leah Thompson 1 tab
rust
use axum::{
    extract::{FromRequestParts, State},
    http::{request::Parts, StatusCode},
    response::{IntoResponse, Response},
    Json,
};

Axum Bearer Token Extractor with Shared Auth State and Typed Claims

axum authentication middleware
by codesnips 3 tabs
ruby
class PaymentService
  def initialize
    Stripe.api_key = Rails.application.credentials.stripe[:secret_key]
  end

  def create_payment_intent(amount:, currency: 'usd')

Environment-specific configuration with Rails credentials

rails security configuration
by Alex Kumar 2 tabs
python
from django.conf import settings
from django.db import models
from django.utils import timezone


class InvoiceQuerySet(models.QuerySet):

Scope a Django DetailView to the Request User with get_queryset

django authorization class-based-views
by codesnips 3 tabs
php
<?php

declare(strict_types=1);

namespace App\Security;

PHP Login Rate Limiting with a Sliding-Window Throttle Middleware

php rate-limiting middleware
by codesnips 3 tabs
go
package auth

import "golang.org/x/crypto/bcrypt"

func HashPassword(pw string, cost int) ([]byte, error) {
  if cost == 0 {

Password hashing with bcrypt and a calibrated cost

go security auth
by Leah Thompson 1 tab
go
package upload

import (
	"errors"
	"io"
	"log"

Streaming Multipart File Uploads to Disk in Go net/http

go net-http multipart
by codesnips 3 tabs
ruby
class AttachmentContentTypeValidator < ActiveModel::EachValidator
  SIGNATURES = {
    "image/png"       => ["\x89PNG\r\n\x1a\n".b],
    "image/jpeg"      => ["\xFF\xD8\xFF".b],
    "image/gif"       => ["GIF87a".b, "GIF89a".b],
    "application/pdf" => ["%PDF-".b]

Safer File Attachments: Content Type + Size Validation

rails security active-storage
by codesnips 4 tabs
php
<?php

namespace App\Models;

use App\Support\TransientUrl;
use Illuminate\Database\Eloquent\Model;

Generate Temporary Signed S3 Download URLs for Private Files in Laravel

laravel s3 storage
by codesnips 4 tabs
python
import hmac
import hashlib
import time
from fastapi import Request, HTTPException, status

Verifying Stripe Webhook Signatures With a Reusable FastAPI Dependency

fastapi webhooks security
by codesnips 3 tabs
ruby
module Api
  module V1
    class PostsController < BaseController
      before_action :authenticate_user!

      def create

Strong parameters for mass assignment protection

rails security api
by Alex Kumar 1 tab