auditing

python
import os
import stat

for root, _dirs, files in os.walk('/etc'):
    for name in files:
        path = os.path.join(root, name)

Python security audit script for exposed risky filesystem state

python auditing host-security
by Kai Nakamura 1 tab
bash
#!/usr/bin/env bash
set -euo pipefail

find / -perm -4000 -type f 2>/dev/null | sort
sudo -l
find /etc/systemd/system -type f -writable 2>/dev/null

Linux privilege escalation checks for suspicious local state

privilege-escalation linux auditing
by Kai Nakamura 1 tab
ruby
class Current < ActiveSupport::CurrentAttributes
  attribute :user, :tenant, :request_id, :ip_address

  def user_display
    user&.email || "system"
  end

CurrentAttributes for Request-Scoped Context

rails activesupport currentattributes
by codesnips 4 tabs
java
package com.example.audit.config;

import java.util.Optional;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.domain.AuditorAware;

Automatic JPA Auditing in Spring Boot with @CreatedDate and @LastModifiedBy

spring-boot spring-data-jpa auditing
by codesnips 4 tabs
ruby
class CreateAuditLogs < ActiveRecord::Migration[7.1]
  def change
    create_table :audit_logs do |t|
      t.references :auditable, polymorphic: true, null: false
      t.references :user, null: true, foreign_key: true
      t.string :action, null: false

Rails Audit Log for Model Changes Using ActiveRecord Callbacks

rails activerecord callbacks
by codesnips 4 tabs
java
package com.example.docs.domain;

import jakarta.persistence.*;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;

Soft-Delete JPA Entities with Hibernate @SQLDelete and @Where Filtering

spring-boot hibernate jpa
by codesnips 3 tabs
ruby
class CreateAuditLogs < ActiveRecord::Migration[7.1]
  def change
    create_table :audit_logs do |t|
      t.references :auditable, polymorphic: true, null: false
      t.string :actor
      t.string :action, null: false

Audit Trail with JSON Diff (Minimal, Useful)

rails activerecord auditing
by codesnips 4 tabs
php
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

Recording an Audit Trail of Model Changes with a Laravel Observer

laravel eloquent observers
by codesnips 4 tabs
python
from django.db import models
from django.utils import timezone


class SoftDeleteQuerySet(models.QuerySet):
    def delete(self):

Soft-Delete in Django with a Custom Manager and QuerySet

django orm soft-delete
by codesnips 3 tabs
plaintext
model User {
  id        String    @id @default(uuid())
  email     String    @unique
  name      String
  posts     Post[]
  deletedAt DateTime?

Soft-Delete and Restore in TypeScript with a Prisma Repository and Migration

prisma postgres soft-delete
by codesnips 4 tabs