You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The AdminJSOptionsassets configuration allows customization of styles, scripts, and core scripts for AdminJS. However, the withProtectedRoutesHandler function in the affected version fails to handle assets correctly. The issues are twofold:
Function Ignored: If admin.options?.assets is a function, its returned values are not processed.
Improper Flattening: Objects such as coreScripts in admin.options?.assets are incorrectly flattened using Array.prototype.flat(), causing privilege escalation by unintentionally granting unauthenticated API access.
Exploitation Scenario
Consider the following AdminJSOptions configuration:
This causes objects like coreScripts to bypass route protection.
Proposed Fix
The updated code ensures proper handling of admin.options?.assets, respects functions, and validates only string-based assets:
importAdminJS,{CurrentAdmin,RouterasAdminRouter}from'adminjs';import{FastifyInstance}from'fastify';exportconstwithProtectedRoutesHandler=(fastifyApp: FastifyInstance,admin: AdminJS,): void=>{const{ rootPath }=admin.options;fastifyApp.addHook('preHandler',async(request,reply)=>{constbuildComponentRoute=AdminRouter.routes.find((r)=>r.action==='bundleComponents',)?.path;letAdminOptionsAssets=admin.options?.assets??{};if(typeofAdminOptionsAssets==='function')AdminOptionsAssets=awaitAdminOptionsAssets(request.session.get('adminUser')asCurrentAdmin);constassets=[
...AdminRouter.assets.map((a)=>a.path),
...Object.values(AdminOptionsAssets).flat(),];if(assets.find((a)=>typeofa==='string'&&request.url.match(a))){return;}elseif(buildComponentRoute&&request.url.match(buildComponentRoute)){return;}elseif(!request.url.startsWith(rootPath)||request.session.get('adminUser')||// these routes don't need authenticationrequest.url.startsWith(admin.options.loginPath)||request.url.startsWith(admin.options.logoutPath)){return;}else{// If the redirection is caused by API call to some action just redirect to resourceconst[redirectTo]=request.url.split('/actions');request.session.redirectTo=redirectTo.includes(`${rootPath}/api`)
? rootPath
: redirectTo;returnreply.redirect(admin.options.loginPath);}});};
Fix Highlights
Function Respect: Functions in assets are executed and their return values are processed.
Validation: Only string-based paths are included in assets, preventing objects like coreScripts from being validated.
Secure Access: Unauthenticated API calls are blocked, ensuring route protection.
Impact
The fix eliminates privilege escalation risks by:
Validating assets paths correctly.
Blocking unauthenticated access to protected API routes.
The text was updated successfully, but these errors were encountered:
Elyasnz
changed the title
Security Issue in AdminJS Fastify Integration: Privilege Escalation in Asset Handling
BUG: Security Issue in AdminJS Fastify Integration: Privilege Escalation in Asset Handling
Dec 25, 2024
Affected Version
This vulnerability is specific to AdminJS Fastify v4.1.3, identified in this commit. For relevant documentation, see adminjs-options.interface.ts and core-scripts.interface.ts.
Problem Overview
The
AdminJSOptions
assets
configuration allows customization of styles, scripts, and core scripts for AdminJS. However, thewithProtectedRoutesHandler
function in the affected version fails to handleassets
correctly. The issues are twofold:admin.options?.assets
is a function, its returned values are not processed.coreScripts
inadmin.options?.assets
are incorrectly flattened usingArray.prototype.flat()
, causing privilege escalation by unintentionally granting unauthenticated API access.Exploitation Scenario
Consider the following
AdminJSOptions
configuration:and the affected code with some logs
When making an API request, such as:
curl -X POST 'http://localhost:8000/admin/api/resources/users/records/23/show'
The logs show that the
coreScripts
object is incorrectly treated as valid:Here,
1
indicates the request was validated, granting access without proper authentication.Root Cause
In the
preHandler
hook ofwithProtectedRoutesHandler
, theassets
array includes improperly flattened values:This causes objects like
coreScripts
to bypass route protection.Proposed Fix
The updated code ensures proper handling of
admin.options?.assets
, respects functions, and validates only string-based assets:Fix Highlights
Impact
The fix eliminates privilege escalation risks by:
The text was updated successfully, but these errors were encountered: