Harden the Server Running XWiki

Last modified by Eleni Cojocariu on 2026/12/04 14:27

An attacker who reaches the account XWiki runs as reaches every wiki on the server; these are the host settings that make that harder.

Steps

Nothing on this page is configured in the wiki. It is the operating system's side of the same job, and the one entry in Attack Vectors that XWiki itself can do nothing about. The commands below are for Debian and Ubuntu, with the equivalent named where another distribution differs.

  1. Let the operating system patch itself, so that a published vulnerability does not wait for your next maintenance window:
    sudo apt install unattended-upgrades
    sudo dpkg-reconfigure --priority=low unattended-upgrades

    On RHEL and its derivatives the equivalent package is dnf-automatic.

  2. Give XWiki an account of its own, able to read the web application and to write the permanent directory and nothing else:
    sudo useradd --system --no-create-home --shell /usr/sbin/nologin xwiki
    sudo chown -R xwiki:xwiki /path/to/webapp /path/to/permanent-directory

    Then run the Servlet Container as that account rather than as root: in a systemd unit it is the User= directive. Do not add the account to sudoers, because whatever it may do is what an attacker who reaches the Java process may do.

  3. Move the administrative services off the ports that are scanned all day, ssh first. Set its port in /etc/ssh/sshd_config:
    Port 2222

    Reload the service, and keep the session you are in open until you have signed in again on the new port:

    sudo systemctl reload ssh

    The service is called sshd on RHEL and its derivatives.

  4. Refuse every incoming port you have not allowed:
    sudo ufw default deny incoming
    sudo ufw allow 2222/tcp
    sudo ufw allow 443/tcp
    sudo ufw enable

    firewall-cmd --add-port does the same where firewalld is the firewall. The Servlet Container's own port, 8080 by default, and the database port are deliberately missing: when the reverse proxy and the database run on this host, both are reached over the loopback interface and neither needs opening.

  5. Read back what the server still answers on:
    sudo ss -ltnp

    Only the ports you allowed are bound to a public address, and every line you cannot account for is a port to close or a process that has no business running here:

    State  Recv-Q Send-Q  Local Address:Port  Process
    LISTEN 0      4096        127.0.0.1:8080  users:(("java",pid=1042,fd=48))
    LISTEN 0      4096        127.0.0.1:5432  users:(("postgres",pid=812,fd=5))
    LISTEN 0      511           0.0.0.0:443   users:(("nginx",pid=744,fd=6))
    LISTEN 0      128           0.0.0.0:2222  users:(("sshd",pid=701,fd=3))

FAQ

Does moving ssh to another port actually help?

It removes the automated scanning that would otherwise fill the logs, and nothing more: a targeted attacker finds the new port in seconds. Key authentication is the control that matters.

Related

Get Connected