]> git.proxmox.com Git - pve-http-server.git/log
pve-http-server.git
7 months agohttp: support Content-Encoding=deflate
Maximiliano Sandoval [Thu, 18 Apr 2024 09:16:35 +0000 (11:16 +0200)]
http: support Content-Encoding=deflate

Add support for compressing the body of responses with
`Content-Encoding: deflate` following [RFC9110]. Note that in this
context `deflate` is actually a "zlib" data format as defined in
[RFC1950].

To preserve the current behavior we prefer `Content-Encoding: gzip`
whenever `gzip` is listed as one of the encodings in the
`Accept-Encoding` header and the data should be compressed.

[RFC9110] https://www.rfc-editor.org/rfc/rfc9110#name-deflate-coding
[RFC1950] https://www.rfc-editor.org/rfc/rfc1950

Suggested-by: Lukas Wagner <l.wagner@proxmox.com>
Signed-off-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
Tested-by: Folke Gleumes <f.gleumes@proxmox.com>
7 months agobump version to 5.0.6
Thomas Lamprecht [Tue, 26 Mar 2024 08:16:53 +0000 (09:16 +0100)]
bump version to 5.0.6

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
9 months agoaccess control: avoid "uninitialized value" warning if using IP ranges
Friedrich Weber [Wed, 24 Jan 2024 11:38:56 +0000 (12:38 +0100)]
access control: avoid "uninitialized value" warning if using IP ranges

ALLOW_FROM/DENY_FROM accept any syntax understood by Net::IP. However,
if an IP range like "10.1.1.1-10.1.1.3" is configured, a confusing
Perl warning is printed to the syslog on a match:

  Use of uninitialized value in concatenation (.) or string at [...]

The reason is that we use Net::IP::prefix to prepare a debug message,
but this returns undef if a range was specified. To avoid the warning,
use Net::IP::print to obtain a string representation instead.

Signed-off-by: Friedrich Weber <f.weber@proxmox.com>
12 months agobump version to 5.0.5
Fabian Grünbichler [Fri, 3 Nov 2023 11:06:55 +0000 (12:06 +0100)]
bump version to 5.0.5

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
16 months agofix #4859: properly configure TLSv1.3 only mode
Fabian Grünbichler [Wed, 19 Jul 2023 09:15:55 +0000 (11:15 +0200)]
fix #4859: properly configure TLSv1.3 only mode

set_min/max_proto_version is recommended upstream nowadays, and it seems to be
required for some reason if *only* TLS v1.3 is supposed to be enabled.

querying via get_options gives us the union of
- system-wide openssl defaults
- our internal SSL defaults
- flags configured by the user via /etc/default/pveproxy

note that by default only 1.2 and 1.3 are enabled in the first place, so
disabling either leaves a single version being set as min and max.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
16 months agobump version to 5.0.4
Thomas Lamprecht [Mon, 3 Jul 2023 07:39:50 +0000 (09:39 +0200)]
bump version to 5.0.4

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
16 months agofix #4802: reduce CA lookups while proxying
Fabian Grünbichler [Mon, 3 Jul 2023 07:18:51 +0000 (09:18 +0200)]
fix #4802: reduce CA lookups while proxying

OpenSSL as packaged in Debian bookworm now ships a compat symlink for
the "combined" CA certificates file (CAfile) as managed by
update-ca-certificates. This symlink is in addition to the CApath
one that has been around for a file. The new symlink in turn gets
picked up by openssl-using code that uses the default values for the
trust store.

Every TLS context initialization now reads the full combined file,
even if no TLS is actually employed on a connection. We do such an
initialization for every proxied connection (where our HTTP server is
the client).

By specifying an explicit CA path (that is identical to the default
one), the old behaviour of looking up each CA certificate
individually iff needed is enabled again.

For an API endpoint where HTTP request handling is the bottle neck
(as opposed to the actual API handler), this improves performance of
proxied requests to be back in line with unproxied ones handled
directly by the unprivileged daemon. For all proxied requests, CPU
usage is decreased as well.

The default CAfile and CApath contain the same certificates, so there
should be no change in trusted certificates. Additionally,
certificate fingerprints are pinned in this context and verified
against the cache of pinned fingerprints.

Reported-by: Roland Kletzing <roland.kletzing@cybercon.de>
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
16 months agoavoid AnyEvent::AIO to fix CPU spinning if pure-perl lib is installed
Dominik Csapak [Mon, 3 Jul 2023 06:39:55 +0000 (08:39 +0200)]
avoid AnyEvent::AIO to fix CPU spinning if pure-perl lib is installed

when installing AnyEvent::AIO (by the package libanyevent-aio-perl),
the worker forks of our daemons using AnyEvent would consume 100% cpu
cycles while trying to do an epoll_wait which no one read from. It
was not really clear which part of the code set that fd up.

Reading the documentation of the related perl modules, it became
clear that the issue was with AnyEvent::IO. By default this uses
AnyEvent::AIO (if installed) which in turn uses IO::AIO which
explicitly says it uses pthreads and is not really fork compatible
(which we rely heavy upon).

It seems that IO::AIO sets up some fds with epoll in the END handler
of it's library (or earlier, but sends data to it in the END
handler), so that when using 'exit' instead of 'POSIX::_exit' (which
we do in PVE::Daemon) creates the observed behavior.

Interestingly we did not use any of AnyEvent::IO's functionality, so
we can safely remove it. Even if we would have used  it in the past,
without AnyEvent::AIO the IO would not have been async anyway (the
pure perl impl doesn't do async IO). My best guess is that we wanted
to use it, but noticed that we can't, and forgot to remove the use
statement.  (This is indicated by a comment that says aio_load is not
async unless IO::AIO is used)

This only occurs now, since bookworm is the first debian release to
package the library.

if we ever wanted to use AnyEvent::AIO, there are probably two other
ways that could fix it:
* replace our 'exit()' calls with 'POSIX::_exit()', which seems to
  fix it, but other side effects are currently unknown
* use 'IO::AIO::reinit()' after forking, which also seems to fix it,
  but perldoc says it 'is not an operation supported by any
  standards, but happens to work on GNU/LINUX and some newer BSD
  systems'

With this fix, one can safely install 'libanyevent-aio-perl' and
'libperl-languageserver-perl' (the only user of it AFAICS) on a
Proxmox VE or Proxmox Mail Gateway system.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
17 months agobump version to 5.0.3
Thomas Lamprecht [Fri, 9 Jun 2023 16:58:12 +0000 (18:58 +0200)]
bump version to 5.0.3

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
17 months agoproxy request: handle missing content-type header
Stoiko Ivanov [Fri, 9 Jun 2023 16:11:45 +0000 (18:11 +0200)]
proxy request: handle missing content-type header

In case the actual request-body is empty it seems not Content-Type
header is set by browsers.

Tested on a vm with stopping and starting a container via GUI
(/api2/extjs/nodes/<nodename>/lxc/<vmid>/status/stop)

fixes f398a3d94bb5c798e1e1ea91113cd76648dd79eb

Reported-by: Friedrich Weber <f.weber@proxmox.com>
Reported-by: Fiona Ebner <f.ebner@proxmox.com>
Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
17 months agobump version to 5.0.2
Wolfgang Bumiller [Wed, 7 Jun 2023 11:21:29 +0000 (13:21 +0200)]
bump version to 5.0.2

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
17 months agobump pve-common dependency to 8.0.2
Wolfgang Bumiller [Wed, 7 Jun 2023 11:18:17 +0000 (13:18 +0200)]
bump pve-common dependency to 8.0.2

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
17 months agouse proper arrays for array parameter
Dominik Csapak [Tue, 6 Jun 2023 13:08:49 +0000 (15:08 +0200)]
use proper arrays for array parameter

since there is no other way to get an array parameter when using
x-www-form-urlencoded content type

the previous format with \0 separated strings (known as '-alist' format)
should not be used anymore (in favor of the now supported arrays)

Acked-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
17 months agoproxy request: forward json content type and parameters
Dominik Csapak [Tue, 6 Jun 2023 13:08:48 +0000 (15:08 +0200)]
proxy request: forward json content type and parameters

instead of always trying to encode them as x-www-form-urlencoded

Acked-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
17 months agoformatter/bootstrap: set SameSite attr of auth cookie to 'strict'
Max Carrara [Wed, 15 Mar 2023 16:26:29 +0000 (17:26 +0100)]
formatter/bootstrap: set SameSite attr of auth cookie to 'strict'

This prohibits the cookie from being sent along in cross-site
sub-requests or when the user navigates to a different site.

Signed-off-by: Max Carrara <m.carrara@proxmox.com>
17 months agomultiline parameter style nit fix
Thomas Lamprecht [Tue, 6 Jun 2023 15:12:50 +0000 (17:12 +0200)]
multiline parameter style nit fix

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
17 months agobump version to 5.0.1
Thomas Lamprecht [Sat, 3 Jun 2023 13:15:51 +0000 (15:15 +0200)]
bump version to 5.0.1

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
17 months agofix regression in api/html (bootstrap) viewer
Dominik Csapak [Tue, 30 May 2023 11:56:25 +0000 (13:56 +0200)]
fix regression in api/html (bootstrap) viewer

Since v5.13, URI::Escape handles the 'unsafe characters' parameter
differently than before, i.e., enforcing what is documented [0]:

 The set is specified as a string that can be used in a regular
 expression character class (between [ ]).

So, the leading/trailing [] were never supposed to be there.

Note that since v5.15 we could also pass a qr// regex object.

[0]: https://github.com/libwww-perl/URI/commit/1a4ed66802f26c15cccd66c0b5d489cf9f3e3ba4

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
 [ T: Add details and mention regex objects ]
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
18 months agobump version to 5.0.0
Thomas Lamprecht [Wed, 17 May 2023 05:33:43 +0000 (07:33 +0200)]
bump version to 5.0.0

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
18 months agod/control: add debhelper misc:depends auto-variable
Thomas Lamprecht [Wed, 17 May 2023 05:33:12 +0000 (07:33 +0200)]
d/control: add debhelper misc:depends auto-variable

and wrap-and-sort -tkn

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
18 months agofixup! buildsys: add sbuild target for convenience
Thomas Lamprecht [Wed, 17 May 2023 05:31:38 +0000 (07:31 +0200)]
fixup! buildsys: add sbuild target for convenience

18 months agobuildsys: derive upload dist automatically
Thomas Lamprecht [Wed, 17 May 2023 05:28:28 +0000 (07:28 +0200)]
buildsys: derive upload dist automatically

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
18 months agobuildsys: add sbuild target for convenience
Thomas Lamprecht [Wed, 17 May 2023 05:28:22 +0000 (07:28 +0200)]
buildsys: add sbuild target for convenience

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
18 months agobuildsys: split out build dir generation and add DSC target
Thomas Lamprecht [Wed, 17 May 2023 05:24:01 +0000 (07:24 +0200)]
buildsys: split out build dir generation and add DSC target

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
18 months agod/control: raise standards version compliance to 4.6.2
Thomas Lamprecht [Wed, 17 May 2023 05:23:15 +0000 (07:23 +0200)]
d/control: raise standards version compliance to 4.6.2

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
18 months agomakefile: convert to use simple parenthesis
Thomas Lamprecht [Wed, 17 May 2023 05:22:11 +0000 (07:22 +0200)]
makefile: convert to use simple parenthesis

and drop the `find` invocation in the clean target, just fix your
editor.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
18 months agod/control: define compat level via build-depends and raise to 13
Thomas Lamprecht [Tue, 16 May 2023 16:23:09 +0000 (18:23 +0200)]
d/control: define compat level via build-depends and raise to 13

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
19 months agoreplace junior semicolon with actual one
Thomas Lamprecht [Fri, 14 Apr 2023 14:38:13 +0000 (16:38 +0200)]
replace junior semicolon with actual one

commas can be used in two ways, quoting Perl Best Practices (PBP):

> The comma actually has two distinct roles in Perl. In a scalar
> context, it is (as those former C programmers expect) a sequencing
> operator: “do this, then do that”. But in a list context, such as
> the argument list of a print, the comma is a list separator, not
> technically an operator at all.
-- PBP, page 69

And the separating variant is called a "junior semicolon" by PBP.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
19 months agobump version to 4.2-3
Thomas Lamprecht [Fri, 14 Apr 2023 14:27:21 +0000 (16:27 +0200)]
bump version to 4.2-3

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
19 months agoexplicitly disallow tmpfilename parameter in query URL
Thomas Lamprecht [Fri, 14 Apr 2023 14:09:07 +0000 (16:09 +0200)]
explicitly disallow tmpfilename parameter in query URL

This is an internal parameter and we pass the actual internal one
around via the $reqstate variable, so avoid confusion and return a
clear error if a POST request sets this query parameter.

Reported-by: Friedrich Weber <f.weber@proxmox.com>
Suggested-by: Friedrich Weber <f.weber@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
19 months agofile upload: don't calculate MD5, log file name instead
Matthias Heiserer [Wed, 12 Apr 2023 14:22:48 +0000 (16:22 +0200)]
file upload: don't calculate MD5, log file name instead

Until now, we calculated the MD5 hash of any uploaded file during the
upload, regardless of whether the user chose to provide a hash sum
and algorithm. The hash was only logged in the syslog.

As the user can provide a hash algorithm and a checksum when
uploading a file, which gets automatically checked (after the
upload), this is not needed anymore. Instead, the file name is
logged.

Depending on the speed of the network and the cpu, upload speed or
CPU usage might improve: All tests were made by uploading a 3.6GB iso
from the PVE host to a local VM. First line is with md5, second
without.

no networklimit
multipart upload complete (size: 3826831360B time: 20.310s rate: 179.69MiB/s md5sum: 8c651682056205967d530697c98d98c3)
multipart upload complete (size: 3826831360B time: 16.169s rate: 225.72MiB/s filename: ubuntu-22.04.1-desktop-amd64.iso)

125MB/s network
In this test, pveproxy worker used x % CPU during the upload. As you can see, the reduced CPU usage is noticable in slower networks.
~75% CPU: multipart upload complete (size: 3826831360B time: 30.764s rate: 118.63MiB/s md5sum: 8c651682056205967d530697c98d98c3)
~60% CPU: multipart upload complete (size: 3826831360B time: 30.763s rate: 118.64MiB/s filename: ubuntu-22.04.1-desktop-amd64.iso)

qemu64 cpu, no network limit
multipart upload complete (size: 3826831360B time: 46.113s rate: 79.14MiB/s md5sum: 8c651682056205967d530697c98d98c3)
multipart upload complete (size: 3826831360B time: 41.492s rate: 87.96MiB/s filename: ubuntu-22.04.1-desktop-amd64.iso)

qemu64, -aes, 1 core, 0.7 cpu
multipart upload complete (size: 3826831360B time: 79.875s rate: 45.69MiB/s md5sum: 8c651682056205967d530697c98d98c3)
multipart upload complete (size: 3826831360B time: 66.364s rate: 54.99MiB/s filename: ubuntu-22.04.1-desktop-amd64.iso)

Signed-off-by: Matthias Heiserer <m.heiserer@proxmox.com>
 [ T: reflow text-width and slightly add to subject ]
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
19 months agobump version to 4.2-2
Thomas Lamprecht [Tue, 11 Apr 2023 12:44:07 +0000 (14:44 +0200)]
bump version to 4.2-2

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
19 months agomultipart upload: properly parse file parts without Content-Type
Friedrich Weber [Tue, 11 Apr 2023 12:19:47 +0000 (14:19 +0200)]
multipart upload: properly parse file parts without Content-Type

As reported in the forum, multipart requests are parsed incorrectly if
the file part header contains *only* Content-Disposition, but no other
fields (in particular, no Content-Type). As a result, uploaded files
are mangled: In most cases, an additional carriage return and line
feed (\r\n) is prepended to the file contents.

As an example, consider the following file part (with explicit \r\n
for clarity):

  Content-Disposition: form-data; name=...; filename=...\r\n
  Content-Type: application/x-iso9660-image\r\n
  \r\n
  file contents...

The current parsing code for file parts roughly works as follows:

1) Consume the Content-Disposition field including the trailing \r\n
2) Consume and ignore everything up to and including the next \r\n\r\n
3) Read the file contents

This works fine in the example above. However, it has a bug in case
Content-Disposition is the *only* header field:

  Content-Disposition: form-data; name=...; filename=...\r\n
  \r\n
  file contents...

Now, step 1 already consumes the first half of the \r\n\r\n sequence
that marks the end of the part headers. As a result, step 3 starts
reading the file at a wrong offset:

- If the remaining contents of the read buffer (currently sized 16KiB)
  contain \r\n\r\n, step 2 consumes everything up to and including
  this marker and step 3 starts reading file contents there. As a
  result, the uploaded file is truncated at its beginning.
- Otherwise, step 2 is a noop and step 3 considers the remaining
  second half of the \r\n\r\n marker to be part of the file contents.
  As a result, the uploaded file is prepended with an extra \r\n.

To fix this, modify step 1 to *not* consume the trailing \r\n. This
keeps the \r\n\r\n marker intact, no matter whether additional header
fields are present or not.

Fixes: 3e3faddb4a3792557351f1a6e9f2685e4713eb24
Link: https://forum.proxmox.com/threads/125411/
Signed-off-by: Friedrich Weber <f.weber@proxmox.com>
20 months agobump version to 4.2-1
Thomas Lamprecht [Thu, 16 Mar 2023 15:58:06 +0000 (16:58 +0100)]
bump version to 4.2-1

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
20 months agoheader processing: add comments
Fabian Grünbichler [Tue, 7 Mar 2023 09:41:41 +0000 (10:41 +0100)]
header processing: add comments

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
20 months agoheader processing: explicit return 0
Fabian Grünbichler [Tue, 7 Mar 2023 09:41:25 +0000 (10:41 +0100)]
header processing: explicit return 0

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
20 months agoheader processing: style fixups
Fabian Grünbichler [Tue, 7 Mar 2023 09:40:53 +0000 (10:40 +0100)]
header processing: style fixups

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
20 months agofix whitespace
Max Carrara [Fri, 3 Mar 2023 17:29:51 +0000 (18:29 +0100)]
fix whitespace

Signed-off-by: Max Carrara <m.carrara@proxmox.com>
20 months agofix #4494: redirect HTTP to HTTPS
Max Carrara [Fri, 3 Mar 2023 17:29:50 +0000 (18:29 +0100)]
fix #4494: redirect HTTP to HTTPS

Allow HTTP connections up until the request's header has been
parsed and processed. If no TLS handshake has been completed
beforehand, the server now responds with either a
'301 Moved Permanently' or a '308 Permanent Redirect' as noted in the
MDN web docs[1].

This is done after the header was parsed; for the redirect to work,
the `Host` header field of the request is used to create the
`Location` field of the response. This makes redirections independent
of how the server is accessed (e.g. via IP, localhost, FQDN, ...)
possible.

Upon redirection the client is immediately disconnected; otherwise,
they would have to wait for the connection to time out until
they may reconnect via TLS again.

[1] https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/301

Signed-off-by: Max Carrara <m.carrara@proxmox.com>
20 months agoheader processing: factor out auth and request handling
Max Carrara [Fri, 3 Mar 2023 17:29:49 +0000 (18:29 +0100)]
header processing: factor out auth and request handling

The part responsible for authentication and subsequent request
handling is moved into the new `authenticate_and_handle_request`
subroutine.

If `authenticate_and_handle_request` doesn't return early, it returns
`1` for further control flow purposes.

Some minor things are formatted or renamed for readability's sake.

Signed-off-by: Max Carrara <m.carrara@proxmox.com>
20 months agoheader processing: extract into separate subroutine
Max Carrara [Fri, 3 Mar 2023 17:29:48 +0000 (18:29 +0100)]
header processing: extract into separate subroutine

The code concerned with processing the request's header in
`unshift_read_header` is moved into the new `process_header`
subroutine.

If `process_header` doesn't return early, it returns `1` for further
control flow purposes.

Some minor things are formatted or renamed for readability's sake.

Signed-off-by: Max Carrara <m.carrara@proxmox.com>
20 months agobump version to 4.1-6
Thomas Lamprecht [Mon, 6 Mar 2023 12:40:01 +0000 (13:40 +0100)]
bump version to 4.1-6

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
20 months agomultipart upload: code cleanup/reuse
Thomas Lamprecht [Mon, 6 Mar 2023 12:01:16 +0000 (13:01 +0100)]
multipart upload: code cleanup/reuse

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
20 months agomultipart upload: remove ignore-whitespace flag from regex
John Hollowell [Fri, 18 Nov 2022 01:39:11 +0000 (01:39 +0000)]
multipart upload: remove ignore-whitespace flag from regex

makes it rather harder to read and now unnecessary

Signed-off-by: John Hollowell <jhollowe@johnhollowell.com>
 [ T: resolve merge conflict and add commit message ]
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
20 months agofix #4344: http-server: ignore unused multipart headers
John Hollowell [Fri, 18 Nov 2022 01:39:10 +0000 (01:39 +0000)]
fix #4344: http-server: ignore unused multipart headers

In commit 0fbcbc2 ("fix #3990: multipart upload: rework to fix
uploading small files") a breaking change was added which now
requires the file's multipart part to have a `Content-Type` even
though the content type is never used. It is just included to consume
those bytes so phase 2 (dumping the file contents into the file) can
continue.

Avoid this overly strict and unused requirement.

Signed-off-by: John Hollowell <jhollowe@johnhollowell.com>
 [ T: resolve merge conflict, add telling commit message ]
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
23 months agomultipart upload: ignore trailing-newline requirement from spec
Matthias Heiserer [Mon, 12 Dec 2022 15:07:56 +0000 (16:07 +0100)]
multipart upload: ignore trailing-newline requirement from spec

Allow upload without trailing newline, even though this is not
compliant with RFC 1521.

RFC 1521 mandates that the close-delimiter ends in a newline:
'close-delimiter := "--" boundary "--" CRLF'

However, some software (e.g. postman) sends their request without a
trailing newline, which resulted in failing uploads.

Signed-off-by: Matthias Heiserer <m.heiserer@proxmox.com>
Reviewed-by: Daniel Tschlatscher <d.tschlatscher@proxmox.com>
Tested-by:  Daniel Tschlatscher <d.tschlatscher@proxmox.com>
23 months agofix multipart upload: ignore additional headers
Matthias Heiserer [Mon, 12 Dec 2022 15:07:55 +0000 (16:07 +0100)]
fix multipart upload: ignore additional headers

Reported in the forum:
https://forum.proxmox.com/threads/image-upload-fails-after-upgrading-from-7-1-to-7-3.119051/#post-516517

When additional headers existed in the request body, the upload failed.
With this patch, all additional headers get ignored.

Example: The following upload would fail because no headers were
expected after Content-Disposition.

```
--EPIHyQJFC5ftgoXHMe8-Jc6E7FqA4oMb0QBfOTz
Content-Disposition: form-data; name="content"
Content-Type: text/plain; charset=ISO-8859-1

iso
```
would fail. These headers now also get ignored, as we don't use them.

Also, upload now works when the Content-Disposition header isn't the
first, i.e.:
```
--XVH95dt1-A3J8mWiLCmHCW4roSC7-gBntjATBy--
Content-Type: text/plain; charset=ISO-8859-1
Content-Disposition: form-data; name="content"
```

Fixed upload was tested using
* Curl
* GUI
* Apache HttpClient 5

Signed-off-by: Matthias Heiserer <m.heiserer@proxmox.com>
Reviewed-by: Daniel Tschlatscher <d.tschlatscher@proxmox.com>
Tested-by:  Daniel Tschlatscher <d.tschlatscher@proxmox.com>
23 months agomultipart upload: fix upload of files starting with newlines
Matthias Heiserer [Mon, 12 Dec 2022 15:07:54 +0000 (16:07 +0100)]
multipart upload: fix upload of files starting with newlines

Currently, if a file starts with a newline, it gets removed and the
upload succeeds (provided no hash is given).

Signed-off-by: Matthias Heiserer <m.heiserer@proxmox.com>
Reviewed-by: Daniel Tschlatscher <d.tschlatscher@proxmox.com>
Tested-by:  Daniel Tschlatscher <d.tschlatscher@proxmox.com>
2 years agobump version to 4.1-5
Thomas Lamprecht [Mon, 7 Nov 2022 15:44:25 +0000 (16:44 +0100)]
bump version to 4.1-5

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2 years agoremove dead code 'parse_content_disposition'
Dominik Csapak [Mon, 7 Nov 2022 15:07:50 +0000 (16:07 +0100)]
remove dead code 'parse_content_disposition'

our recent change to parsing the upload headers made that code
unnecessary, so remove it

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2 years agoupload: re-allow white space in filenames
Dominik Csapak [Mon, 7 Nov 2022 15:07:49 +0000 (16:07 +0100)]
upload: re-allow white space in filenames

Some fields (e.g. filename) can contain spaces, but our 'trim'
function, would only return the value until the first whitespace
character instead of removing leading/trailing white space. This lead
to passing the wrong filename to the API call (e.g. 'foo' instead of
'foo (1).iso'), which would then reject it because of the 'wrong'
extension.

Fix this by just using the battle proven trim from pve-common.

Fixes: 0fbcbc2 ("fix #3990: multipart upload: rework to fix uploading small files")
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2 years agobump version to 4.1-4
Thomas Lamprecht [Thu, 29 Sep 2022 12:37:08 +0000 (14:37 +0200)]
bump version to 4.1-4

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2 years agounshift_read_header: minor code style improvement
Thomas Lamprecht [Thu, 29 Sep 2022 15:03:59 +0000 (17:03 +0200)]
unshift_read_header: minor code style improvement

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2 years agomultipart upload: report duration with millisecond precision in syslog
Thomas Lamprecht [Thu, 29 Sep 2022 15:03:34 +0000 (17:03 +0200)]
multipart upload: report duration with millisecond precision in syslog

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2 years agomultipart upload: avoid some extra lines and general code style fixes
Thomas Lamprecht [Thu, 29 Sep 2022 14:34:18 +0000 (16:34 +0200)]
multipart upload: avoid some extra lines and general code style fixes

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2 years agomultipart upload: avoid code duplication in writing data to tmp file
Thomas Lamprecht [Thu, 29 Sep 2022 14:31:51 +0000 (16:31 +0200)]
multipart upload: avoid code duplication in writing data to tmp file

Separate the flow into first getting the length and data reference
and only then handle writing/digest in a common way

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2 years agomultipart upload: factor out content-disposition extraction
Thomas Lamprecht [Thu, 29 Sep 2022 14:29:25 +0000 (16:29 +0200)]
multipart upload: factor out content-disposition extraction

and improve the boundary variable helper name by adding a _re postfix
and using snake case everywhere.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2 years agomultipart upload: drop unused variables
Thomas Lamprecht [Thu, 29 Sep 2022 14:26:13 +0000 (16:26 +0200)]
multipart upload: drop unused variables

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2 years agofix #3990: multipart upload: rework to fix uploading small files
Matthias Heiserer [Fri, 13 May 2022 13:49:00 +0000 (15:49 +0200)]
fix #3990: multipart upload: rework to fix uploading small files

== The problem
Upload of files smaller than ~16kb failed.
This was because the code assumed that it would be called
several times, and each time would do a certain action.
When the whole file was in the buffer, this failed because
the function would try parssing the first part in the payload and
then return, instead of parsing the rest of the available data.

== Why not just modifying the current code a bit?
The code had a lot of nested control statements and a
non-intuitive control flow (phase 0->2->1->1->1 and so on).

The way the phases and buffer content were checked made it
rather difficult to just fix a few lines.

== What was changed
* Part headers are parsed with a single regex line each,
 which improves code readability.

* Parsing the content is done in order, so even if the whole data is in the buffer,
 it can be read in one go. Files of arbitrary sizes can be uploaded.

== Tested with
* Uploaded 0B, 1B, 14KB, 16KB, 1GB, 10GB, 20GB files

* Tested with all checksums and without

* Tested on firefox, chromium, and pvesh

I didn't do any fuzzing or automated upload testing.

== Drawbacks & Potential issues
* Part headers are hardcoded, adding new ones requries modifying this file

== does not fix
* upload can still time out

Signed-off-by: Matthias Heiserer <m.heiserer@proxmox.com>
Tested-by: Daniel Tschlatscher <d.tschlatscher@proxmox.com>
2 years agoAnyEvent: whitespace fix
Matthias Heiserer [Fri, 13 May 2022 13:48:59 +0000 (15:48 +0200)]
AnyEvent: whitespace fix

and remove unnecessary parentheses.

Signed-off-by: Matthias Heiserer <m.heiserer@proxmox.com>
2 years agoacknowledge content-disposition header
Daniel Tschlatscher [Wed, 7 Sep 2022 08:56:28 +0000 (10:56 +0200)]
acknowledge content-disposition header

Acknowledging the Content-Disposition header makes it possible for the
backend to tell the browser whether a file should be downloaded,
rather than displayed inline, and what it's default name should be.

Signed-off-by: Daniel Tschlatscher <d.tschlatscher@proxmox.com>
2 years agorequest: add missing early return to complete error check
Thomas Lamprecht [Mon, 4 Jul 2022 09:08:16 +0000 (11:08 +0200)]
request: add missing early return to complete error check

While $self->error will immediately send out a 4xx or 5xx response
anyhow its still good to cover against possible side effects (e.g.,
from future code in that branch) on the server and return directly.

Note that this is mostly for completeness sake, we already have
another check that covers this one for relevant cases in commit
580d540ea907ba15f64379c5bb69ecf1a49a875f.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2 years agobump version to 4.1-3
Thomas Lamprecht [Sat, 2 Jul 2022 07:16:29 +0000 (09:16 +0200)]
bump version to 4.1-3

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2 years agorequests: assert that theres no @ in the URLs authority
Thomas Lamprecht [Sat, 2 Jul 2022 06:27:02 +0000 (08:27 +0200)]
requests: assert that theres no @ in the URLs authority

We don't expect any userinfo in the authority and t o avoid that this
allows some leverage in doing weird things later its better to error
out early on such requests.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Originally-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2 years agopass through streaming: only allow from privileged local pvedaemon
Thomas Lamprecht [Sat, 2 Jul 2022 05:59:50 +0000 (07:59 +0200)]
pass through streaming: only allow from privileged local pvedaemon

Ensures that no external request can control streaming on proxying
requests as safety net for when we'd have another issue in the
request handling part.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Originally-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2 years agoproxy request: assert that API url starts with a slash
Thomas Lamprecht [Sat, 2 Jul 2022 05:56:12 +0000 (07:56 +0200)]
proxy request: assert that API url starts with a slash

We implicitly assume that to be the case when assembling the target
URL, so assert it explicitly as it's user controlled input.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Originally-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2 years agoresponse: avoid linefeeds in response status
Thomas Lamprecht [Fri, 1 Jul 2022 09:32:54 +0000 (11:32 +0200)]
response: avoid linefeeds in response status

basically only possible to trigger with chromium based browsers
(chrome, edge, opera) but besides those having the biggest usage
currently its not that nice in any way.

Users could inject headers in their response, which isn't really that
bad itself, as they won't really do anything at least for sane
browsers that don't allow setting third party cookies by default
(unlike again, chrome), in which case one can create huge cookies
that then trigger the max header size check on requests, DOS'ing an
user's access to a PVE interface if they can get them to visit a
malicious site (a clear cooki actione would allow visiting it again)

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Reported-by: STAR Labs <info@starlabs.sg>
2 years agoresponse: improve no content comment
Thomas Lamprecht [Fri, 1 Jul 2022 08:14:31 +0000 (10:14 +0200)]
response: improve no content comment

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2 years agobump version to 4.1-2
Thomas Lamprecht [Tue, 17 May 2022 14:40:33 +0000 (16:40 +0200)]
bump version to 4.1-2

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2 years agohtml formatter: encode href attributes
Fabian Grünbichler [Tue, 17 May 2022 12:48:27 +0000 (14:48 +0200)]
html formatter: encode href attributes

these contain untrusted data, so treat them accordingly.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2 years agotls: log failure to apply TLS 1.3 ciphers
Fabian Grünbichler [Tue, 18 Jan 2022 11:35:49 +0000 (12:35 +0100)]
tls: log failure to apply TLS 1.3 ciphers

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2 years agobump version to 4.1-1
Thomas Lamprecht [Thu, 13 Jan 2022 12:32:47 +0000 (13:32 +0100)]
bump version to 4.1-1

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2 years agofix #3789: allow disabling TLS v1.2/v1.3
Fabian Grünbichler [Fri, 17 Dec 2021 12:57:29 +0000 (13:57 +0100)]
fix #3789: allow disabling TLS v1.2/v1.3

SSL 2 and 3 are already disabled by default by us, and TLS 1.1 and below
are disabled by default on Debian systems.

requires corresponding patch in pve-manager to have an effect.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Tested-by: Stoiko Ivanov <s.ivanov@proxmox.com>
Reviewed-by: Stoiko Ivanov <s.ivanov@proxmox.com>
2 years agofix #3745: allow overriding TLS key location
Fabian Grünbichler [Fri, 17 Dec 2021 12:57:28 +0000 (13:57 +0100)]
fix #3745: allow overriding TLS key location

when using a custom pveproxy certificate. actual handling is done in
pve-manager.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Tested-by: Stoiko Ivanov <s.ivanov@proxmox.com>
Reviewed-by: Stoiko Ivanov <s.ivanov@proxmox.com>
2 years agofix #3790: allow setting TLS 1.3 cipher suites
Fabian Grünbichler [Fri, 17 Dec 2021 12:57:27 +0000 (13:57 +0100)]
fix #3790: allow setting TLS 1.3 cipher suites

like the TLS <= 1.2 cipher list, but needs a different option since the
format and values are incompatible. AnyEvent doesn't yet handle this
directly like the cipher list, so set it directly on the context.

requires corresponding patch in pve-manager (which reads the config, and
passes relevant parts back to the API server).

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Tested-by: Stoiko Ivanov <s.ivanov@proxmox.com>
Reviewed-by: Stoiko Ivanov <s.ivanov@proxmox.com>
2 years agofix #3807: don't attempt response on closed handle
Fabian Grünbichler [Wed, 29 Dec 2021 11:15:34 +0000 (12:15 +0100)]
fix #3807: don't attempt response on closed handle

if a client closes the connection while the API server is
waiting/stalling here, the handle will disappear, and sending a response
is no longer possible.

(this issue is only cosmetic, but if such clients are a regular
occurrence it might get quite noisy in the logs)

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2 years agosmall indentation and code cleanup
Thomas Lamprecht [Thu, 13 Jan 2022 12:09:44 +0000 (13:09 +0100)]
small indentation and code cleanup

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2 years agoavoid warning if request params do not exists
Thomas Lamprecht [Thu, 13 Jan 2022 12:09:11 +0000 (13:09 +0100)]
avoid warning if request params do not exists

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2 years agoWS: guard disconnect block check properly
Fabian Grünbichler [Fri, 17 Dec 2021 09:55:34 +0000 (10:55 +0100)]
WS: guard disconnect block check properly

if the WS gets disconnected without any data having been sent first,
wbuf (and thus `length $wbuf`) is undef. the actual length of the buffer
is not relevant here anyway, just the fact that it's non-empty - so
avoid the undef warning by dropping the unnecessary comparison.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2 years agobump version to 4.0-4
Thomas Lamprecht [Wed, 24 Nov 2021 17:14:57 +0000 (18:14 +0100)]
bump version to 4.0-4

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2 years agohttp: split and sort use statements
Thomas Lamprecht [Wed, 24 Nov 2021 17:13:14 +0000 (18:13 +0100)]
http: split and sort use statements

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2 years agodownload-stream: allow the api call to set the content-encoding
Dominik Csapak [Wed, 24 Nov 2021 14:47:47 +0000 (15:47 +0100)]
download-stream: allow the api call to set the content-encoding

this is useful if we want to pipe the output of a program e.g. through gzip

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
3 years agoconstructor: split TLS flags to separate lines
Thomas Lamprecht [Tue, 16 Nov 2021 06:34:01 +0000 (07:34 +0100)]
constructor: split TLS flags to separate lines

easier to grasp what's actually being set..

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
3 years agofix #3724: disable TLS renegotiation
Stoiko Ivanov [Mon, 15 Nov 2021 20:50:43 +0000 (21:50 +0100)]
fix #3724: disable TLS renegotiation

The issue is probably not critical and best addressed by not running
the perl API servers in an exposed environment or when this needs to
be done by installing a reverse proxy in front of them.

The DOS potential of the perl daemons is limited more by the limited
number of parallel workers (and the memory constraints of starting
more of them), than by the CPU cycles wasted on TLS renegotiation.

Still disabling TLS renegotiation should show very little downside:
* it was removed in TLS 1.3 for security reasons
* it was the way nginx addressed this issue [1].
* we do not use client certificate authentication

Tested by running `openssl s_client -no_tls1_3 -connect 192.0.2.1:8006`
and issuing a `HEAD / HTTP/1.1\nR\n`
with and without the patch.

[1] 70bd187c4c386d82d6e4d180e0db84f361d1be02 at
    https://github.com/nginx/nginx (although that code adapted to
    the various changes in openssl API over the years)
Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
3 years agowebproxy: handle unflushed write buffer
Fabian Grünbichler [Thu, 11 Nov 2021 14:07:13 +0000 (15:07 +0100)]
webproxy: handle unflushed write buffer

for proxied requests, we usually tear down the proxy connection
immediately when closing the source connection. this is not the correct
course of action for bulk one-way data streams that are proxied, where
the source connection might be closed, but the proxy connection might
still have data in the write buffer that needs to be written out.

push_shutdown already handles this case (closing the socket/FH after it
has been fully drained).

one example for such a proxied data stream is the 'migrate' data for a
remote migration, which gets proxied over a websocket connection.
terminating the proxied connection early makes the target VM crash for
obvious reasons.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
3 years agobuildsys: change upload dist to bullseye
Thomas Lamprecht [Mon, 4 Oct 2021 08:21:12 +0000 (10:21 +0200)]
buildsys: change upload dist to bullseye

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
3 years agobump version to 4.0-3
Thomas Lamprecht [Mon, 4 Oct 2021 08:18:38 +0000 (10:18 +0200)]
bump version to 4.0-3

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
3 years agod/control: wrap-and-sort -tkn
Thomas Lamprecht [Mon, 4 Oct 2021 08:13:57 +0000 (10:13 +0200)]
d/control: wrap-and-sort -tkn

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
3 years agod/control: break libpve-storage-perl (<< 7.0-11)
Thomas Lamprecht [Mon, 4 Oct 2021 08:13:21 +0000 (10:13 +0200)]
d/control: break libpve-storage-perl (<< 7.0-11)

as only newer version cleanup temp files on their own.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
3 years agoanyevent: move unlink from http-server to endpoint
Lorenz Stechauner [Tue, 31 Aug 2021 10:16:28 +0000 (12:16 +0200)]
anyevent: move unlink from http-server to endpoint

any uploaded file has to be deleted by the corrosponding
endpoint. the file upload was only used by the 'upload to
storage' feature in pve.

this change allows the endpoint to delete the file itself,
making the old and racey`sleep 1` (waiting until the worker
has opened the file) obsolete.

this change breaks all pve-manager versions, in which the
worker does not unlink the temp file itself.

Signed-off-by: Lorenz Stechauner <l.stechauner@proxmox.com>
3 years agobump version to 4.0-2
Fabian Grünbichler [Tue, 18 May 2021 08:19:37 +0000 (10:19 +0200)]
bump version to 4.0-2

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
3 years agowebsocket: add note about compat removal
Fabian Grünbichler [Tue, 18 May 2021 07:25:15 +0000 (09:25 +0200)]
websocket: add note about compat removal

this major release still needs to have an incompatible client, the next
one can drop setting a protocol client-side, and the one after that can
remove the protocol handling on the server side.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
3 years agoAnyEvent/websocket_proxy: drop handling of websocket subprotocols
Dominik Csapak [Mon, 17 May 2021 13:07:35 +0000 (15:07 +0200)]
AnyEvent/websocket_proxy: drop handling of websocket subprotocols

We do not support any, and we only ever send binary frames, so drop
trying to parse the header.

For compatibility with current clients (novnc, pve-xtermjs), we have
to reply with the protocols it sent.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
3 years agoAnyEvent/websocket_proxy: remove 'base64' handling
Dominik Csapak [Mon, 17 May 2021 13:07:34 +0000 (15:07 +0200)]
AnyEvent/websocket_proxy: remove 'base64' handling

novnc does not support this anymore since 2015, and neither does
our xtermjs client. it is also not listed in IANAs list of websocket
protocols [0].

so simply drop it and only send out binary frames and don't decode text frames

0: https://www.iana.org/assignments/websocket/websocket.xml#subprotocol-name

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
3 years agobump version to 4.0-1
Thomas Lamprecht [Fri, 14 May 2021 14:38:26 +0000 (16:38 +0200)]
bump version to 4.0-1

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
3 years agobuildsys: split packaging and source build-systems
Thomas Lamprecht [Fri, 14 May 2021 14:37:17 +0000 (16:37 +0200)]
buildsys: split packaging and source build-systems

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
3 years agod/control: drop unzip from build depends
Thomas Lamprecht [Fri, 14 May 2021 13:13:06 +0000 (15:13 +0200)]
d/control: drop unzip from build depends

is actually not required since quite a bit, i.e., commit
88628fd1414cc87c782083734a80b39aa4b806cc from my last bootstrapping
effort in 2019.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
3 years agod/control: improve package description
Thomas Lamprecht [Fri, 14 May 2021 13:12:05 +0000 (15:12 +0200)]
d/control: improve package description

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
3 years agod/control: bump compat level to 12
Thomas Lamprecht [Fri, 14 May 2021 13:11:46 +0000 (15:11 +0200)]
d/control: bump compat level to 12

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
3 years agod/copyright: update years
Thomas Lamprecht [Fri, 14 May 2021 13:11:22 +0000 (15:11 +0200)]
d/copyright: update years

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>