NPM Package Registry returns HTTP400 for packages with single-character names #11470

Closed
opened 2025-11-02 09:38:47 -06:00 by GiteaMirror · 2 comments
Owner

Originally created by @TimberBro on GitHub (Aug 16, 2023).

Description

Steps to reproduce the issue:

  1. Create new token or find existing token with privileges to publish packages.
  2. Install NPM locally or use container.
  3. Run npm i q in environment from previous step
    It'll download https://www.npmjs.com/package/q/v/1.5.1 as your dependency and put it in ./node_modules/q/ directory.
  4. Run
    npm config set registry http://{gitea_url}:3000/api/packages/{username}/npm/
    npm config set -- '//{gitea_url}:3000/api/packages/{username}/npm/:_authToken' "{token}"
    
  5. Run npm publish ./node_modules/q/ to publish this package to Gitea.
  6. Error from NPM
    npm ERR! code E400
    npm ERR! 400 Bad Request - PUT http://{gitea_url}:3000/api/packages/{username}/npm/q - package name is invalid
    

Error from Gitea log

2023/08/16 23:11:16 ...ges/helper/helper.go:34:LogAndProcessError() [D] package name is invalid
2023/08/16 23:11:16 ...eb/routing/logger.go:102:func1() [I] router: completed PUT /api/packages/{username}/npm/q for 172.18.0.1:52196, 400 Bad Request in 19.4ms @ npm/npm.go:154(npm.UploadPackage)

Gitea Version

3b129aa

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

No response

Screenshots

No response

Git Version

2.40.1

Operating System

Ubuntu 22.04

How are you running Gitea?

Gitea running in docker.

Docker version:

vagrant@ubuntu:~$ docker version
Client:
 Version:           20.10.25
 API version:       1.41
 Go version:        go1.18.1
 Git commit:        20.10.25-0ubuntu1~22.04.1
 Built:             Fri Jul 14 21:58:09 2023
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server:
 Engine:
  Version:          20.10.25
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.18.1
  Git commit:       20.10.25-0ubuntu1~22.04.1
  Built:            Thu Jun 29 21:21:05 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.7.2
  GitCommit:
 runc:
  Version:          1.1.7-0ubuntu1~22.04.1
  GitCommit:
 docker-init:
  Version:          0.19.0
  GitCommit:

With docker-compose version:

vagrant@ubuntu:~$ docker-compose version
docker-compose version 1.29.2, build unknown
docker-py version: 5.0.3
CPython version: 3.10.12
OpenSSL version: OpenSSL 3.0.2 15 Mar 2022

Database

PostgreSQL

Originally created by @TimberBro on GitHub (Aug 16, 2023). ### Description Steps to reproduce the issue: 1. Create new token or find existing token with privileges to publish packages. 1. Install NPM locally or use container. 1. Run `npm i q` in environment from previous step It'll download `https://www.npmjs.com/package/q/v/1.5.1` as your dependency and put it in `./node_modules/q/` directory. 1. Run ``` npm config set registry http://{gitea_url}:3000/api/packages/{username}/npm/ npm config set -- '//{gitea_url}:3000/api/packages/{username}/npm/:_authToken' "{token}" ``` 1. Run `npm publish ./node_modules/q/` to publish this package to Gitea. 1. Error from NPM ``` npm ERR! code E400 npm ERR! 400 Bad Request - PUT http://{gitea_url}:3000/api/packages/{username}/npm/q - package name is invalid ``` Error from Gitea log ``` 2023/08/16 23:11:16 ...ges/helper/helper.go:34:LogAndProcessError() [D] package name is invalid 2023/08/16 23:11:16 ...eb/routing/logger.go:102:func1() [I] router: completed PUT /api/packages/{username}/npm/q for 172.18.0.1:52196, 400 Bad Request in 19.4ms @ npm/npm.go:154(npm.UploadPackage) ``` ### Gitea Version 3b129aa ### Can you reproduce the bug on the Gitea demo site? No ### Log Gist _No response_ ### Screenshots _No response_ ### Git Version 2.40.1 ### Operating System Ubuntu 22.04 ### How are you running Gitea? Gitea running in docker. Docker version: ``` vagrant@ubuntu:~$ docker version Client: Version: 20.10.25 API version: 1.41 Go version: go1.18.1 Git commit: 20.10.25-0ubuntu1~22.04.1 Built: Fri Jul 14 21:58:09 2023 OS/Arch: linux/amd64 Context: default Experimental: true Server: Engine: Version: 20.10.25 API version: 1.41 (minimum version 1.12) Go version: go1.18.1 Git commit: 20.10.25-0ubuntu1~22.04.1 Built: Thu Jun 29 21:21:05 2023 OS/Arch: linux/amd64 Experimental: false containerd: Version: 1.7.2 GitCommit: runc: Version: 1.1.7-0ubuntu1~22.04.1 GitCommit: docker-init: Version: 0.19.0 GitCommit: ``` With docker-compose version: ``` vagrant@ubuntu:~$ docker-compose version docker-compose version 1.29.2, build unknown docker-py version: 5.0.3 CPython version: 3.10.12 OpenSSL version: OpenSSL 3.0.2 15 Mar 2022 ``` ### Database PostgreSQL
GiteaMirror added the topic/packagestype/bug labels 2025-11-02 09:38:47 -06:00
Author
Owner

@TimberBro commented on GitHub (Aug 16, 2023):

Additional information:

  1. q is not the only package affected by the error.
    More examples:
    https://www.npmjs.com/package/d
    https://www.npmjs.com/package/@types/q

  2. I was able to find a method, that leads to this problem.
    For some reason, these names does not match against this regular expression:
    3b129aaa80/modules/packages/npm/creator.go (L37)

@TimberBro commented on GitHub (Aug 16, 2023): Additional information: 1. `q` is not the only package affected by the error. More examples: https://www.npmjs.com/package/d https://www.npmjs.com/package/@types/q 2. I was able to find a method, that leads to this problem. For some reason, these names does not match against this regular expression: https://github.com/go-gitea/gitea/blob/3b129aaa80e752dd2e0e007fc28c0db652af6b5c/modules/packages/npm/creator.go#L37
Author
Owner

@silverwind commented on GitHub (Aug 17, 2023):

Should check/test that regex. This package may be a good starting point:

https://github.com/npm/validate-npm-package-name

@silverwind commented on GitHub (Aug 17, 2023): Should check/test that regex. This package may be a good starting point: https://github.com/npm/validate-npm-package-name
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#11470