Skip to content

auth/hardcoded-role regex misses quoted role comparisons (most common pattern) #490

Description

@ajianaz

Problem

The auth/hardcoded-role security pattern only matches unquoted role comparisons, missing the most common real-world pattern with quoted strings:

Current Regex

regex: r"(?i)role\s*==\s*(?:admin|super|root)|is_admin\s*==\s*True",

What It Misses

Pattern Detected? Note
role == admin ✅ Bareword (rare outside Ruby/PHP)
role == "admin" ❌ Most common — JS, TS, Python, Go
user.role == "admin" ❌ Property access + quotes
role === "admin" ❌ Strict equality (JS/TS)
role == "super" ❌
if role == "root": ... ❌ Python

Fix

Add optional quotes and property access:

regex: r#"(?i)(?:\.?\w+\.)*role\s*[=]{2,3}\s*["']?(?:admin|super|root)["']?|is_admin\s*==\s*True"#,

Related

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions