security

ruby
AuditLog.create!(
  actor_id: current_user.id,
  action: 'member.approve',
  target_type: 'Member',
  target_id: member.id,
  ip_address: request.remote_ip,

Structured audit logging for privileged actions

audit-logging siem observability
by Kai Nakamura 1 tab
typescript
import { S3Client } from "@aws-sdk/client-s3";
import { createPresignedPost, PresignedPost } from "@aws-sdk/s3-presigned-post";
import { randomUUID } from "crypto";

const s3 = new S3Client({ region: process.env.AWS_REGION });
const BUCKET = process.env.UPLOAD_BUCKET!;

Pre-signed S3 upload from the browser

s3 security aws-sdk
by codesnips 3 tabs
dockerfile
# Optimized production Dockerfile

# Stage 1: Dependencies
FROM node:20-alpine AS deps
WORKDIR /app

Docker image optimization and security scanning

docker optimization security
by Ryan Nakamura 2 tabs
kotlin
package com.example.myapp.data.local

import android.content.Context
import android.content.SharedPreferences
import androidx.security.crypto.EncryptedSharedPreferences
import androidx.security.crypto.MasterKey

Encrypted SharedPreferences for secure storage

kotlin android security
by Alex Chen 1 tab
php
<?php

namespace App\Models\Scopes;

use App\Support\TenantContext;
use Illuminate\Database\Eloquent\Builder;

Automatic Multi-Tenant Scoping in Laravel with a Global Scope and Auth Context

laravel multi-tenancy eloquent
by codesnips 4 tabs
ruby
class Current < ActiveSupport::CurrentAttributes
  attribute :tenant, :request_id

  def tenant=(tenant)
    super
    Rails.logger.tagged("tenant=#{tenant&.id}") if tenant

Tenant Isolation in Rails with CurrentAttributes and an around_action

rails multi-tenancy current-attributes
by codesnips 4 tabs
typescript
import { SetMetadata } from '@nestjs/common';

export enum Role {
  User = 'user',
  Editor = 'editor',
  Admin = 'admin',

Role-Based Access Control in NestJS with a Custom Guard and @Roles Decorator

nestjs authorization rbac
by codesnips 3 tabs
typescript
import { Request, Response } from 'express';
import { authenticate } from './auth.service';

export async function login(req: Request, res: Response): Promise<void> {
  const { email, password } = req.body ?? {};

Password hashing with Argon2

security node argon2
by codesnips 3 tabs
php
<?php

namespace App\Models;

use App\Notifications\VerifyEmailNotification;
use Illuminate\Contracts\Auth\MustVerifyEmail;

Signed Email-Verification Links with Custom Laravel Notification and Signed Routes

laravel signed-urls email-verification
by codesnips 4 tabs
ruby
class DownloadsController < ApplicationController
  before_action :authenticate_user!

  def show
    report = current_account.reports.find(params[:report_id])
    authorize! :download, report

Signed, Expiring S3 Download URLs for Active Storage Attachments in Rails

rails active-storage s3
by codesnips 4 tabs
typescript
import { Injectable, signal, computed } from '@angular/core';

export interface CurrentUser {
  id: string;
  email: string;
  roles: string[];

Guarding a Lazy-Loaded Angular Admin Route with a Functional CanActivate Role Check

angular routing lazy-loading
by codesnips 3 tabs
php
<?php

namespace App\Http\Requests;

use Illuminate\Contracts\Validation\Validator;
use Illuminate\Foundation\Http\FormRequest;

Laravel Form Request Validation for Signup With Custom Rules and Error Responses

laravel validation form-request
by codesnips 3 tabs