

Also from Kynth Studios


Also from Kynth Studios


Also from Kynth Studios
12345# JavaScript Broken Access Control (OWASP A01:2021)67This rule identifies and prevents broken access control vulnerabilities in JavaScript applications, focusing on both browser and Node.js environments, as defined in OWASP Top 10:2021-A01.89<rule>10name: javascript_broken_access_control11description: Detect and prevent broken access control patterns in JavaScript applications as defined in OWASP Top 10:2021-A011213actions:14 - type: enforce15 conditions:16 # Pattern 1: Detect Direct Reference to User-Supplied IDs (IDOR vulnerability)17 - pattern: "(?:req|request)\\.(?:params|query|body)\\.(?:id|userId|recordId)[^\\n]*?(?:findById|getById|find\\(|get\\()"18 message: "Potential Insecure Direct Object Reference (IDOR) vulnerability. User-supplied IDs should be validated against user permissions before database access."1920 # Pattern 2: Detect Missing Authorization Checks in Route Handlers21 - pattern: "(?:app|router)\\.(?:get|post|put|delete|patch)\\(['\"][^'\"]+['\"],\\s*(?:async)?\\s*\\(?(?:req|request),\\s*(?:res|response)(?:,[^\\)]+)?\\)?\\s*=>\\s*\\{[^\\}]*?\\}\\)"22 negative_pattern: "(?:isAuthenticated|isAuthorized|checkPermission|verifyAccess|auth\\.check|authenticate|authorize|userHasAccess|checkAuth|permissions\\.|requireAuth|requiresAuth|ensureAuth|\\bauth\\b|\\broles?\\b|\\bpermission\\b|\\baccess\\b)"23 message: "Route handler appears to be missing authorization checks. Implement proper access control to verify user permissions before processing requests."2425 # Pattern 3: Detect JWT Token Validation Issues26 - pattern: "(?:jwt|jsonwebtoken)\\.verify\\((?:[^,]+),\\s*['\"]((?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?)['\"]"27 message: "Hardcoded JWT secret detected. Store JWT secrets securely in environment variables or a configuration manager."2829 # Pattern 4: Detect Client-Side Authorization Checks30 - pattern: "if\\s*\\((?:user|currentUser)\\.(?:role|isAdmin|hasPermission|can[A-Z][a-zA-Z]+|is[A-Z][a-zA-Z]+)\\)\\s*\\{[^\\}]*?(?:fetch|axios|\\$\\.ajax|http\\.get|http\\.post)\\([^\\)]*?\\)"31 message: "Authorization logic implemented on client-side. Client-side authorization checks can be bypassed. Always enforce authorization on the server."3233 # Pattern 5: Detect Improper CORS Configuration34 - pattern: "(?:app\\.use\\(cors\\(\\{[^\\}]*?origin:\\s*['\"]\\*['\"])|Access-Control-Allow-Origin:\\s*['\"]\\*['\"]"35 message: "Wildcard CORS policy detected. This allows any domain to make cross-origin requests. Restrict CORS to specific trusted domains."3637 # Pattern 6: Detect Lack of Role Checks in Admin Functions38 - pattern: "(?:function|const)\\s+(?:admin|updateUser|deleteUser|createUser|updateRole|manageUsers|setPermission)[^\\{]*?\\{[^\\}]*?\\}"39 negative_pattern: "(?:role|permission|isAdmin|hasAccess|authorize|authenticate|auth\\.check|checkPermission|checkRole|verifyRole|ensureAdmin|adminOnly|adminRequired|requirePermission)"40 message: "Administrative function appears to be missing role or permission checks. Implement proper authorization checks to restrict access to administrative functions."4142 # Pattern 7: Detect Missing Login Rate Limiting43 - pattern: "(?:function|const)\\s+(?:login|signin|authenticate|auth)[^\\{]*?\\{[^\\}]*?(?:compare(?:Sync)?|check(?:Password)?|match(?:Password)?|verify(?:Password)?)[^\\}]*?\\}"44 negative_pattern: "(?:rate(?:Limit)?|throttle|limit|delay|cooldown|attempt|counter|maxTries|maxAttempts|lockout|timeout)"45 message: "Login function appears to be missing rate limiting. Implement rate limiting to prevent brute force attacks."4647 # Pattern 8: Detect Horizontal Privilege Escalation Vulnerability48 - pattern: "(?:findById|findOne|findByPk|get)\\((?:req|request)\\.(?:params|query|body)\\.(?:id|userId|accountId)\\)"49 negative_pattern: "(?:!=|!==|===|==)\\s*(?:req\\.user\\.id|req\\.userId|currentUser\\.id|user\\.id|session\\.userId)"50 message: "Potential horizontal privilege escalation vulnerability. Ensure the requested resource belongs to the authenticated user."5152 # Pattern 9: Detect Missing CSRF Protection53 - pattern: "(?:app|router)\\.(?:post|put|delete|patch)\\(['\"][^'\"]+['\"]"54 negative_pattern: "(?:csrf|xsrf|csurf|csrfProtection|antiForgery|csrfToken|csrfMiddleware)"55 message: "Route may be missing CSRF protection. Implement CSRF tokens for state-changing operations to prevent cross-site request forgery attacks."5657 # Pattern 10: Detect Bypassing Access Control with Path Traversal58 - pattern: "(?:fs|require)(?:\\.promises)?\\.(read|open|access|stat)(?:File|Sync)?\\([^\\)]*?(?:req|request)\\.(?:params|query|body|path)\\.[^\\)]*?\\)"59 negative_pattern: "(?:normalize|resolve|sanitize|validate|pathValidation|checkPath)"60 message: "Potential path traversal vulnerability in file access. Validate and sanitize user-supplied paths to prevent directory traversal attacks."6162 # Pattern 11: Detect Missing Authentication Middleware63 - pattern: "(?:new\\s+)?express\\(\\)|(?:import|require)\\(['\"]express['\"]\\)"64 negative_pattern: "(?:app\\.use\\((?:passport|auth|jwt|session|authenticate)|passport\\.authenticate|express-session|express-jwt|jsonwebtoken|requiresAuth|\\bauth\\b)"65 message: "Express application may be missing authentication middleware. Implement proper authentication to secure your application."6667 # Pattern 12: Detect Insecure Cookie Settings68 - pattern: "(?:res\\.cookie|cookie\\.set|cookies\\.set|document\\.cookie)\\([^\\)]*?\\)"69 negative_pattern: "(?:secure:\\s*true|httpOnly:\\s*true|sameSite|expires|maxAge)"70 message: "Cookies appear to be set without security attributes. Set the secure, httpOnly, and sameSite attributes for sensitive cookies."7172 # Pattern 13: Detect Hidden Form Fields for Access Control73 - pattern: "<input[^>]*?type=['\"]hidden['\"][^>]*?(?:(?:name|id)=['\"](?:admin|role|isAdmin|access|permission|privilege)['\"])"74 message: "Hidden form fields used for access control. Never rely on hidden form fields for access control decisions as they can be easily manipulated."7576 # Pattern 14: Detect Client-Side Access Control Routing77 - pattern: "(?:isAdmin|hasRole|hasPermission|userCan|canAccess)\\s*\\?\\s*<(?:Route|Navigate|Link|Redirect)"78 message: "Client-side conditional routing based on user roles detected. Always enforce access control on the server side as client-side checks can be bypassed."7980 # Pattern 15: Detect Access Control based on URL Parameters81 - pattern: "if\\s*\\((?:req|request)\\.(?:query|params)\\.(?:admin|mode|access|role|type)\\s*===?\\s*['\"](?:admin|true|1|superuser|manager)['\"]\\)"82 message: "Access control based on URL parameters detected. Never use request parameters for access control decisions as they can be easily manipulated."8384 - type: suggest85 message: |86 **JavaScript Access Control Best Practices:**8788 1. **Implement Server-Side Access Control**89 - Never rely solely on client-side access control90 - Use middleware to enforce authorization91 - Example Express.js middleware:92```javascript93 // Role-based access control middleware94 function requireRole(role) {95 return (req, res, next) => {96 if (!req.user) {97 return res.status(401).json({ error: 'Authentication required' });98 }99100 if (!req.user.roles.includes(role)) {101 return res.status(403).json({ error: 'Insufficient permissions' });102 }103104 next();105 };106 }107108 // Usage in routes109 app.get('/admin/users', requireRole('admin'), (req, res) => {110 // Handle admin-only route111 });112```113114 2. **Implement Proper Authentication**115 - Use established authentication libraries116 - Implement multi-factor authentication for sensitive operations117 - Example with Passport.js:118```javascript119 const passport = require('passport');120 const JwtStrategy = require('passport-jwt').Strategy;121122 passport.use(new JwtStrategy(jwtOptions, async (payload, done) => {123 try {124 const user = await User.findById(payload.sub);125 if (!user) {126 return done(null, false);127 }128 return done(null, user);129 } catch (error) {130 return done(error, false);131 }132 }));133134 // Protect routes135 app.get('/protected',136 passport.authenticate('jwt', { session: false }),137 (req, res) => {138 res.json({ success: true });139 }140 );141```142143 3. **Implement Proper Authorization**144 - Use attribute or role-based access control145 - Check permissions for each protected resource146 - Example:147```javascript148 // Permission-based middleware149 function checkPermission(permission) {150 return async (req, res, next) => {151 try {152 // Get user permissions from database153 const userPermissions = await getUserPermissions(req.user.id);154155 if (!userPermissions.includes(permission)) {156 return res.status(403).json({ error: 'Permission denied' });157 }158159 next();160 } catch (error) {161 next(error);162 }163 };164 }165166 // Usage167 app.post('/articles',168 authenticate,169 checkPermission('article:create'),170 (req, res) => {171 // Create article172 }173 );174```175176 4. **Protect Against Insecure Direct Object References (IDOR)**177 - Validate that the requested resource belongs to the user178 - Use indirect references or access control lists179 - Example:180```javascript181 app.get('/documents/:id', authenticate, async (req, res) => {182 try {183 const document = await Document.findById(req.params.id);184185 // Check if document exists186 if (!document) {187 return res.status(404).json({ error: 'Document not found' });188 }189190 // Check if user owns the document or has access191 if (document.userId !== req.user.id &&192 !(await userHasAccess(req.user.id, document.id))) {193 return res.status(403).json({ error: 'Access denied' });194 }195196 res.json(document);197 } catch (error) {198 res.status(500).json({ error: error.message });199 }200 });201```202203 5. **Implement Proper CORS Configuration**204 - Never use wildcard (*) in production205 - Whitelist specific trusted origins206 - Example:207```javascript208 const cors = require('cors');209210 const corsOptions = {211 origin: ['https://trusted-app.com', 'https://admin.trusted-app.com'],212 methods: ['GET', 'POST', 'PUT', 'DELETE'],213 allowedHeaders: ['Content-Type', 'Authorization'],214 credentials: true,215 maxAge: 86400 // 24 hours216 };217218 app.use(cors(corsOptions));219```220221 6. **Implement CSRF Protection**222 - Use anti-CSRF tokens for state-changing operations223 - Validate the token on the server224 - Example with csurf:225```javascript226 const csrf = require('csurf');227228 // Setup CSRF protection229 const csrfProtection = csrf({ cookie: true });230231 // Generate CSRF token232 app.get('/form', csrfProtection, (req, res) => {233 res.render('form', { csrfToken: req.csrfToken() });234 });235236 // Validate CSRF token237 app.post('/process', csrfProtection, (req, res) => {238 // Process the request239 });240```241242 7. **Implement Secure Cookie Settings**243 - Set secure, httpOnly, and sameSite attributes244 - Use appropriate expiration times245 - Example:246```javascript247 res.cookie('sessionId', sessionId, {248 httpOnly: true, // Prevents JavaScript access249 secure: true, // Only sent over HTTPS250 sameSite: 'strict', // Prevents CSRF attacks251 maxAge: 3600000, // 1 hour252 path: '/',253 domain: 'yourdomain.com'254 });255```256257 8. **Implement Rate Limiting**258 - Apply rate limiting to authentication endpoints259 - Prevent brute force attacks260 - Example with express-rate-limit:261```javascript262 const rateLimit = require('express-rate-limit');263264 const loginLimiter = rateLimit({265 windowMs: 15 * 60 * 1000, // 15 minutes266 max: 5, // 5 attempts per window267 standardHeaders: true,268 legacyHeaders: false,269 message: {270 error: 'Too many login attempts, please try again after 15 minutes'271 }272 });273274 app.post('/login', loginLimiter, (req, res) => {275 // Handle login276 });277```278279 9. **Implement Proper Session Management**280 - Use secure session management libraries281 - Rotate session IDs after login282 - Example:283```javascript284 const session = require('express-session');285286 app.use(session({287 secret: process.env.SESSION_SECRET,288 resave: false,289 saveUninitialized: false,290 cookie: {291 secure: true,292 httpOnly: true,293 sameSite: 'strict',294 maxAge: 3600000 // 1 hour295 }296 }));297298 app.post('/login', (req, res) => {299 // Authenticate user300301 // Regenerate session to prevent session fixation302 req.session.regenerate((err) => {303 if (err) {304 return res.status(500).json({ error: 'Failed to create session' });305 }306307 // Set authenticated user in session308 req.session.userId = user.id;309 req.session.authenticated = true;310311 res.json({ success: true });312 });313 });314```315316 10. **Implement Proper Access Control for APIs**317 - Use OAuth 2.0 or JWT for API authentication318 - Implement proper scope checking319 - Example with JWT:320```javascript321 const jwt = require('jsonwebtoken');322323 function verifyToken(req, res, next) {324 const token = req.headers.authorization?.split(' ')[1];325326 if (!token) {327 return res.status(401).json({ error: 'No token provided' });328 }329330 try {331 const decoded = jwt.verify(token, process.env.JWT_SECRET);332 req.user = decoded;333334 // Check if token has required scope335 if (req.route.path === '/api/admin' && !decoded.scopes.includes('admin')) {336 return res.status(403).json({ error: 'Insufficient scope' });337 }338339 next();340 } catch (error) {341 return res.status(401).json({ error: 'Invalid token' });342 }343 }344345 // Protect API routes346 app.get('/api/users', verifyToken, (req, res) => {347 // Handle request348 });349```350351 - type: validate352 conditions:353 # Check 1: Authentication middleware354 - pattern: "(?:app\\.use\\((?:authenticate|auth\\.initialize|passport\\.initialize|express-session|jwt))|(?:passport\\.authenticate\\()|(?:auth\\.required)"355 message: "Authentication middleware is implemented correctly."356357 # Check 2: Authorization checks358 - pattern: "(?:isAuthorized|checkPermission|hasRole|requireRole|checkAccess|canAccess|checkAuth|roleRequired|requireScope)"359 message: "Authorization checks are implemented."360361 # Check 3: CSRF protection362 - pattern: "(?:csrf|csurf|csrfProtection|antiForgery|csrfToken)"363 message: "CSRF protection is implemented."364365 # Check 4: Secure cookies366 - pattern: "(?:cookie|cookies).*(?:secure:\\s*true|httpOnly:\\s*true|sameSite)"367 message: "Secure cookie settings are configured."368369 # Check 5: CORS configuration370 - pattern: "cors\\(\\{[^\\}]*?origin:\\s*\\[[^\\]]+\\]"371 message: "CORS is configured with specific origins rather than wildcards."372373metadata:374 priority: high375 version: 1.0376 tags:377 - security378 - javascript379 - access-control380 - authorization381 - authentication382 - owasp383 - language:javascript384 - language:typescript385 - framework:express386 - framework:react387 - framework:angular388 - framework:vue389 - category:security390 - subcategory:access-control391 - standard:owasp-top10392 - risk:a01-broken-access-control393 references:394 - "https://owasp.org/Top10/A01_2021-Broken_Access_Control/"395 - "https://cheatsheetseries.owasp.org/cheatsheets/Access_Control_Cheat_Sheet.html"396 - "https://cheatsheetseries.owasp.org/cheatsheets/Authorization_Cheat_Sheet.html"397 - "https://nodejs.org/en/security/best-practices/"398 - "https://expressjs.com/en/advanced/best-practice-security.html"399 - "https://auth0.com/blog/node-js-and-express-tutorial-building-and-securing-restful-apis/"400</rule>401
One repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| ivangrynenko/cursorrules.cursor/rules/cursor-rules.mdc · 86 | Cursor rules | teststylearchgit+2 | 77/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/behat-steps.mdc · 86 | Cursor rules | lint-formatstyleperformanceagent-behaviour | 42/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/php-drupal-development-standards.mdc · 86 | Cursor rules | no sections | 34/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/python-insecure-design.mdc · 86 | Cursor rules | no sections | 40/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/python-cryptographic-failures.mdc · 86 | Cursor rules | security | 40/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/python-injection.mdc · 86 | Cursor rules | styledo-not | 51/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/node-dependencies.mdc · 86 | Cursor rules | no sections | 16/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/behat-ai-guide.mdc · 86 | Cursor rules | testtesting-strategydo-not | 45/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/new-pull-request.mdc · 86 | Cursor rules | archtesting-strategygitsecurity+3 | 58/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/accessibility-standards.mdc · 86 | Cursor rules | ui | 44/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/api-standards.mdc · 86 | Cursor rules | api | 44/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/build-optimization.mdc · 86 | Cursor rules | build | 48/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/code-generation-standards.mdc · 86 | Cursor rules | lint-formatstyletypesdocs | 52/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/confluence-editing-standards.mdc · 86 | Cursor rules | stylearchsecuritydeployment | 60/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/debugging-standards.mdc · 86 | Cursor rules | no sections | 30/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/docker-compose-standards.mdc · 86 | Cursor rules | style | 62/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/drupal-authentication-failures.mdc · 86 | Cursor rules | security | 48/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/drupal-broken-access-control.mdc · 86 | Cursor rules | stylesecurity | 52/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/drupal-cryptographic-failures.mdc · 86 | Cursor rules | security | 48/100 | 14 days ago | |
| ivangrynenko/cursorrules.cursor/rules/drupal-database-standards.mdc · 86 | Cursor rules | database | 30/100 | 14 days ago |
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| hiromaily/go-crypto-wallet.cursor/rules/typescript.mdc · 126 | Cursor rules | setupbuildtestlint-format+6 | 100/100 | 14 days ago | |
| TechSquidTV/Hermes.cursor/rules/10-hermes-api.mdc · 45 | Cursor rules | testlint-formatstylearch+5 | 100/100 | 14 days ago | |
| langflow-ai/langflow.cursor/rules/docs_development.mdc · 153k | Cursor rules | setupbuildtestlint-format+7 | 97/100 | 14 days ago | |
| TechSquidTV/Hermes.cursor/rules/20-hermes-api-tests.mdc · 45 | Cursor rules | teststyletesting-strategysecurity+3 | 97/100 | 14 days ago | |
| skillrecordings/egghead-next.cursor/rules/gh-task-plan.mdc · 1.4k | Cursor rules | teststylearchtypes+2 | 96/100 | 14 days ago | |
| skillrecordings/egghead-next.cursor/rules/project-update-rules.mdc · 1.4k | Cursor rules | buildtestlint-formatstyle+7 | 96/100 | 14 days ago | |
| skillrecordings/egghead-next.cursor/rules/project-update-user-rules.mdc · 1.4k | Cursor rules | buildtestlint-formatstyle+7 | 96/100 | 14 days ago | |
| hiromaily/go-crypto-wallet.cursor/rules/proto.mdc · 126 | Cursor rules | buildlint-formatstylearch+3 | 96/100 | 14 days ago |
A badge carrying the measured quality of the strongest agent config file in this repository, out of 100. It reads from this index every time somebody loads your page, so it changes when the measurement changes and there is nothing to keep up to date. Free, no account, and the value is not something you or we can set by hand.
[](https://rulestack.kynth.studio/configs/ivangrynenko-cursorrules-cursor-rules-javascript-broken-access-control)Would rather not hotlink us? Every badge is also served in shields.io’s endpoint schema, so shields renders the image and your readers never talk to our domain:
Published by Toolproof, the masthead over this index and eight others. The method behind the number is at toolproof.kynth.studio/methodology, and the whole thing is readable as JSON with no key at /api.