8000 [pull] main from miniflux:main by pull[bot] · Pull Request #369 · suhaoGe/miniflux · GitHub
[go: up one dir, main page]

Skip to content
8000
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions internal/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"runtime"
"testing"

"miniflux.app/v2/internal/config"
"miniflux.app/v2/internal/version"
)

Expand Down Expand Up @@ -201,3 +202,35 @@ func TestNewHandlerSupportsBasePathStripping(t *testing.T) {
})
}
}

func TestBasicAuthIsRejectedWhenLocalAuthDisabled(t *testing.T) {
t.Setenv("DISABLE_LOCAL_AUTH", "1")
t.Setenv("OAUTH2_PROVIDER", "oidc")
t.Setenv("OAUTH2_CLIENT_ID", "client")
t.Setenv("OAUTH2_CLIENT_SECRET", "secret")
t.Setenv("OAUTH2_REDIRECT_URL", "https://example.org/oauth2/oidc/callback")
t.Setenv("OAUTH2_OIDC_DISCOVERY_ENDPOINT", "https://example.org")

parsedOptions, err := config.NewConfigParser().ParseEnvironmentVariables()
if err != nil {
t.Fatalf("Unable to configure test options: %v", err)
}

previousOptions := config.Opts
config.Opts = parsedOptions
t.Cleanup(func() {
config.Opts = previousOptions
})

handler := NewHandler(nil, nil)

r := httptest.NewRequest(http.MethodGet, "/v1/me", nil)
r.SetBasicAuth("admin", "password")
w := httptest.NewRecorder()

handler.ServeHTTP(w, r)

if got := w.Code; got != http.StatusUnauthorized {
t.Fatalf(`Unexpected status code, got %d instead of %d`, got, http.StatusUnauthorized)
}
}
12 changes: 12 additions & 0 deletions internal/api/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"log/slog"
"net/http"

"miniflux.app/v2/internal/config"
"miniflux.app/v2/internal/http/request"
"miniflux.app/v2/internal/http/response"
"miniflux.app/v2/internal/storage"
Expand Down Expand Up @@ -109,6 +110,17 @@ func (m *middleware) validateBasicAuth(next http.Handler) http.Handler {
return
}

if config.Opts.DisableLocalAuth() {
slog.Warn("[API] Blocking Basic HTTP Authentication attempt, local auth is disabled",
slog.Bool("authentication_failed", true),
slog.String("client_ip", clientIP),
slog.String("user_agent", r.UserAgent()),
slog.String("request_uri", r.RequestURI),
)
response.JSONUnauthorized(w, r)
return
}

if username == "" || password == "" {
slog.Warn("[API] Empty username or password provided during Basic HTTP Authentication",
slog.Bool("authentication_failed", true),
Expand Down
2 changes: 1 addition & 1 deletion internal/googlereader/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (m *authMiddleware) serveValidated(w http.ResponseWriter, r *http.Request,
}

parts := strings.Split(token, "/")
if len(parts) != 2 {
if len(parts) != 2 || parts[0] == "" {
slog.Warn("[GoogleReader] Auth token does not have the expected structure username/hash",
slog.Bool("authentication_failed", true),
slog.String("client_ip", clientIP),
Expand Down
37 changes: 37 additions & 0 deletions internal/googlereader/middleware_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

package googlereader // import "miniflux.app/v2/internal/googlereader"

import (
"net/http"
"net/http/httptest"
"net/url"
"strings"
"testing"
)

func TestAuthMiddlewareRejectsTokenWithEmptyUsername(t *testing.T) {
token := getAuthToken("", "")

getRequest := httptest.NewRequest(http.MethodGet, "/reader/api/0/user-info", nil)
getRequest.Header.Set("Authorization", "GoogleLogin auth="+token)

postRequest := httptest.NewRequest(http.MethodPost, "/reader/api/0/edit-tag", strings.NewReader(url.Values{"T": {token}}.Encode()))
postRequest.Header.Set("Content-Type", "application/x-www-form-urlencoded")

// The store is nil: the middleware must reject the token before querying it.
middleware := newAuthMiddleware(nil)
next := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
t.Fatal("next handler should not be called")
})

for _, request := range []*http.Request{getRequest, postRequest} {
recorder := httptest.NewRecorder()
middleware.validateApiKey(next).ServeHTTP(recorder, request)

if recorder.Code != http.StatusUnauthorized {
t.Errorf("%s: expected status %d, got %d", request.Method, http.StatusUnauthorized, recorder.Code)
}
}
}
2 changes: 2 additions & 0 deletions internal/locale/translations/ar_SA.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
"error.duplicate_fever_username": "يوجد بالفعل شخص آخر بنفس اسم مستخدم Fever!",
"error.duplicate_googlereader_username": "يوجد بالفعل شخص آخر بنفس اسم مستخدم Google Reader!",
"error.linktaco_missing_required_fields": "مطلوب رمز LinkTaco API و Organization Slug",
"error.googlereader_missing_required_fields": "مطلوب اسم مستخدم وكلمة مرور Google Reader",
"error.duplicate_linked_account": "يوجد بالفعل شخص مرتبط بهذا الموفر!",
"error.duplicated_feed": "هذا المصدر موجود بالفعل.",
"error.empty_file": "هذا الملف فارغ.",
Expand Down Expand Up @@ -144,6 +145,7 @@
"error.invalid_site_url": "رابط الموقع غير صالح.",
"error.invalid_theme": "السمة غير صالحة.",
"error.invalid_timezone": "المنطقة الزمنية غير صالحة.",
"error.local_auth_disabled": "Local authentication is disabled. Passwords cannot be changed.",
"error.network_operation": "Miniflux غير قادر على الوصول إلى هذا الموقع بسبب خطأ في الشبكة: %v.",
"error.network_timeout": "هذا الموقع بطيء جداً وانتهى وقت الطلب: %v",
"error.password_min_length": "يجب أن تتكون كلمة المرور من 6 أحرف على الأقل.",
Expand Down
2 changes: 2 additions & 0 deletions internal/locale/translations/de_DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
"error.invalid_site_url": "Ungültiger Site-URL.",
"error.invalid_theme": "Ungültiges Thema.",
"error.invalid_timezone": "Ungültige Zeitzone.",
"error.local_auth_disabled": "Local authentication is disabled. Passwords cannot be changed.",
"error.network_operation": "Miniflux kann die Webseite aufgrund eines Netzwerk-Fehlers nicht erreichen: %v",
"error.network_timeout": "Die Webseite ist zu langsam und die Anfrage ist abgelaufen: %v.",
"error.password_min_length": "Wenigstens 6 Zeichen müssen genutzt werden.",
Expand Down Expand Up @@ -163,6 +164,7 @@
"error.user_already_exists": "Dieser Benutzer existiert bereits.",
"error.user_mandatory_fields": "Der Benutzername ist obligatorisch.",
"error.linktaco_missing_required_fields": "LinkTaco API Token und Organization Slug sind erforderlich.",
"error.googlereader_missing_required_fields": "Google Reader Benutzername und Passwort sind erforderlich.",
"form.api_key.label.description": "API-Schlüsselbezeichnung",
"form.category.hide_globally": "Artikel in der globalen Ungelesen-Liste ausblenden",
"form.category.label.title": "Titel",
Expand Down
2 changes: 2 additions & 0 deletions internal/locale/translations/el_EL.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
"error.invalid_site_url": "Μη έγκυρη διεύθυνση URL ιστότοπου.",
"error.invalid_theme": "Μη έγκυρο θέμα.",
"error.invalid_timezone": "Μη έγκυρη ζώνη ώρας.",
"error.local_auth_disabled": "Local authentication is disabled. Passwords cannot be changed.",
"error.network_operation": "Το Miniflux δεν μπορεί να φτάσει σε αυτόν τον ιστότοπο λόγω σφάλματος δικτύου: %v.",
"error.network_timeout": "Αυτός ο ιστότοπος είναι πολύ αργός και το αίτημα έληξε: %v",
"error.password_min_length": "Ο κωδικός πρόσβασης πρέπει να έχει τουλάχιστον 6 χαρακτήρες.",
Expand Down Expand Up @@ -163,6 +164,7 @@
"error.user_already_exists": "Αυτός ο χρήστης υπάρχει ήδη.",
"error.user_mandatory_fields": "Το όνομα χρήστη είναι υποχρεωτικό.",
"error.linktaco_missing_required_fields": "Το LinkTaco API Token και το Organization Slug είναι απαραίτητα",
"error.googlereader_missing_required_fields": "Το όνομα χρήστη και ο κωδικός πρόσβασης του Google Reader είναι απαραίτητα",
"form.api_key.label.description": "Ετικέτα κλειδιού API",
"form.category.hide_globally": "Απόκρυψη καταχωρήσεων σε γενική λίστα μη αναγνωσμένων",
"form.category.label.title": "Τίτλος",
Expand Down
2 changes: 2 additions & 0 deletions internal/locale/translations/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
"error.duplicate_fever_username": "There is already someone else with the same Fever username!",
"error.duplicate_googlereader_username": "There is already someone else with the same Google Reader username!",
"error.linktaco_missing_required_fields": "LinkTaco API Token and Organization Slug are required",
"error.googlereader_missing_required_fields": "Google Reader username and password are required",
"error.duplicate_linked_account": "There is already someone associated with this provider!",
"error.duplicated_feed": "This feed already exists.",
"error.empty_file": "This file is empty.",
Expand Down Expand Up @@ -132,6 +133,7 @@
"error.invalid_site_url": "Invalid site URL.",
"error.invalid_theme": "Invalid theme.",
"error.invalid_timezone": "Invalid timezone.",
"error.local_auth_disabled": "Local authentication is disabled. Passwords cannot be changed.",
"error.network_operation": "Miniflux is not able to reach this website due to a network error: %v.",
"error.network_timeout": "This website is too slow and the request timed out: %v",
"error.password_min_length": "The password must have at least 6 characters.",
Expand Down
2 changes: 2 additions & 0 deletions internal/locale/translations/es_ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
"error.invalid_site_url": "URL del sitio no válida.",
"error.invalid_theme": "Tema no válido.",
"error.invalid_timezone": "Zona horaria no válida.",
"error.local_auth_disabled": "Local authentication is disabled. Passwords cannot be changed.",
"error.network_operation": "Miniflux no puede acceder a este sitio web debido a un error de red: %v.",
"error.network_timeout": "Este sitio web es demasiado lento y se agotó el tiempo de espera de la solicitud: %v",
"error.password_min_length": "La contraseña debería tener al menos 6 caracteres.",
Expand Down Expand Up @@ -163,6 +164,7 @@
"error.user_already_exists": "Este usuario ya existe.",
"error.user_mandatory_fields": "El nombre de usuario es obligatorio.",
"error.linktaco_missing_required_fields": "LinkTaco API Token y Organization Slug son obligatorios.",
"error.googlereader_missing_required_fields": "El nombre de usuario y la contraseña de Google Reader son obligatorios.",
"form.api_key.label.description": "Etiqueta de clave API",
"form.category.hide_globally": "Ocultar artículos en la lista global de no leídos",
"form.category.label.title": "Título",
Expand Down
2 changes: 2 additions & 0 deletions internal/locale/translations/fi_FI.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
"error.invalid_site_url": "Virheellinen sivuston URL-osoite.",
"error.invalid_theme": "Virheellinen teema.",
"error.invalid_timezone": "Virheellinen aikavyöhyke.",
"error.local_auth_disabled": "Local authentication is disabled. Passwords cannot be changed.",
"error.network_operation": "Miniflux ei tavoita tätä sivustoa verkkovirheen vuoksi: %v.",
"error.network_timeout": "Tämä sivusto on liian hidas ja pyyntö aikakatkaistiin: %v",
"error.password_min_length": "Salasanassa on oltava vähintään 6 merkkiä.",
Expand Down Expand Up @@ -163,6 +164,7 @@
"error.user_already_exists": "Käyttäjä on jo olemassa.",
"error.user_mandatory_fields": "Käyttäjätunnus on pakollinen.",
"error.linktaco_missing_required_fields": "LinkTaco API Token ja Organization Slug vaaditaan",
"error.googlereader_missing_required_fields": "Google Reader -käyttäjätunnus ja -salasana vaaditaan",
"form.api_key.label.description": "API-avaimen nimi",
"form.category.hide_globally": "Piilota artikkelit lukemattomien listassa",
"form.category.label.title": "Otsikko",
Expand Down
2 changes: 2 additions & 0 deletions internal/locale/translations/fr_FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
"error.invalid_site_url": "URL de site non valide.",
"error.invalid_theme": "Thème non valide.",
"error.invalid_timezone": "Fuseau horaire non valide.",
"error.local_auth_disabled": "Local authentication is disabled. Passwords cannot be changed.",
"error.network_operation": "Miniflux n'est pas en mesure de se connecter à ce site web à cause d'un problème réseau : %v.",
"error.network_timeout": "Ce site web est trop lent à répondre : %v.",
"error.password_min_length": "Vous devez utiliser au moins 6 caractères pour le mot de passe.",
Expand Down Expand Up @@ -163,6 +164,7 @@
"error.user_already_exists": "Cet utilisateur existe déjà.",
"error.user_mandatory_fields": "Le nom d'utilisateur est obligatoire.",
"error.linktaco_missing_required_fields": "Le token API LinkTaco et le slug de l'organisation sont requis.",
"error.googlereader_missing_required_fields": "Le nom d'utilisateur et le mot de passe Google Reader sont requis.",
"form.api_key.label.description": "Libellé de la clé d'API",
"form.category.hide_globally": "Masquer les entrées dans la liste globale non lue",
"form.category.label.title": "Titre",
Expand Down
2 changes: 2 additions & 0 deletions internal/locale/translations/gl_ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
"error.duplicate_fever_username": "Xa hai alguén con ese identificador en Fever!",
"error.duplicate_googlereader_username": "Xa hai alguén con ese identificador en Google Reader!",
"error.linktaco_missing_required_fields": "Requírese LinkTaco API Token e Organization Slug",
"error.googlereader_missing_required_fields": "Requírense o nome de usuario e o contrasinal de Google Reader",
"error.duplicate_linked_account": "Xa hai alguén asociado con este provedor!",
"error.duplicated_feed": "Xa existe a canle.",
"error.empty_file": "O ficheiro está baleiro.",
Expand Down Expand Up @@ -132,6 +133,7 @@
"error.invalid_site_url": "URL da web non válido.",
"error.invalid_theme": "Decorado non válido.",
"error.invalid_timezone": "Zona horaria non válida.",
"error.local_auth_disabled": "Local authentication is disabled. Passwords cannot be changed.",
"error.network_operation": "Miniflux non pode acadar esta web por mor dun erro na rede: %v.",
"error.network_timeout": "Esta web é demasiado lenta e caducou a petición: %v",
"error.password_min_length": "O contrasinal ten que ter 6 caracteres polo menos.",
Expand Down
2 changes: 2 additions & 0 deletions internal/locale/translations/hi_IN.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
"error.invalid_site_url": "अमान्य साइट यूआरएल",
"error.invalid_theme": "अमान्य थीम.",
"error.invalid_timezone": "अमान्य समयक्षेत्र.",
"error.local_auth_disabled": "Local authentication is disabled. Passwords cannot be changed.",
"error.network_operation": "नेटवर्क त्रुटि के कारण मिनीफ्लक्स इस वेबसाइट तक नहीं पहुँच पा रहा: %v.",
"error.network_timeout": "यह वेबसाइट बहुत धीमी है और अनुरोध का समय समाप्त हो गया: %v",
"error.password_min_length": "पासवर्ड में कम से कम 6 अक्षर होने चाहिए।",
Expand Down Expand Up @@ -163,6 +164,7 @@
"error.user_already_exists": "यह उपयोगकर्ता पहले से ही मौजूद है।",
"error.user_mandatory_fields": "उपयोगकर्ता नाम अनिवार्य है।",
"error.linktaco_missing_required_fields": "LinkTaco API Token और Organization Slug आवश्यक हैं",
"error.googlereader_missing_required_fields": "Google Reader उपयोगकर्ता नाम और पासवर्ड आवश्यक हैं",
"form.api_key.label.description": "एपीआई कुंजी लेबल",
"form.category.hide_globally": "वैश्विक अपठित सूची में प्रविष्टियां छिपाएं",
"form.category.label.title": "शीर्षक",
Expand Down
2 changes: 2 additions & 0 deletions internal/locale/translations/id_ID.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
"error.invalid_site_url": "URL situs tidak valid.",
"error.invalid_theme": "Tema tidak valid.",
"error.invalid_timezone": "Zona waktu tidak valid.",
"error.local_auth_disabled": "Local authentication is disabled. Passwords cannot be changed.",
"error.network_operation": "Miniflux tidak dapat menjangkau situs ini dikarenakan galat jaringan: %v.",
"error.network_timeout": "Situs ini terlalu lambat dan permintaan ke situs terlalu lama: %v",
"error.password_min_length": "Kata sandi harus memiliki setidaknya 6 karakter.",
Expand Down Expand Up @@ -160,6 +161,7 @@
"error.user_already_exists": "Pengguna ini sudah ada.",
"error.user_mandatory_fields": "Harus ada nama pengguna.",
"error.linktaco_missing_required_fields": "LinkTaco API Token dan Organization Slug diperlukan",
"error.googlereader_missing_required_fields": "Nama pengguna dan kata sandi Google Reader diperlukan",
"form.api_key.label.description": "Label Kunci API",
"form.category.hide_globally": "Sembunyikan entri di daftar belum dibaca global",
"form.category.label.title": "Judul",
Expand Down
2 changes: 2 additions & 0 deletions internal/locale/translations/it_IT.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
"error.invalid_site_url": "URL del sito non valido.",
"error.invalid_theme": "Tema non valido.",
"error.invalid_timezone": "Fuso orario non valido.",
"error.local_auth_disabled": "Local authentication is disabled. Passwords cannot be changed.",
"error.network_operation": "Miniflux non riesce a raggiungere questo sito web a causa di un errore di rete: %v.",
"error.network_timeout": "Questo sito web è troppo lento e la richiesta è scaduta: %v",
"error.password_min_length": "La password deve contenere almeno 6 caratteri.",
Expand Down Expand Up @@ -163,6 +164,7 @@
"error.user_already_exists": "Questo utente esiste già.",
"error.user_mandatory_fields": "Il nome utente è obbligatorio.",
"error.linktaco_missing_required_fields": "LinkTaco API Token e Organization Slug sono richiesti",
"error.googlereader_missing_required_fields": "Nome utente e password di Google Reader sono richiesti",
"form.api_key.label.description": "Etichetta chiave API",
"form.category.hide_globally": "Nascondere le voci nella lista globale dei non letti",
"form.category.label.title": "Titolo",
Expand Down
2 changes: 2 additions & 0 deletions internal/locale/translations/ja_JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
"error.invalid_site_url": "サイト URL が無効です。",
"error.invalid_theme": "テーマが無効です。",
"error.invalid_timezone": "タイムゾーンが無効です。",
"error.local_auth_disabled": "Local authentication is disabled. Passwords cannot be changed.",
"error.network_operation": "Miniflux はネットワークエラーのためこのウェブサイトに到達できません: %v.",
"error.network_timeout": "このウェブサイトは応答が遅すぎるためタイムアウトしました: %v",
"error.password_min_length": "パスワードは6文字以上である必要があります。",
Expand Down Expand Up @@ -160,6 +161,7 @@
"error.user_already_exists": "このユーザーは既に存在します。",
"error.user_mandatory_fields": "ユーザー名が必要です。",
"error.linktaco_missing_required_fields": "LinkTaco API TokenとOrganization Slugが必要です",
"error.googlereader_missing_required_fields": "Google Readerのユーザー名とパスワードが必要です",
"form.api_key.label.description": "API キーラベル",
"form.category.hide_globally": "未読一覧に記事を表示しない",
"form.category.label.title": "タイトル",
Expand Down
2 changes: 2 additions & 0 deletions internal/locale/translations/ko_KR.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
"error.invalid_site_url": "사이트 URL이 유효하지 않습니다.",
"error.invalid_theme": "테마가 유효하지 않습니다.",
"error.invalid_timezone": "시간대가 유효하지 않습니다.",
"error.local_auth_disabled": "Local authentication is disabled. Passwords cannot be changed.",
"error.network_operation": "네트워크 오류로 인해 Miniflux가 이 웹사이트에 도달할 수 없습니다: %v.",
"error.network_timeout": "이 웹사이트의 응답이 너무 느려 시간 초과되었습니다: %v",
"error.password_min_length": "비밀번호는 6자 이상이어야 합니다.",
Expand Down Expand Up @@ -160,6 +161,7 @@
"error.user_already_exists": "이 사용자는 이미 존재합니다.",
"error.user_mandatory_fields": "사용자명이 필요합니다.",
"error.linktaco_missing_required_fields": "LinkTaco API 토큰과 조직 슬러그가 필요합니다",
"error.googlereader_missing_required_fields": "Google Reader 사용자 이름과 비밀번호가 필요합니다",
"form.api_key.label.description": "API키 설명",
"form.category.hide_globally": "읽지 않음 목록에 게시물을 표시하지 않음",
"form.category.label.title": "제목",
Expand Down
Loading
Loading
0