verdaccio: Unable to View Packages as an Authenticated User on Versions > 6.0.5
Your environment
- verdaccio version: v6.1.3
- node version: v22.13.1
- package manager: npm: 10.9.2 - /usr/local/bin/npm
- os: Linux 6.8 Alpine Linux
- platform: docker
- reverse proxy: yes
Describe the bug
I am unable to view packages as an authenticated user.
Steps to reproduce
- Spin up a Docker container using the following configuration file:
services:
verdaccio:
image: verdaccio/verdaccio:6.1.3
container_name: verdaccio
restart: unless-stopped
cpus: 1.0
mem_limit: 1G
memswap_limit: -1
ports:
- "0.0.0.0:4873:4873"
networks:
- verdaccio_network
volumes:
- ./config.yml:/verdaccio/conf/config.yaml:ro
- ./htpasswd:/verdaccio/storage/htpasswd:ro
- verdaccio_data:/verdaccio
networks:
verdaccio_network:
volumes:
verdaccio_data:
- Access the Verdaccio web dashboard.
- Login
- Try looking for or searching for any packages
Expected behavior
I should be able to view packages as an authenticated user.
Screenshots, Verdaccio server log, package manager log
verdaccio | info --- config file - /verdaccio/conf/config.yaml
verdaccio | info --- plugin @verdaccio/local-storage successfully loaded (storage)
verdaccio | info --- using htpasswd file: /verdaccio/storage/htpasswd
verdaccio | info --- plugin verdaccio-htpasswd successfully loaded (authentication)
verdaccio | info --- plugin @verdaccio/ui-theme successfully loaded (theme)
verdaccio | warn --- http address - http://[REDACTED_IP]:4873/ - verdaccio/6.1.3
verdaccio | info <-- [REDACTED_IP] requested 'GET /'
verdaccio | http <-- 200, user: null([REDACTED_IP] via [REDACTED_IP]), req: 'GET /', bytes: 0/0
verdaccio | http <-- 200, user: null([REDACTED_IP] via [REDACTED_IP]), req: 'GET /', bytes: 0/525
verdaccio | info <-- [REDACTED_IP] requested 'GET /-/verdaccio/data/packages'
verdaccio | http <-- 200, user: null([REDACTED_IP] via [REDACTED_IP]), req: 'GET /-/verdaccio/data/packages', bytes: 0/0
verdaccio | http <-- 304, user: null([REDACTED_IP] via [REDACTED_IP]), req: 'GET /-/verdaccio/data/packages', bytes: 0/0
verdaccio | info <-- [REDACTED_IP] requested 'POST /-/verdaccio/sec/login'
verdaccio | http <-- 200, user: null([REDACTED_IP] via [REDACTED_IP]), req: 'POST /-/verdaccio/sec/login', bytes: 98/0
verdaccio | http <-- 200, user: admin([REDACTED_IP] via [REDACTED_IP]), req: 'POST /-/verdaccio/sec/login', bytes: 98/341
verdaccio | info <-- [REDACTED_IP] requested 'GET /-/verdaccio/data/packages'
verdaccio | http <-- 200, user: null([REDACTED_IP] via [REDACTED_IP]), req: 'GET /-/verdaccio/data/packages', bytes: 0/0
verdaccio | http <-- 304, user: null([REDACTED_IP] via [REDACTED_IP]), req: 'GET /-/verdaccio/data/packages', bytes: 0/0
verdaccio | info <-- [REDACTED_IP] requested 'GET /'
verdaccio | http <-- 200, user: null([REDACTED_IP] via [REDACTED_IP]), req: 'GET /', bytes: 0/0
verdaccio | http <-- 200, user: null([REDACTED_IP] via [REDACTED_IP]), req: 'GET /', bytes: 0/525
verdaccio | info <-- [REDACTED_IP] requested 'GET /-/verdaccio/data/packages'
verdaccio | http <-- 200, user: null([REDACTED_IP] via [REDACTED_IP]), req: 'GET /-/verdaccio/data/packages', bytes: 0/0
verdaccio | http <-- 304, user: null([REDACTED_IP] via [REDACTED_IP]), req: 'GET /-/verdaccio/data/packages', bytes: 0/0
verdaccio | info <-- [REDACTED_IP] requested 'GET /-/verdaccio/data/search/form'
verdaccio | http <-- 200, user: null([REDACTED_IP] via [REDACTED_IP]), req: 'GET /-/verdaccio/data/search/form', bytes: 0/0
verdaccio | http <-- 304, user: null([REDACTED_IP] via [REDACTED_IP]), req: 'GET /-/verdaccio/data/search/form', bytes: 0/0
Configuration file
storage: /verdaccio/storage/data
plugins: /verdaccio/plugins
web:
login: true
auth:
htpasswd:
file: /verdaccio/storage/htpasswd
max_users: -1
packages:
"@*/*":
access: $authenticated
publish: $authenticated
unpublish: $authenticated
"**":
access: $authenticated
publish: $authenticated
unpublish: $authenticated
Contribute to Verdaccio
- I’m willing to fix this bug 🥇
About this issue
- Original URL
- State: open
- Created a year ago
- Reactions: 2
- Comments: 16 (4 by maintainers)
TLDR
It’s a regression of #5090 in src/api/web/index.ts
AI to the rescue
I extracted the diff between 6.0.5 and 6.1.4 and asked Cursor + Claude 4 Sonnet to deep dive into it. Here’s the result after 45 sec of thinking and about 1 min of further analysis.
@juanpicado not sure how much of https://github.com/verdaccio/verdaccio/blob/556bc9747bfd8e8bf31e84852d4cc0fc89f6ce78/src/api/web/index.ts you want to revert but at least we have the root cause identified 😀
My prompt
The diff introduced a new issue: the authentication isn’t working properly anymore. when a logged in user tries to select packages, the user isn’t passed on to the get request. the use id appears as “null” in the http log.
Do a deep dive into the diff to identify what introduced this issue. You can read any other file of the repo if this helps.
Claude’s answer
Based on my deep analysis of the diff, I’ve identified the root cause of the authentication issue. Here’s what happened:
The Problem
The authentication issue was introduced by a critical change in middleware setup in the web interface. Let me break down the specific changes:
Before the diff (working):
After the diff (broken):
Root Cause Analysis
Middleware Replacement: The diff replaced
webUIJWTmiddleware()withapiJWTmiddleware()and moved it inside therenderWebMiddlewarecall.Different Middleware Behaviors:
webUIJWTmiddleware()is designed for browser-based web UI requests (handles web sessions, cookies, etc.)apiJWTmiddleware()is designed for API calls (handles Bearer tokens, basic auth, etc.)Authentication Flow Mismatch: Web browsers typically send session cookies or web-specific tokens, but the API middleware expects different authentication methods.
User Context Lost: When the web interface makes requests to get packages, the
req.remote_userisnullbecause the API middleware isn’t properly processing the web authentication tokens that browsers send.The Specific Issue
In
packages/web/src/api/package.ts, there’s this logic:When
remoteUserisnull(due to the middleware not properly extracting the user from web requests), the authentication check fails even though the user is logged in.The Fix
The issue should be resolved by reverting to use
webUIJWTmiddleware()for web interface requests instead ofapiJWTmiddleware(), or ensuring that the API middleware can properly handle web authentication tokens.The change essentially broke the separation between web UI authentication (for browsers) and API authentication (for programmatic access), causing logged-in web users to appear as
nullin the system.Conclusion
Amazing. The agent certainly could have proposed a PR, too. Crazy times.
@mbtools I already did 😉
Confirmation:
@mbtools The secret is 32 characters long.
No, it is not good idea as you says, but help for guidance, only suggested as comparison purposes.
I added to my
docker-compose.ymlfile:I also updated my config file:
And recreated the container. I now get the following logs:
I don’t have any issues with file permissions (thankfully). That’s confirmed when I switch back to an older Verdaccio version and things work.