Validate the path during ConfigFile upload

The IBM management console usecase - ConfigFile upload was allowing
to create or modify any file at the BMC when the path url is given
as below.
PUT https://${bmc}/ibm/v1/Host/ConfigFiles/../../../../../<any file under root dir> --data-binary "junk data"

This commit adds validation to the "path" variable after the "ConfigFiles/"
in the url - so that only the ConfigFiles are created or modified.

The filename validation includes:
  Restrict the maximum filename length to 20 characters
  Restrict the allowed charaters to [A-Za-z0-9-]

The minimum size of the file allowed is 100 bytes
The maximum size of the file allowed is 500KB
Maximum total size of the ConfigFile directory at BMC file system allowed is 10MB

Tested by:

  1. PUT https://${bmc}/ibm/v1/Host/ConfigFiles/../../../../../etc/p2 --data-binary "some data"
     Bad Request

  2. PUT https://${bmc}/ibm/v1/Host/ConfigFiles/../../../etc/p2 --data-binary "some data"
     Bad Request

  3. PUT https://${bmc}/ibm/v1/Host/ConfigFiles/../etc/p2 --data-binary "some data"
     Bad Request

  4. PUT https://${bmc}/ibm/v1/Host/ConfigFiles/etc/p2 --data-binary "some data"
     {
       "Description": "Error while creating the file"
     }

  5. PUT https://${bmc}/ibm/v1/Host/ConfigFiles/mydir/p2 --data-binary "some data"
     {
       "Description": "Error while creating the file"
     }

  6. PUT https://${bmc}/ibm/v1/Host/ConfigFiles/ --data-binary "some data"
     Not Found

  7. PUT https://${bmc}/ibm/v1/Host/ConfigFiles --data-binary "some data"
     Method Not Allowed

  8. PUT https://${bmc}/ibm/v1/Host/ConfigFiles/p2/../p2 --data-binary "some data"
     Bad Request

  9. PUT https://${bmc}/ibm/v1/Host/ConfigFiles/p2/p2 --data-binary "some data"
     {
       "Description": "Error while creating the file"
     }

  10. PUT https://${bmc}/ibm/v1/Host/ConfigFiles/p2/../../../p2 --data-binary "some data"
      Bad Request

  11. PUT https://${bmc}/ibm/v1/Host/ConfigFiles/./../../p2 --data-binary "some data"
      Bad Request

  12. PUT https://${bmc}/ibm/v1/Host/ConfigFiles/. --data-binary "some data"
      Bad Request

  13. PUT https://${bmc}/ibm/v1/Host/../ConfigFiles/p2 --data-binary "some data"
      Not Found

  14. PUT https://${bmc}/ibm/v1/Host/ConfigFiles/p2 --data-binary "some data"
      {
        "Description": "File Created"
      }

  15. PUT https://${bmc}/ibm/v1/Host/ConfigFiles/p2 --data-binary "some data"
      {
        "Description": "File Updated"
      }

  16. PUT https://${bmc}/ibm/v1/Host/ConfigFiles/p2.ext --data-binary "some data"
      {
        "Description": "File Created"
      }
  17. Tested sending filename greater than 20 charaters
      Bad Request
  18. Tested sending filename with special charaters
      Bad Request
  19. Tested sending filesize less than 100bytes
      Bad request
  20. Tested sending filesize greater than 500KB
      Bad request
  21. Tested uploading the file when the directory size is nearly full
      Bad request
  22. Added unit test for isValidConfigFileName

Signed-off-by: Sunitha Harish <sunharis@in.ibm.com>
Change-Id: I838d39d5765ddc8701f7e5c533a93eebde021cbf
3 files changed
tree: 956a31fa7150257b2fff7633036af7b736a90ee0
  1. http/
  2. include/
  3. redfish-core/
  4. scripts/
  5. src/
  6. static/
  7. subprojects/
  8. .clang-format
  9. .clang-ignore
  10. .clang-tidy
  11. .dockerignore
  12. .gitignore
  13. .shellcheck
  14. bmcweb.service.in
  15. bmcweb.socket
  16. build_x86.sh
  17. build_x86_docker.sh
  18. COMMON_ERRORS.md
  19. DEVELOPING.md
  20. Dockerfile
  21. Dockerfile.base
  22. LICENCE
  23. MAINTAINERS
  24. meson.build
  25. meson_options.txt
  26. OEM_SCHEMAS.md
  27. OWNERS
  28. pam-webserver
  29. README.md
  30. Redfish.md
README.md

OpenBMC webserver

This component attempts to be a "do everything" embedded webserver for openbmc.

Capabilities

At this time, the webserver implements a few interfaces:

  • Authentication middleware that supports cookie and token based authentication, as well as CSRF prevention backed by linux PAM authentication credentials.
  • An (incomplete) attempt at replicating phosphor-dbus-rest interfaces in C++. Right now, a few of the endpoint definitions work as expected, but there is still a lot of work to be done. The portions of the interface that are functional are designed to work correctly for phosphor-webui, but may not yet be complete.
  • Replication of the rest-dbus backend interfaces to allow bmc debug to logged in users.
  • An initial attempt at a read-only redfish interface. Currently the redfish interface targets ServiceRoot, SessionService, AccountService, Roles, and ManagersService. Some functionality here has been shimmed to make development possible. For example, there exists only a single user role.
  • SSL key generation at runtime. See the configuration section for details.
  • Static file hosting. Currently, static files are hosted from the fixed location at /usr/share/www. This is intended to allow loose coupling with yocto projects, and allow overriding static files at build time.
  • Dbus-monitor over websocket. A generic endpoint that allows UIs to open a websocket and register for notification of events to avoid polling in single page applications. (this interface may be modified in the future due to security concerns.

Configuration

BMCWeb is configured by setting -D flags that correspond to options in bmcweb/meson_options.txt and then compiling. For example, meson <builddir> -Dkvm=disabled ... followed by ninja in build directory. The option names become C++ preprocessor symbols that control which code is compiled into the program.

Compile bmcweb with default options:

meson builddir
ninja -C builddir

Compile bmcweb with yocto defaults:

meson builddir -Dbuildtype=minsize -Db_lto=true -Dtests=disabled
ninja -C buildir

If any of the dependencies are not found on the host system during configuration, meson automatically gets them via its wrap dependencies mentioned in bmcweb/subprojects.

Enable/Disable meson wrap feature

meson builddir -Dwrap_mode=nofallback
ninja -C builddir

Generate test coverage report:

meson builddir -Db_coverage=true -Dtests=enabled
ninja coverage -C builddir test

When BMCWeb starts running, it reads persistent configuration data (such as UUID and session data) from a local file. If this is not usable, it generates a new configuration.

When BMCWeb SSL support is enabled and a usable certificate is not found, it will generate a self-sign a certificate before launching the server. The keys are generated by the secp384r1 algorithm. The certificate

  • is issued by C=US, O=OpenBMC, CN=testhost,
  • is valid for 10 years,
  • has a random serial number, and
  • is signed using the SHA-256 algorithm.