security

javascript
// Configuration management with validation
const Joi = require('joi');

// Define schema for all environment variables
const envSchema = Joi.object({
  NODE_ENV: Joi.string()

Environment variable management and secret rotation

environment-variables secrets configuration
by Ryan Nakamura 2 tabs
ruby
class WebhookSignature
  class VerificationError < StandardError; end

  TOLERANCE = 300 # seconds

  def initialize(payload:, header:, secrets:)

Robust Webhook Verification (HMAC + Timestamp)

rails security webhooks
by codesnips 3 tabs
hcl
# ECS Task Execution Role (pull images, push logs)
resource "aws_iam_role" "ecs_execution" {
  name = "${var.project_name}-ecs-execution"

  assume_role_policy = jsonencode({
    Version = "2012-10-17"

AWS IAM policies and security best practices

aws iam security
by Ryan Nakamura 1 tab
javascript
// 1. DANGEROUS: Never use innerHTML with user input
const userInput = '<img src=x onerror="alert('XSS')">';

// WRONG - vulnerable to XSS
document.getElementById('output').innerHTML = userInput;

Front-end security - XSS and CSRF prevention

security xss csrf
by Alex Chang 1 tab
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
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
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
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