agent-security-hardening
AFaffaan-m/ECC315k4,381 new stars in the last 7 days
Apply Rails security and multi-tenant safety practices including scoped queries, SSRF defenses, rate limiting, and tenant-scoped realtime updates. Use when implementing auth, webhooks, tenant boundaries, or security-sensitive endpoints.
Use for security-sensitive Rails work and tenant-boundary reviews. Patterns from Fizzy (path-based multi-tenant SaaS) and Campfire (single-tenant, bot APIs).
Model.find(params[:id]) in tenant-aware flows.head :forbidden) when access cannot be proven.One proven setup, not the only one (subdomains or a tenant gem work too). The identity/user split and scoped lookups below apply whichever you pick.
PATH_INFO into SCRIPT_NAME, loads the account, and wraps the request in Current.with_account(account). URL helpers stay tenant-correct automatically (including ActiveStorage and webhook payload URLs via script_name:).Identity; each request resolves Current.user = identity.users.find_by(account: Current.account). A valid session in account A can never act in account B. Apply the same resolution in ActionCable Connection#connect.Current setters cascade: assigning session resolves identity, assigning identity resolves user for the current account.disallow_account_scope) and redirect away from tenant-prefixed URLs.path: account.slug) when simultaneous multi-tenant login is supported.with_each_tenant). Serialize Current.account into job payloads (see rails-jobs).Rack::MockRequest; integration tests set default_url_options[:script_name] from the fixture account.Params choose which record within an already-authorized set — never establish access:
@card = Current.user.accessible_cards.find_by!(number: params[:card_id]) # access graph
@membership = Current.user.memberships.find_by!(room_id: params[:room_id]) # join model
@user = Current.account.users.find(params[:user_id]) # tenant association
has_secure_token :key on a Publication record), never internal IDs.blob → attachment → record.accessible_to?(user)); published content gets an explicit publicly_accessible? path.secure_compare, bound to the email via a verified pending-auth cookie.deny_bots + allow_bot_access only:).rate_limit to: 10, within: 15.minutes, only: :create,
with: -> { redirect_to ..., alert: "Try again in 15 minutes." }
last_active_at at most hourly).For webhooks, push endpoints, unfurling — any user-influenced URL:
Net::HTTP.new(host, port, ipaddr: resolved_ip)) to beat DNS rebinding.Sec-Fetch-Site verification (same-origin/same-site) on top of origin checks; roll out in report-only mode first, and append Sec-Fetch-Site to the Vary header.object_src :none, base_uri :none, frame_ancestors :self); use report-only + report_uri to validate before enforcing.X-Robots-Tag: none.card.editable_by?(user), or policy objects); controllers check and head :forbidden.allow_unauthenticated_access, ensure_can_administer) over scattered conditionals.37signals-style.ActionCable.server.remote_connections.where(current_user: user).disconnect(reconnect: false).Stripe::Webhook.construct_event), then re-fetch canonical state from the source API rather than trusting payload contents/ordering.User looked up by session without account scoping (identity/user conflation).AFaffaan-m/ECC315k4,381 new stars in the last 7 days
Audit the whole repo: find bugs, security holes and performance bottlenecks. Get a ranked report in plain English.
DIDietrichGebert/ponytail203k4,904 new stars in the last 7 days
GAgarrytan/gstack143k598 new stars in the last 7 days
ADaddyosmani/agent-skills122k1,667 new stars in the last 7 days
Harden code against the OWASP Top 10: input handling, authentication, sessions and dependencies.
ADaddyosmani/agent-skills122k1,667 new stars in the last 7 days
RUruvnet/RuView106k739 new stars in the last 7 days