nextcloud / server

☁️ Nextcloud server, a safe home for all your data
https://nextcloud.com
GNU Affero General Public License v3.0
27.32k stars 4.06k forks source link

[Bug]: Cannot login after fresh install - IP address throttled because it reached the attempts limit #43705

Closed ickedude closed 8 months ago

ickedude commented 8 months ago

⚠️ This issue respects the following points: ⚠️

Bug description

I am not able to login after a fresh installation of nextcloud. No matter if I install via web installer or archive. In the following steps I used the password bla everywhere, but also tried complex password. Problem is reproducible with 28.0.2 and 27.0.1

Steps to reproduce

  1. docker run -it debian:12
  2. apt update
  3. apt install -y postgresql
  4. /etc/init.d/postgresql start
  5. su postgres
  6. createuser -P nc
  7. createdb -O nc nc
  8. exit
  9. apt install -y php-cli php-fpm php-xml php-pgsql php-gd php-mbstring php-curl php-zip curl unzip nginx-light
  10. cd /var/www
  11. curl -o nextcloud.zip https://download.nextcloud.com/server/releases/latest.zip
  12. unzip nextcloud.zip
  13. chown -R www-data:www-data nextcloud
  14. Create the file /etc/nginx/sites-enabled/nextcloud with the following content (from https://docs.nextcloud.com/server/latest/admin_manual/installation/nginx.html modified to not require https)
    
    upstream php-handler {
    #server 127.0.0.1:9000;
    server unix:/run/php/php8.2-fpm.sock;
    }

Set the immutable cache control options only for assets with a cache busting v argument

map $arg_v $asset_immutable { "" ""; default ", immutable"; }

server { listen 8080;

# Prevent nginx HTTP Server Detection
server_tokens off;

# Path to the root of your installation
root /var/www/nextcloud;

# set max upload size and increase upload timeout:
client_max_body_size 512M;
client_body_timeout 300s;
fastcgi_buffers 64 4K;

# Enable gzip but do not remove ETag headers
gzip on;
gzip_vary on;
gzip_comp_level 4;
gzip_min_length 256;
gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;
gzip_types application/atom+xml text/javascript application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/wasm application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy;

# The settings allows you to optimize the HTTP2 bandwidth.
# See https://blog.cloudflare.com/delivering-http-2-upload-speed-improvements/
# for tuning hints
client_body_buffer_size 512k;

# HTTP response headers borrowed from Nextcloud `.htaccess`
add_header Referrer-Policy                   "no-referrer"       always;
add_header X-Content-Type-Options            "nosniff"           always;
add_header X-Frame-Options                   "SAMEORIGIN"        always;
add_header X-Permitted-Cross-Domain-Policies "none"              always;
add_header X-Robots-Tag                      "noindex, nofollow" always;
add_header X-XSS-Protection                  "1; mode=block"     always;

# Remove X-Powered-By, which is an information leak
fastcgi_hide_header X-Powered-By;

# Set .mjs and .wasm MIME types
# Either include it in the default mime.types list
# and include that list explicitly or add the file extension
# only for Nextcloud like below:
include mime.types;
types {
    text/javascript js mjs;
application/wasm wasm;
}

# Specify how to handle directories -- specifying `/index.php$request_uri`
# here as the fallback means that Nginx always exhibits the desired behaviour
# when a client requests a path that corresponds to a directory that exists
# on the server. In particular, if that directory contains an index.php file,
# that file is correctly served; if it doesn't, then the request is passed to
# the front-end controller. This consistent behaviour means that we don't need
# to specify custom rules for certain paths (e.g. images and other assets,
# `/updater`, `/ocs-provider`), and thus
# `try_files $uri $uri/ /index.php$request_uri`
# always provides the desired behaviour.
index index.php index.html /index.php$request_uri;

# Rule borrowed from `.htaccess` to handle Microsoft DAV clients
location = / {
    if ( $http_user_agent ~ ^DavClnt ) {
        return 302 /remote.php/webdav/$is_args$args;
    }
}

location = /robots.txt {
    allow all;
    log_not_found off;
    access_log off;
}

# Make a regex exception for `/.well-known` so that clients can still
# access it despite the existence of the regex rule
# `location ~ /(\.|autotest|...)` which would otherwise handle requests
# for `/.well-known`.
location ^~ /.well-known {
    # The rules in this block are an adaptation of the rules
    # in `.htaccess` that concern `/.well-known`.

    location = /.well-known/carddav { return 301 /remote.php/dav/; }
    location = /.well-known/caldav  { return 301 /remote.php/dav/; }

    location /.well-known/acme-challenge    { try_files $uri $uri/ =404; }
    location /.well-known/pki-validation    { try_files $uri $uri/ =404; }

    # Let Nextcloud's API for `/.well-known` URIs handle all other
    # requests by passing them to the front-end controller.
    return 301 /index.php$request_uri;
}

# Rules borrowed from `.htaccess` to hide certain paths from clients
location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)(?:$|/)  { return 404; }
location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console)                { return 404; }

# Ensure this block, which passes PHP files to the PHP process, is above the blocks
# which handle static assets (as seen below). If this block is not declared first,
# then Nginx will encounter an infinite rewriting loop when it prepends `/index.php`
# to the URI, resulting in a HTTP 500 error response.
location ~ \.php(?:$|/) {
    # Required for legacy support
    rewrite ^/(?!index|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|ocs-provider\/.+|.+\/richdocumentscode\/proxy) /index.php$request_uri;

    fastcgi_split_path_info ^(.+?\.php)(/.*)$;
    set $path_info $fastcgi_path_info;

    try_files $fastcgi_script_name =404;

    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $path_info;
    fastcgi_param HTTPS on;

    fastcgi_param modHeadersAvailable true;         # Avoid sending the security headers twice
    fastcgi_param front_controller_active true;     # Enable pretty urls
    fastcgi_pass php-handler;

    fastcgi_intercept_errors on;
    fastcgi_request_buffering off;

    fastcgi_max_temp_file_size 0;
}

# Serve static files
location ~ \.(?:css|js|mjs|svg|gif|png|jpg|ico|wasm|tflite|map|ogg|flac)$ {
    try_files $uri /index.php$request_uri;
    # HTTP response headers borrowed from Nextcloud `.htaccess`
    add_header Cache-Control                     "public, max-age=15778463$asset_immutable";
    add_header Referrer-Policy                   "no-referrer"       always;
    add_header X-Content-Type-Options            "nosniff"           always;
    add_header X-Frame-Options                   "SAMEORIGIN"        always;
    add_header X-Permitted-Cross-Domain-Policies "none"              always;
    add_header X-Robots-Tag                      "noindex, nofollow" always;
    add_header X-XSS-Protection                  "1; mode=block"     always;
    access_log off;     # Optional: Don't log access to assets
}

location ~ \.woff2?$ {
    try_files $uri /index.php$request_uri;
    expires 7d;         # Cache-Control policy borrowed from `.htaccess`
    access_log off;     # Optional: Don't log access to assets
}

# Rule borrowed from `.htaccess`
location /remote {
    return 301 /remote.php$request_uri;
}

location / {
    try_files $uri $uri/ /index.php$request_uri;
}

}

15. `nginx -g 'daemon off;' &`
16. `php-fpm8.2 &`
17. `su www-data -s /bin/bash`
18. `php nextcloud/occ maintenance:install --database pgsql --database-name nc --database-user nc --database-pass bla --admin-user admin --admin-pass bla`
19. `php nextcloud/occ config:system:set overwrite.cli.url --value 'http://172.17.0.2'`
20. `php nextcloud/occ config:system:set trusted_domains 0 --value '172.17.0.2'`
21. `php nextcloud/occ config:system:set debug --value true --type boolean`
22. `php nextcloud/occ config:system:set loglevel --value 0 --type integer`
23. use a browser to visit http://172.17.0.2:8080/login

### Expected behavior

seeing user home screen after login

### Installation method

Community Manual installation with Archive

### Nextcloud Server version

28

### Operating system

Debian/Ubuntu

### PHP engine version

PHP 8.2

### Web server

Nginx

### Database engine version

PostgreSQL

### Is this bug present after an update or on a fresh install?

Fresh Nextcloud Server install

### Are you using the Nextcloud Server Encryption module?

Encryption is Disabled

### What user-backends are you using?

- [X] Default user-backend _(database)_
- [ ] LDAP/ Active Directory
- [ ] SSO - SAML
- [ ] Other

### Configuration report

```shell
{
    "system": {
        "passwordsalt": "***REMOVED SENSITIVE VALUE***",
        "secret": "***REMOVED SENSITIVE VALUE***",
        "trusted_domains": [
            "172.17.0.2"
        ],
        "datadirectory": "***REMOVED SENSITIVE VALUE***",
        "dbtype": "pgsql",
        "version": "28.0.2.5",
        "overwrite.cli.url": "http:\/\/172.17.0.2",
        "dbname": "***REMOVED SENSITIVE VALUE***",
        "dbhost": "***REMOVED SENSITIVE VALUE***",
        "dbport": "",
        "dbtableprefix": "oc_",
        "dbuser": "***REMOVED SENSITIVE VALUE***",
        "dbpassword": "***REMOVED SENSITIVE VALUE***",
        "installed": true,
        "instanceid": "***REMOVED SENSITIVE VALUE***"
    }
}

List of activated Apps

Enabled:
  - activity: 2.20.0
  - circles: 28.0.0-dev
  - cloud_federation_api: 1.11.0
  - comments: 1.18.0
  - contactsinteraction: 1.9.0
  - dashboard: 7.8.0
  - dav: 1.29.1
  - federatedfilesharing: 1.18.0
  - federation: 1.18.0
  - files: 2.0.0
  - files_pdfviewer: 2.9.0
  - files_reminders: 1.1.0
  - files_sharing: 1.20.0
  - files_trashbin: 1.18.0
  - files_versions: 1.21.0
  - firstrunwizard: 2.17.0
  - logreader: 2.13.0
  - lookup_server_connector: 1.16.0
  - nextcloud_announcements: 1.17.0
  - notifications: 2.16.0
  - oauth2: 1.16.3
  - password_policy: 1.18.0
  - photos: 2.4.0
  - privacy: 1.12.0
  - provisioning_api: 1.18.0
  - recommendations: 2.0.0
  - related_resources: 1.3.0
  - serverinfo: 1.18.0
  - settings: 1.10.1
  - sharebymail: 1.18.0
  - support: 1.11.0
  - survey_client: 1.16.0
  - systemtags: 1.18.0
  - text: 3.9.1
  - theming: 2.3.0
  - twofactor_backupcodes: 1.17.0
  - updatenotification: 1.18.0
  - user_status: 1.8.1
  - viewer: 2.2.0
  - weather_status: 1.8.0
  - workflowengine: 2.10.0
Disabled:
  - admin_audit: 1.18.0
  - bruteforcesettings: 2.8.0
  - encryption: 2.16.0
  - files_external: 1.20.0
  - suspicious_login: 6.0.0
  - twofactor_totp: 10.0.0-beta.2
  - user_ldap: 1.19.0

Nextcloud Signing status

login is not possible

Nextcloud Logs

{"reqId":"TE1kJT0eeeS5XbazqSQ6","level":0,"time":"2024-02-20T20:41:06+00:00","remoteAddr":"172.17.0.1","user":"--","app":"no app in context","method":"POST","url":"/login","message":"Logging out","userAgent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36","version":"28.0.2.5","data":{"user":"null"}}
{"reqId":"TE1kJT0eeeS5XbazqSQ6","level":1,"time":"2024-02-20T20:41:06+00:00","remoteAddr":"172.17.0.1","user":"--","app":"core","method":"POST","url":"/login","message":"Bruteforce attempt from \"172.17.0.1\" detected for action \"login\".","userAgent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36","version":"28.0.2.5","data":{"app":"core"}}
{"reqId":"TE1kJT0eeeS5XbazqSQ6","level":1,"time":"2024-02-20T20:41:06+00:00","remoteAddr":"172.17.0.1","user":"--","app":"no app in context","method":"POST","url":"/login","message":"IP address throttled because it reached the attempts limit in the last 30 minutes [action: login, delay: 200, ip: 172.17.0.1]","userAgent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36","version":"28.0.2.5","data":[]}

Additional info

browser console log:

JQMIGRATE: Migrate is installed, version 3.4.1
globals.js:59 jQuery is deprecated: The global jQuery is deprecated. It will be removed in a later versions without another warning. Please ship your own.

globals.js:59 $ is deprecated: The global jQuery is deprecated. It will be removed in a later versions without another warning. Please ship your own.

globals.js:59 Backbone is deprecated: please ship your own, this will be removed in Nextcloud 20

globals.js:59 Handlebars is deprecated: please ship your own, this will be removed in Nextcloud 20

session-heartbeat.js:103 session heartbeat polling started
ickedude commented 8 months ago

I spend two days to debug, but found the problem 20min after creating the issue 😠. I have found out that the browser does not respect cookies because the secure flag is set. The command php nextcloud/occ config:system:set overwriteprotocol --value http instructs nextcloud to accept http as the protocol. The flag is no longer set and login works. I'm sorry for wasting your time.

joshtrichards commented 8 months ago

fastcgi_param HTTPS on;

Alternatively, this line can be adjusted in your FastCGI Nginx config since you're not using HTTPS. Your approach will work fine as well. Both are roughly equal and overwriteprotocol takes precedence:

https://github.com/nextcloud/server/blob/1731d3154a8e9c8d3692c6c73f5a6b91b9bc17a5/lib/private/AppFramework/Http/Request.php#L647-L678