docstring_tokens
stringlengths
0
76.5k
code_tokens
stringlengths
75
1.81M
label_window
sequencelengths
4
2.12k
html_url
stringlengths
74
116
file_name
stringlengths
3
311
if rateLimiter := Context.auth.raleLimiter; rateLimiter != nil { if left := rateLimiter.check(remoteAddr); left > 0 {
<mask> <mask> return <mask> } <mask> <mask> if blocker := Context.auth.blocker; blocker != nil { <mask> if left := blocker.check(remoteAddr); left > 0 { <mask> w.Header().Set("Retry-After", strconv.Itoa(int(left.Seconds()))) <mask> aghhttp.Error(r, w, http.StatusTooManyRequests, "auth: blocked for %s", left) <mask> <mask> return <mask> } </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove return "", err </s> add return nil, errors.Error("invalid username or password") </s> remove var sess []byte sess, err = newSessionToken() </s> add sess, err := newSessionToken() </s> remove language := strings.TrimSpace(string(body)) if language == "" { msg := "empty language specified" log.Println(msg) http.Error(w, msg, http.StatusBadRequest) </s> add langReq := &languageJSON{} err := json.NewDecoder(r.Body).Decode(langReq) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "reading req: %s", err) </s> remove if !allowedLanguages.Has(language) { msg := fmt.Sprintf("unknown language specified: %s", language) log.Println(msg) http.Error(w, msg, http.StatusBadRequest) </s> add lang := langReq.Language if !allowedLanguages.Has(lang) { aghhttp.Error(r, w, http.StatusBadRequest, "unknown language: %q", lang) </s> remove if blocker != nil { blocker.remove(addr) </s> add if rateLimiter != nil { rateLimiter.remove(addr)
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth.go
cookie, err := Context.auth.newCookie(req, remoteAddr)
<mask> return <mask> } <mask> } <mask> <mask> var cookie string <mask> cookie, err = Context.auth.httpCookie(req, remoteAddr) <mask> if err != nil { <mask> aghhttp.Error(r, w, http.StatusBadRequest, "crypto rand reader: %s", err) <mask> <mask> return <mask> } </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove aghhttp.Error(r, w, http.StatusBadRequest, "crypto rand reader: %s", err) </s> add aghhttp.Error(r, w, http.StatusForbidden, "%s", err) </s> remove w.Header().Set("Content-Type", "application/json") err = json.NewEncoder(w).Encode(resp) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "Unable to write response json: %s", err) return } </s> add _ = aghhttp.WriteJSONResponse(w, r, resp) </s> remove language := strings.TrimSpace(string(body)) if language == "" { msg := "empty language specified" log.Println(msg) http.Error(w, msg, http.StatusBadRequest) </s> add langReq := &languageJSON{} err := json.NewDecoder(r.Body).Decode(langReq) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "reading req: %s", err) </s> remove if !allowedLanguages.Has(language) { msg := fmt.Sprintf("unknown language specified: %s", language) log.Println(msg) http.Error(w, msg, http.StatusBadRequest) </s> add lang := langReq.Language if !allowedLanguages.Has(lang) { aghhttp.Error(r, w, http.StatusBadRequest, "unknown language: %q", lang) </s> remove msg := fmt.Sprintf("failed to read request body: %s", err) log.Error(msg) http.Error(w, msg, http.StatusBadRequest) </s> add aghhttp.Error(r, w, http.StatusBadRequest, "reading req: %s", err)
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth.go
aghhttp.Error(r, w, http.StatusForbidden, "%s", err)
<mask> <mask> var cookie string <mask> cookie, err = Context.auth.httpCookie(req, remoteAddr) <mask> if err != nil { <mask> aghhttp.Error(r, w, http.StatusBadRequest, "crypto rand reader: %s", err) <mask> <mask> return <mask> } <mask> <mask> // Use realIP here, since this IP address is only used for logging. </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove var cookie string cookie, err = Context.auth.httpCookie(req, remoteAddr) </s> add cookie, err := Context.auth.newCookie(req, remoteAddr) </s> remove msg := fmt.Sprintf("failed to read request body: %s", err) log.Error(msg) http.Error(w, msg, http.StatusBadRequest) </s> add aghhttp.Error(r, w, http.StatusBadRequest, "reading req: %s", err) </s> remove w.Header().Set("Content-Type", "application/json") err = json.NewEncoder(w).Encode(resp) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "Unable to write response json: %s", err) return } </s> add _ = aghhttp.WriteJSONResponse(w, r, resp) </s> remove w.Header().Set("Content-Type", "application/json") err = json.NewEncoder(w).Encode(resp) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "encoding the response: %s", err) return } </s> add _ = aghhttp.WriteJSONResponse(w, r, resp) </s> remove language := strings.TrimSpace(string(body)) if language == "" { msg := "empty language specified" log.Println(msg) http.Error(w, msg, http.StatusBadRequest) </s> add langReq := &languageJSON{} err := json.NewDecoder(r.Body).Decode(langReq) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "reading req: %s", err)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth.go
<mask> // Technically shouldn't happen. <mask> log.Error("auth: unknown ip") <mask> } <mask> <mask> if len(cookie) == 0 { <mask> log.Info("auth: failed to login user %q from ip %v", req.Name, ip) <mask> <mask> time.Sleep(1 * time.Second) <mask> <mask> http.Error(w, "invalid username or password", http.StatusBadRequest) <mask> <mask> return <mask> } <mask> <mask> log.Info("auth: user %q successfully logged in from ip %v", req.Name, ip) <mask> <mask> h := w.Header() <mask> h.Set("Set-Cookie", cookie) <mask> h.Set("Cache-Control", "no-store, no-cache, must-revalidate, proxy-revalidate") </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove h.Set("Set-Cookie", cookie) </s> add </s> remove cookie := r.Header.Get("Cookie") sess := parseCookie(cookie) </s> add respHdr := w.Header() c, err := r.Cookie(sessionCookieName) if err != nil { // The only error that is returned from r.Cookie is [http.ErrNoCookie]. // The user is already logged out. respHdr.Set("Location", "/login.html") w.WriteHeader(http.StatusFound) return } </s> remove if glProcessCookie(r) { log.Debug("auth: authentication was handled by GL-Inet submodule") ok = true } else if err == nil { r := Context.auth.checkSession(cookie.Value) if r == checkSessionOK { ok = true } else if r < 0 { log.Debug("auth: invalid cookie value: %s", cookie) } } else { // there's no Cookie, check Basic authentication user, pass, ok2 := r.BasicAuth() if ok2 { u := Context.auth.UserFind(user, pass) if len(u.Name) != 0 { ok = true } else { </s> add if err != nil { // The only error that is returned from r.Cookie is [http.ErrNoCookie]. // Check Basic authentication. user, pass, hasBasic := r.BasicAuth() if hasBasic { _, isAuthenticated = Context.auth.findUser(user, pass) if !isAuthenticated {
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth.go
http.SetCookie(w, cookie)
<mask> } <mask> <mask> log.Info("auth: user %q successfully logged in from ip %v", req.Name, ip) <mask> <mask> h := w.Header() <mask> h.Set("Cache-Control", "no-store, no-cache, must-revalidate, proxy-revalidate") <mask> h.Set("Pragma", "no-cache") <mask> h.Set("Expires", "0") <mask> <mask> aghhttp.OK(w) </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove h.Set("Set-Cookie", cookie) </s> add </s> remove if len(cookie) == 0 { log.Info("auth: failed to login user %q from ip %v", req.Name, ip) time.Sleep(1 * time.Second) http.Error(w, "invalid username or password", http.StatusBadRequest) return } </s> add </s> remove cookie := r.Header.Get("Cookie") sess := parseCookie(cookie) </s> add respHdr := w.Header() c, err := r.Cookie(sessionCookieName) if err != nil { // The only error that is returned from r.Cookie is [http.ErrNoCookie]. // The user is already logged out. respHdr.Set("Location", "/login.html") w.WriteHeader(http.StatusFound) return } </s> remove if glProcessCookie(r) { log.Debug("auth: authentication was handled by GL-Inet submodule") ok = true } else if err == nil { r := Context.auth.checkSession(cookie.Value) if r == checkSessionOK { ok = true } else if r < 0 { log.Debug("auth: invalid cookie value: %s", cookie) } } else { // there's no Cookie, check Basic authentication user, pass, ok2 := r.BasicAuth() if ok2 { u := Context.auth.UserFind(user, pass) if len(u.Name) != 0 { ok = true } else { </s> add if err != nil { // The only error that is returned from r.Cookie is [http.ErrNoCookie]. // Check Basic authentication. user, pass, hasBasic := r.BasicAuth() if hasBasic { _, isAuthenticated = Context.auth.findUser(user, pass) if !isAuthenticated {
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth.go
<mask> <mask> log.Info("auth: user %q successfully logged in from ip %v", req.Name, ip) <mask> <mask> h := w.Header() <mask> h.Set("Set-Cookie", cookie) <mask> h.Set("Cache-Control", "no-store, no-cache, must-revalidate, proxy-revalidate") <mask> h.Set("Pragma", "no-cache") <mask> h.Set("Expires", "0") <mask> <mask> aghhttp.OK(w) </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove if len(cookie) == 0 { log.Info("auth: failed to login user %q from ip %v", req.Name, ip) time.Sleep(1 * time.Second) http.Error(w, "invalid username or password", http.StatusBadRequest) return } </s> add </s> remove cookie := r.Header.Get("Cookie") sess := parseCookie(cookie) </s> add respHdr := w.Header() c, err := r.Cookie(sessionCookieName) if err != nil { // The only error that is returned from r.Cookie is [http.ErrNoCookie]. // The user is already logged out. respHdr.Set("Location", "/login.html") w.WriteHeader(http.StatusFound) return } </s> remove user := User{Name: "name"} </s> add user := webUser{Name: "name"}
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth.go
respHdr := w.Header() c, err := r.Cookie(sessionCookieName) if err != nil { // The only error that is returned from r.Cookie is [http.ErrNoCookie]. // The user is already logged out. respHdr.Set("Location", "/login.html") w.WriteHeader(http.StatusFound) return }
<mask> aghhttp.OK(w) <mask> } <mask> <mask> func handleLogout(w http.ResponseWriter, r *http.Request) { <mask> cookie := r.Header.Get("Cookie") <mask> sess := parseCookie(cookie) <mask> <mask> Context.auth.RemoveSession(sess) <mask> <mask> w.Header().Set("Location", "/login.html") <mask> </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove Context.auth.RemoveSession(sess) </s> add Context.auth.RemoveSession(c.Value) </s> remove w.Header().Set("Location", "/login.html") </s> add c = &http.Cookie{ Name: sessionCookieName, Value: "", Path: "/", Expires: time.Unix(0, 0), </s> remove if r.URL.Path == "/login.html" { // redirect to dashboard if already authenticated authRequired := Context.auth != nil && Context.auth.AuthRequired() </s> add p := r.URL.Path authRequired := Context.auth != nil && Context.auth.AuthRequired() if p == "/login.html" { </s> remove s := fmt.Sprintf("%s=; Path=/; HttpOnly; Expires=Thu, 01 Jan 1970 00:00:00 GMT", sessionCookieName) w.Header().Set("Set-Cookie", s) </s> add HttpOnly: true, SameSite: http.SameSiteLaxMode, } </s> remove func optionalAuthThird(w http.ResponseWriter, r *http.Request) (authFirst bool) { authFirst = false </s> add func optionalAuthThird(w http.ResponseWriter, r *http.Request) (mustAuth bool) { if glProcessCookie(r) { log.Debug("auth: authentication is handled by GL-Inet submodule") return false }
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth.go
Context.auth.RemoveSession(c.Value)
<mask> func handleLogout(w http.ResponseWriter, r *http.Request) { <mask> cookie := r.Header.Get("Cookie") <mask> sess := parseCookie(cookie) <mask> <mask> Context.auth.RemoveSession(sess) <mask> <mask> w.Header().Set("Location", "/login.html") <mask> <mask> s := fmt.Sprintf("%s=; Path=/; HttpOnly; Expires=Thu, 01 Jan 1970 00:00:00 GMT", <mask> sessionCookieName) </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove w.Header().Set("Location", "/login.html") </s> add c = &http.Cookie{ Name: sessionCookieName, Value: "", Path: "/", Expires: time.Unix(0, 0), </s> remove s := fmt.Sprintf("%s=; Path=/; HttpOnly; Expires=Thu, 01 Jan 1970 00:00:00 GMT", sessionCookieName) w.Header().Set("Set-Cookie", s) </s> add HttpOnly: true, SameSite: http.SameSiteLaxMode, } </s> remove cookie := r.Header.Get("Cookie") sess := parseCookie(cookie) </s> add respHdr := w.Header() c, err := r.Cookie(sessionCookieName) if err != nil { // The only error that is returned from r.Cookie is [http.ErrNoCookie]. // The user is already logged out. respHdr.Set("Location", "/login.html") w.WriteHeader(http.StatusFound) return } </s> remove if r.URL.Path == "/login.html" { // redirect to dashboard if already authenticated authRequired := Context.auth != nil && Context.auth.AuthRequired() </s> add p := r.URL.Path authRequired := Context.auth != nil && Context.auth.AuthRequired() if p == "/login.html" { </s> remove func optionalAuthThird(w http.ResponseWriter, r *http.Request) (authFirst bool) { authFirst = false </s> add func optionalAuthThird(w http.ResponseWriter, r *http.Request) (mustAuth bool) { if glProcessCookie(r) { log.Debug("auth: authentication is handled by GL-Inet submodule") return false }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth.go
c = &http.Cookie{ Name: sessionCookieName, Value: "", Path: "/", Expires: time.Unix(0, 0),
<mask> sess := parseCookie(cookie) <mask> <mask> Context.auth.RemoveSession(sess) <mask> <mask> w.Header().Set("Location", "/login.html") <mask> <mask> s := fmt.Sprintf("%s=; Path=/; HttpOnly; Expires=Thu, 01 Jan 1970 00:00:00 GMT", <mask> sessionCookieName) <mask> w.Header().Set("Set-Cookie", s) <mask> </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove Context.auth.RemoveSession(sess) </s> add Context.auth.RemoveSession(c.Value) </s> remove s := fmt.Sprintf("%s=; Path=/; HttpOnly; Expires=Thu, 01 Jan 1970 00:00:00 GMT", sessionCookieName) w.Header().Set("Set-Cookie", s) </s> add HttpOnly: true, SameSite: http.SameSiteLaxMode, } </s> remove cookie := r.Header.Get("Cookie") sess := parseCookie(cookie) </s> add respHdr := w.Header() c, err := r.Cookie(sessionCookieName) if err != nil { // The only error that is returned from r.Cookie is [http.ErrNoCookie]. // The user is already logged out. respHdr.Set("Location", "/login.html") w.WriteHeader(http.StatusFound) return } </s> remove w.WriteHeader(http.StatusForbidden) _, _ = w.Write([]byte("Forbidden")) </s> add log.Debug("auth: redirected to login page") w.Header().Set("Location", "/login.html") w.WriteHeader(http.StatusFound) </s> remove user := User{Name: "name"} </s> add user := webUser{Name: "name"}
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth.go
HttpOnly: true, SameSite: http.SameSiteLaxMode, }
<mask> Context.auth.RemoveSession(sess) <mask> <mask> w.Header().Set("Location", "/login.html") <mask> <mask> s := fmt.Sprintf("%s=; Path=/; HttpOnly; Expires=Thu, 01 Jan 1970 00:00:00 GMT", <mask> sessionCookieName) <mask> w.Header().Set("Set-Cookie", s) <mask> <mask> w.WriteHeader(http.StatusFound) <mask> } <mask> <mask> // RegisterAuthHandlers - register handlers </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove w.Header().Set("Location", "/login.html") </s> add c = &http.Cookie{ Name: sessionCookieName, Value: "", Path: "/", Expires: time.Unix(0, 0), </s> remove Context.auth.RemoveSession(sess) </s> add Context.auth.RemoveSession(c.Value) </s> remove w.WriteHeader(http.StatusForbidden) _, _ = w.Write([]byte("Forbidden")) </s> add log.Debug("auth: redirected to login page") w.Header().Set("Location", "/login.html") w.WriteHeader(http.StatusFound) </s> remove cookie := r.Header.Get("Cookie") sess := parseCookie(cookie) </s> add respHdr := w.Header() c, err := r.Cookie(sessionCookieName) if err != nil { // The only error that is returned from r.Cookie is [http.ErrNoCookie]. // The user is already logged out. respHdr.Set("Location", "/login.html") w.WriteHeader(http.StatusFound) return }
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth.go
respHdr.Set("Location", "/login.html") respHdr.Set("Set-Cookie", c.String())
<mask> SameSite: http.SameSiteLaxMode, <mask> } <mask> <mask> w.WriteHeader(http.StatusFound) <mask> } <mask> <mask> // RegisterAuthHandlers - register handlers </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove s := fmt.Sprintf("%s=; Path=/; HttpOnly; Expires=Thu, 01 Jan 1970 00:00:00 GMT", sessionCookieName) w.Header().Set("Set-Cookie", s) </s> add HttpOnly: true, SameSite: http.SameSiteLaxMode, } </s> remove w.WriteHeader(http.StatusForbidden) _, _ = w.Write([]byte("Forbidden")) </s> add log.Debug("auth: redirected to login page") w.Header().Set("Location", "/login.html") w.WriteHeader(http.StatusFound) </s> remove return fmt.Sprintf( "%s=%s; Path=/; HttpOnly; Expires=%s", sessionCookieName, hex.EncodeToString(sess), cookieExpiryFormat(now.Add(cookieTTL)), ), nil </s> add return &http.Cookie{ Name: sessionCookieName, Value: hex.EncodeToString(sess), Path: "/", Expires: now.Add(cookieTTL), HttpOnly: true, SameSite: http.SameSiteLaxMode, }, nil </s> remove } else if r == checkSessionNotFound { log.Debug("auth: invalid cookie value: %s", cookie) </s> add </s> remove w.Header().Set("Content-Type", "application/json") err = json.NewEncoder(w).Encode(data) if err != nil { aghhttp.Error( r, w, http.StatusInternalServerError, "Unable to marshal default addresses to json: %s", err, ) return } </s> add _ = aghhttp.WriteJSONResponse(w, r, data)
[ "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth.go
<mask> Context.mux.Handle("/control/login", postInstallHandler(ensureHandler(http.MethodPost, handleLogin))) <mask> httpRegister(http.MethodGet, "/control/logout", handleLogout) <mask> } <mask> <mask> func parseCookie(cookie string) string { <mask> pairs := strings.Split(cookie, ";") <mask> for _, pair := range pairs { <mask> pair = strings.TrimSpace(pair) <mask> kv := strings.SplitN(pair, "=", 2) <mask> if len(kv) != 2 { <mask> continue <mask> } <mask> if kv[0] == sessionCookieName { <mask> return kv[1] <mask> } <mask> } <mask> return "" <mask> } <mask> <mask> // optionalAuthThird return true if user should authenticate first. <mask> func optionalAuthThird(w http.ResponseWriter, r *http.Request) (authFirst bool) { <mask> authFirst = false <mask> <mask> // redirect to login page if not authenticated </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove func optionalAuthThird(w http.ResponseWriter, r *http.Request) (authFirst bool) { authFirst = false </s> add func optionalAuthThird(w http.ResponseWriter, r *http.Request) (mustAuth bool) { if glProcessCookie(r) { log.Debug("auth: authentication is handled by GL-Inet submodule") return false } </s> remove ok := false </s> add isAuthenticated := false </s> remove return authFirst </s> add return true </s> remove for _, u := range a.users { </s> add for _, u = range a.users { </s> remove if !ok { if r.URL.Path == "/" || r.URL.Path == "/index.html" { if glProcessRedirect(w, r) { log.Debug("auth: redirected to login page by GL-Inet submodule") } else { w.Header().Set("Location", "/login.html") w.WriteHeader(http.StatusFound) } </s> add if isAuthenticated { return false } if p := r.URL.Path; p == "/" || p == "/index.html" { if glProcessRedirect(w, r) { log.Debug("auth: redirected to login page by GL-Inet submodule")
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth.go
func optionalAuthThird(w http.ResponseWriter, r *http.Request) (mustAuth bool) { if glProcessCookie(r) { log.Debug("auth: authentication is handled by GL-Inet submodule") return false }
<mask> return "" <mask> } <mask> <mask> // optionalAuthThird return true if user should authenticate first. <mask> func optionalAuthThird(w http.ResponseWriter, r *http.Request) (authFirst bool) { <mask> authFirst = false <mask> <mask> // redirect to login page if not authenticated <mask> ok := false <mask> cookie, err := r.Cookie(sessionCookieName) <mask> </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove ok := false </s> add isAuthenticated := false </s> remove func parseCookie(cookie string) string { pairs := strings.Split(cookie, ";") for _, pair := range pairs { pair = strings.TrimSpace(pair) kv := strings.SplitN(pair, "=", 2) if len(kv) != 2 { continue } if kv[0] == sessionCookieName { return kv[1] } } return "" } </s> add </s> remove if glProcessCookie(r) { log.Debug("auth: authentication was handled by GL-Inet submodule") ok = true } else if err == nil { r := Context.auth.checkSession(cookie.Value) if r == checkSessionOK { ok = true } else if r < 0 { log.Debug("auth: invalid cookie value: %s", cookie) } } else { // there's no Cookie, check Basic authentication user, pass, ok2 := r.BasicAuth() if ok2 { u := Context.auth.UserFind(user, pass) if len(u.Name) != 0 { ok = true } else { </s> add if err != nil { // The only error that is returned from r.Cookie is [http.ErrNoCookie]. // Check Basic authentication. user, pass, hasBasic := r.BasicAuth() if hasBasic { _, isAuthenticated = Context.auth.findUser(user, pass) if !isAuthenticated { </s> remove func optionalAuth(handler func(http.ResponseWriter, *http.Request)) func(http.ResponseWriter, *http.Request) { </s> add // TODO(a.garipov): Use [http.Handler] consistently everywhere throughout the // project. func optionalAuth( h func(http.ResponseWriter, *http.Request), ) (wrapped func(http.ResponseWriter, *http.Request)) { </s> remove if r.URL.Path == "/login.html" { // redirect to dashboard if already authenticated authRequired := Context.auth != nil && Context.auth.AuthRequired() </s> add p := r.URL.Path authRequired := Context.auth != nil && Context.auth.AuthRequired() if p == "/login.html" {
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth.go
isAuthenticated := false
<mask> func optionalAuthThird(w http.ResponseWriter, r *http.Request) (authFirst bool) { <mask> authFirst = false <mask> <mask> // redirect to login page if not authenticated <mask> ok := false <mask> cookie, err := r.Cookie(sessionCookieName) <mask> <mask> if glProcessCookie(r) { <mask> log.Debug("auth: authentication was handled by GL-Inet submodule") <mask> ok = true </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove func optionalAuthThird(w http.ResponseWriter, r *http.Request) (authFirst bool) { authFirst = false </s> add func optionalAuthThird(w http.ResponseWriter, r *http.Request) (mustAuth bool) { if glProcessCookie(r) { log.Debug("auth: authentication is handled by GL-Inet submodule") return false } </s> remove if glProcessCookie(r) { log.Debug("auth: authentication was handled by GL-Inet submodule") ok = true } else if err == nil { r := Context.auth.checkSession(cookie.Value) if r == checkSessionOK { ok = true } else if r < 0 { log.Debug("auth: invalid cookie value: %s", cookie) } } else { // there's no Cookie, check Basic authentication user, pass, ok2 := r.BasicAuth() if ok2 { u := Context.auth.UserFind(user, pass) if len(u.Name) != 0 { ok = true } else { </s> add if err != nil { // The only error that is returned from r.Cookie is [http.ErrNoCookie]. // Check Basic authentication. user, pass, hasBasic := r.BasicAuth() if hasBasic { _, isAuthenticated = Context.auth.findUser(user, pass) if !isAuthenticated { </s> remove func parseCookie(cookie string) string { pairs := strings.Split(cookie, ";") for _, pair := range pairs { pair = strings.TrimSpace(pair) kv := strings.SplitN(pair, "=", 2) if len(kv) != 2 { continue } if kv[0] == sessionCookieName { return kv[1] } } return "" } </s> add </s> remove if !ok { if r.URL.Path == "/" || r.URL.Path == "/index.html" { if glProcessRedirect(w, r) { log.Debug("auth: redirected to login page by GL-Inet submodule") } else { w.Header().Set("Location", "/login.html") w.WriteHeader(http.StatusFound) } </s> add if isAuthenticated { return false } if p := r.URL.Path; p == "/" || p == "/index.html" { if glProcessRedirect(w, r) { log.Debug("auth: redirected to login page by GL-Inet submodule") </s> remove func optionalAuth(handler func(http.ResponseWriter, *http.Request)) func(http.ResponseWriter, *http.Request) { </s> add // TODO(a.garipov): Use [http.Handler] consistently everywhere throughout the // project. func optionalAuth( h func(http.ResponseWriter, *http.Request), ) (wrapped func(http.ResponseWriter, *http.Request)) {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth.go
if err != nil { // The only error that is returned from r.Cookie is [http.ErrNoCookie]. // Check Basic authentication. user, pass, hasBasic := r.BasicAuth() if hasBasic { _, isAuthenticated = Context.auth.findUser(user, pass) if !isAuthenticated {
<mask> <mask> // redirect to login page if not authenticated <mask> ok := false <mask> cookie, err := r.Cookie(sessionCookieName) <mask> <mask> if glProcessCookie(r) { <mask> log.Debug("auth: authentication was handled by GL-Inet submodule") <mask> ok = true <mask> } else if err == nil { <mask> r := Context.auth.checkSession(cookie.Value) <mask> if r == checkSessionOK { <mask> ok = true <mask> } else if r < 0 { <mask> log.Debug("auth: invalid cookie value: %s", cookie) <mask> } <mask> } else { <mask> // there's no Cookie, check Basic authentication <mask> user, pass, ok2 := r.BasicAuth() <mask> if ok2 { <mask> u := Context.auth.UserFind(user, pass) <mask> if len(u.Name) != 0 { <mask> ok = true <mask> } else { <mask> log.Info("auth: invalid Basic Authorization value") <mask> } <mask> } <mask> } <mask> if !ok { </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove ok := false </s> add isAuthenticated := false </s> remove if !ok { if r.URL.Path == "/" || r.URL.Path == "/index.html" { if glProcessRedirect(w, r) { log.Debug("auth: redirected to login page by GL-Inet submodule") } else { w.Header().Set("Location", "/login.html") w.WriteHeader(http.StatusFound) } </s> add if isAuthenticated { return false } if p := r.URL.Path; p == "/" || p == "/index.html" { if glProcessRedirect(w, r) { log.Debug("auth: redirected to login page by GL-Inet submodule") </s> remove func optionalAuthThird(w http.ResponseWriter, r *http.Request) (authFirst bool) { authFirst = false </s> add func optionalAuthThird(w http.ResponseWriter, r *http.Request) (mustAuth bool) { if glProcessCookie(r) { log.Debug("auth: authentication is handled by GL-Inet submodule") return false } </s> remove return Context.auth.UserFind(user, pass) </s> add u, _ = Context.auth.findUser(user, pass) return u
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth.go
} else { res := Context.auth.checkSession(cookie.Value) isAuthenticated = res == checkSessionOK if !isAuthenticated { log.Debug("auth: invalid cookie value: %s", cookie) }
<mask> log.Info("auth: invalid Basic Authorization value") <mask> } <mask> } <mask> } <mask> <mask> if isAuthenticated { <mask> return false </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove if !ok { if r.URL.Path == "/" || r.URL.Path == "/index.html" { if glProcessRedirect(w, r) { log.Debug("auth: redirected to login page by GL-Inet submodule") } else { w.Header().Set("Location", "/login.html") w.WriteHeader(http.StatusFound) } </s> add if isAuthenticated { return false } if p := r.URL.Path; p == "/" || p == "/index.html" { if glProcessRedirect(w, r) { log.Debug("auth: redirected to login page by GL-Inet submodule") </s> remove if glProcessCookie(r) { log.Debug("auth: authentication was handled by GL-Inet submodule") ok = true } else if err == nil { r := Context.auth.checkSession(cookie.Value) if r == checkSessionOK { ok = true } else if r < 0 { log.Debug("auth: invalid cookie value: %s", cookie) } } else { // there's no Cookie, check Basic authentication user, pass, ok2 := r.BasicAuth() if ok2 { u := Context.auth.UserFind(user, pass) if len(u.Name) != 0 { ok = true } else { </s> add if err != nil { // The only error that is returned from r.Cookie is [http.ErrNoCookie]. // Check Basic authentication. user, pass, hasBasic := r.BasicAuth() if hasBasic { _, isAuthenticated = Context.auth.findUser(user, pass) if !isAuthenticated { </s> remove } else if strings.HasPrefix(r.URL.Path, "/assets/") || strings.HasPrefix(r.URL.Path, "/login.") { // process as usual // no additional auth requirements } else if Context.auth != nil && Context.auth.AuthRequired() { </s> add log.Debug("auth: invalid cookie value: %s", cookie) } } else if isPublicResource(p) { // Process as usual, no additional auth requirements. } else if authRequired { </s> remove } else if r == checkSessionNotFound { log.Debug("auth: invalid cookie value: %s", cookie) </s> add </s> remove } </s> add
[ "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth.go
if isAuthenticated { return false } if p := r.URL.Path; p == "/" || p == "/index.html" { if glProcessRedirect(w, r) { log.Debug("auth: redirected to login page by GL-Inet submodule")
<mask> log.Info("auth: invalid Basic Authorization value") <mask> } <mask> } <mask> } <mask> if !ok { <mask> if r.URL.Path == "/" || r.URL.Path == "/index.html" { <mask> if glProcessRedirect(w, r) { <mask> log.Debug("auth: redirected to login page by GL-Inet submodule") <mask> } else { <mask> w.Header().Set("Location", "/login.html") <mask> w.WriteHeader(http.StatusFound) <mask> } <mask> } else { <mask> w.WriteHeader(http.StatusForbidden) <mask> _, _ = w.Write([]byte("Forbidden")) <mask> } <mask> authFirst = true </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove w.WriteHeader(http.StatusForbidden) _, _ = w.Write([]byte("Forbidden")) </s> add log.Debug("auth: redirected to login page") w.Header().Set("Location", "/login.html") w.WriteHeader(http.StatusFound) </s> remove if glProcessCookie(r) { log.Debug("auth: authentication was handled by GL-Inet submodule") ok = true } else if err == nil { r := Context.auth.checkSession(cookie.Value) if r == checkSessionOK { ok = true } else if r < 0 { log.Debug("auth: invalid cookie value: %s", cookie) } } else { // there's no Cookie, check Basic authentication user, pass, ok2 := r.BasicAuth() if ok2 { u := Context.auth.UserFind(user, pass) if len(u.Name) != 0 { ok = true } else { </s> add if err != nil { // The only error that is returned from r.Cookie is [http.ErrNoCookie]. // Check Basic authentication. user, pass, hasBasic := r.BasicAuth() if hasBasic { _, isAuthenticated = Context.auth.findUser(user, pass) if !isAuthenticated { </s> remove authFirst = true </s> add } else { log.Debug("auth: responded with forbidden to %s %s", r.Method, p) w.WriteHeader(http.StatusForbidden) _, _ = w.Write([]byte("Forbidden")) </s> remove } else if r == checkSessionNotFound { log.Debug("auth: invalid cookie value: %s", cookie) </s> add
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth.go
log.Debug("auth: redirected to login page") w.Header().Set("Location", "/login.html") w.WriteHeader(http.StatusFound)
<mask> w.Header().Set("Location", "/login.html") <mask> w.WriteHeader(http.StatusFound) <mask> } <mask> } else { <mask> w.WriteHeader(http.StatusForbidden) <mask> _, _ = w.Write([]byte("Forbidden")) <mask> } <mask> authFirst = true <mask> } <mask> <mask> return authFirst </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove authFirst = true </s> add } else { log.Debug("auth: responded with forbidden to %s %s", r.Method, p) w.WriteHeader(http.StatusForbidden) _, _ = w.Write([]byte("Forbidden")) </s> remove if !ok { if r.URL.Path == "/" || r.URL.Path == "/index.html" { if glProcessRedirect(w, r) { log.Debug("auth: redirected to login page by GL-Inet submodule") } else { w.Header().Set("Location", "/login.html") w.WriteHeader(http.StatusFound) } </s> add if isAuthenticated { return false } if p := r.URL.Path; p == "/" || p == "/index.html" { if glProcessRedirect(w, r) { log.Debug("auth: redirected to login page by GL-Inet submodule") </s> remove return authFirst </s> add return true </s> remove } else if r == checkSessionNotFound { log.Debug("auth: invalid cookie value: %s", cookie) </s> add </s> remove func parseCookie(cookie string) string { pairs := strings.Split(cookie, ";") for _, pair := range pairs { pair = strings.TrimSpace(pair) kv := strings.SplitN(pair, "=", 2) if len(kv) != 2 { continue } if kv[0] == sessionCookieName { return kv[1] } } return "" } </s> add
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth.go
} else { log.Debug("auth: responded with forbidden to %s %s", r.Method, p) w.WriteHeader(http.StatusForbidden) _, _ = w.Write([]byte("Forbidden"))
<mask> } else { <mask> w.WriteHeader(http.StatusForbidden) <mask> _, _ = w.Write([]byte("Forbidden")) <mask> } <mask> authFirst = true <mask> } <mask> <mask> return authFirst <mask> } <mask> </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove w.WriteHeader(http.StatusForbidden) _, _ = w.Write([]byte("Forbidden")) </s> add log.Debug("auth: redirected to login page") w.Header().Set("Location", "/login.html") w.WriteHeader(http.StatusFound) </s> remove if !ok { if r.URL.Path == "/" || r.URL.Path == "/index.html" { if glProcessRedirect(w, r) { log.Debug("auth: redirected to login page by GL-Inet submodule") } else { w.Header().Set("Location", "/login.html") w.WriteHeader(http.StatusFound) } </s> add if isAuthenticated { return false } if p := r.URL.Path; p == "/" || p == "/index.html" { if glProcessRedirect(w, r) { log.Debug("auth: redirected to login page by GL-Inet submodule") </s> remove return authFirst </s> add return true </s> remove func parseCookie(cookie string) string { pairs := strings.Split(cookie, ";") for _, pair := range pairs { pair = strings.TrimSpace(pair) kv := strings.SplitN(pair, "=", 2) if len(kv) != 2 { continue } if kv[0] == sessionCookieName { return kv[1] } } return "" } </s> add </s> remove return u </s> add return u, true
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth.go
return true
<mask> } <mask> authFirst = true <mask> } <mask> <mask> return authFirst <mask> } <mask> <mask> func optionalAuth(handler func(http.ResponseWriter, *http.Request)) func(http.ResponseWriter, *http.Request) { <mask> return func(w http.ResponseWriter, r *http.Request) { <mask> if r.URL.Path == "/login.html" { </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove func optionalAuth(handler func(http.ResponseWriter, *http.Request)) func(http.ResponseWriter, *http.Request) { </s> add // TODO(a.garipov): Use [http.Handler] consistently everywhere throughout the // project. func optionalAuth( h func(http.ResponseWriter, *http.Request), ) (wrapped func(http.ResponseWriter, *http.Request)) { </s> remove if r.URL.Path == "/login.html" { // redirect to dashboard if already authenticated authRequired := Context.auth != nil && Context.auth.AuthRequired() </s> add p := r.URL.Path authRequired := Context.auth != nil && Context.auth.AuthRequired() if p == "/login.html" { </s> remove func optionalAuthThird(w http.ResponseWriter, r *http.Request) (authFirst bool) { authFirst = false </s> add func optionalAuthThird(w http.ResponseWriter, r *http.Request) (mustAuth bool) { if glProcessCookie(r) { log.Debug("auth: authentication is handled by GL-Inet submodule") return false } </s> remove func parseCookie(cookie string) string { pairs := strings.Split(cookie, ";") for _, pair := range pairs { pair = strings.TrimSpace(pair) kv := strings.SplitN(pair, "=", 2) if len(kv) != 2 { continue } if kv[0] == sessionCookieName { return kv[1] } } return "" } </s> add </s> remove if !ok { if r.URL.Path == "/" || r.URL.Path == "/index.html" { if glProcessRedirect(w, r) { log.Debug("auth: redirected to login page by GL-Inet submodule") } else { w.Header().Set("Location", "/login.html") w.WriteHeader(http.StatusFound) } </s> add if isAuthenticated { return false } if p := r.URL.Path; p == "/" || p == "/index.html" { if glProcessRedirect(w, r) { log.Debug("auth: redirected to login page by GL-Inet submodule")
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth.go
// TODO(a.garipov): Use [http.Handler] consistently everywhere throughout the // project. func optionalAuth( h func(http.ResponseWriter, *http.Request), ) (wrapped func(http.ResponseWriter, *http.Request)) {
<mask> <mask> return authFirst <mask> } <mask> <mask> func optionalAuth(handler func(http.ResponseWriter, *http.Request)) func(http.ResponseWriter, *http.Request) { <mask> return func(w http.ResponseWriter, r *http.Request) { <mask> if r.URL.Path == "/login.html" { <mask> // redirect to dashboard if already authenticated <mask> authRequired := Context.auth != nil && Context.auth.AuthRequired() <mask> cookie, err := r.Cookie(sessionCookieName) </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove if r.URL.Path == "/login.html" { // redirect to dashboard if already authenticated authRequired := Context.auth != nil && Context.auth.AuthRequired() </s> add p := r.URL.Path authRequired := Context.auth != nil && Context.auth.AuthRequired() if p == "/login.html" { </s> remove return authFirst </s> add return true </s> remove r := Context.auth.checkSession(cookie.Value) if r == checkSessionOK { </s> add // Redirect to the dashboard if already authenticated. res := Context.auth.checkSession(cookie.Value) if res == checkSessionOK { </s> remove func optionalAuthThird(w http.ResponseWriter, r *http.Request) (authFirst bool) { authFirst = false </s> add func optionalAuthThird(w http.ResponseWriter, r *http.Request) (mustAuth bool) { if glProcessCookie(r) { log.Debug("auth: authentication is handled by GL-Inet submodule") return false } </s> remove ok := false </s> add isAuthenticated := false
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth.go
p := r.URL.Path authRequired := Context.auth != nil && Context.auth.AuthRequired() if p == "/login.html" {
<mask> } <mask> <mask> func optionalAuth(handler func(http.ResponseWriter, *http.Request)) func(http.ResponseWriter, *http.Request) { <mask> return func(w http.ResponseWriter, r *http.Request) { <mask> if r.URL.Path == "/login.html" { <mask> // redirect to dashboard if already authenticated <mask> authRequired := Context.auth != nil && Context.auth.AuthRequired() <mask> cookie, err := r.Cookie(sessionCookieName) <mask> if authRequired && err == nil { <mask> r := Context.auth.checkSession(cookie.Value) <mask> if r == checkSessionOK { <mask> w.Header().Set("Location", "/") </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove func optionalAuth(handler func(http.ResponseWriter, *http.Request)) func(http.ResponseWriter, *http.Request) { </s> add // TODO(a.garipov): Use [http.Handler] consistently everywhere throughout the // project. func optionalAuth( h func(http.ResponseWriter, *http.Request), ) (wrapped func(http.ResponseWriter, *http.Request)) { </s> remove r := Context.auth.checkSession(cookie.Value) if r == checkSessionOK { </s> add // Redirect to the dashboard if already authenticated. res := Context.auth.checkSession(cookie.Value) if res == checkSessionOK { </s> remove return authFirst </s> add return true </s> remove func optionalAuthThird(w http.ResponseWriter, r *http.Request) (authFirst bool) { authFirst = false </s> add func optionalAuthThird(w http.ResponseWriter, r *http.Request) (mustAuth bool) { if glProcessCookie(r) { log.Debug("auth: authentication is handled by GL-Inet submodule") return false } </s> remove if glProcessCookie(r) { log.Debug("auth: authentication was handled by GL-Inet submodule") ok = true } else if err == nil { r := Context.auth.checkSession(cookie.Value) if r == checkSessionOK { ok = true } else if r < 0 { log.Debug("auth: invalid cookie value: %s", cookie) } } else { // there's no Cookie, check Basic authentication user, pass, ok2 := r.BasicAuth() if ok2 { u := Context.auth.UserFind(user, pass) if len(u.Name) != 0 { ok = true } else { </s> add if err != nil { // The only error that is returned from r.Cookie is [http.ErrNoCookie]. // Check Basic authentication. user, pass, hasBasic := r.BasicAuth() if hasBasic { _, isAuthenticated = Context.auth.findUser(user, pass) if !isAuthenticated {
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth.go
// Redirect to the dashboard if already authenticated. res := Context.auth.checkSession(cookie.Value) if res == checkSessionOK {
<mask> // redirect to dashboard if already authenticated <mask> authRequired := Context.auth != nil && Context.auth.AuthRequired() <mask> cookie, err := r.Cookie(sessionCookieName) <mask> if authRequired && err == nil { <mask> r := Context.auth.checkSession(cookie.Value) <mask> if r == checkSessionOK { <mask> w.Header().Set("Location", "/") <mask> w.WriteHeader(http.StatusFound) <mask> <mask> return <mask> } else if r == checkSessionNotFound { </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove if r.URL.Path == "/login.html" { // redirect to dashboard if already authenticated authRequired := Context.auth != nil && Context.auth.AuthRequired() </s> add p := r.URL.Path authRequired := Context.auth != nil && Context.auth.AuthRequired() if p == "/login.html" { </s> remove func optionalAuth(handler func(http.ResponseWriter, *http.Request)) func(http.ResponseWriter, *http.Request) { </s> add // TODO(a.garipov): Use [http.Handler] consistently everywhere throughout the // project. func optionalAuth( h func(http.ResponseWriter, *http.Request), ) (wrapped func(http.ResponseWriter, *http.Request)) { </s> remove } else if r == checkSessionNotFound { log.Debug("auth: invalid cookie value: %s", cookie) </s> add </s> remove if glProcessCookie(r) { log.Debug("auth: authentication was handled by GL-Inet submodule") ok = true } else if err == nil { r := Context.auth.checkSession(cookie.Value) if r == checkSessionOK { ok = true } else if r < 0 { log.Debug("auth: invalid cookie value: %s", cookie) } } else { // there's no Cookie, check Basic authentication user, pass, ok2 := r.BasicAuth() if ok2 { u := Context.auth.UserFind(user, pass) if len(u.Name) != 0 { ok = true } else { </s> add if err != nil { // The only error that is returned from r.Cookie is [http.ErrNoCookie]. // Check Basic authentication. user, pass, hasBasic := r.BasicAuth() if hasBasic { _, isAuthenticated = Context.auth.findUser(user, pass) if !isAuthenticated { </s> remove } else if strings.HasPrefix(r.URL.Path, "/assets/") || strings.HasPrefix(r.URL.Path, "/login.") { // process as usual // no additional auth requirements } else if Context.auth != nil && Context.auth.AuthRequired() { </s> add log.Debug("auth: invalid cookie value: %s", cookie) } } else if isPublicResource(p) { // Process as usual, no additional auth requirements. } else if authRequired {
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth.go
<mask> w.Header().Set("Location", "/") <mask> w.WriteHeader(http.StatusFound) <mask> <mask> return <mask> } else if r == checkSessionNotFound { <mask> log.Debug("auth: invalid cookie value: %s", cookie) <mask> } <mask> } <mask> <mask> } else if strings.HasPrefix(r.URL.Path, "/assets/") || <mask> strings.HasPrefix(r.URL.Path, "/login.") { </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove } </s> add </s> remove } else if strings.HasPrefix(r.URL.Path, "/assets/") || strings.HasPrefix(r.URL.Path, "/login.") { // process as usual // no additional auth requirements } else if Context.auth != nil && Context.auth.AuthRequired() { </s> add log.Debug("auth: invalid cookie value: %s", cookie) } } else if isPublicResource(p) { // Process as usual, no additional auth requirements. } else if authRequired { </s> remove if !ok { if r.URL.Path == "/" || r.URL.Path == "/index.html" { if glProcessRedirect(w, r) { log.Debug("auth: redirected to login page by GL-Inet submodule") } else { w.Header().Set("Location", "/login.html") w.WriteHeader(http.StatusFound) } </s> add if isAuthenticated { return false } if p := r.URL.Path; p == "/" || p == "/index.html" { if glProcessRedirect(w, r) { log.Debug("auth: redirected to login page by GL-Inet submodule") </s> remove if glProcessCookie(r) { log.Debug("auth: authentication was handled by GL-Inet submodule") ok = true } else if err == nil { r := Context.auth.checkSession(cookie.Value) if r == checkSessionOK { ok = true } else if r < 0 { log.Debug("auth: invalid cookie value: %s", cookie) } } else { // there's no Cookie, check Basic authentication user, pass, ok2 := r.BasicAuth() if ok2 { u := Context.auth.UserFind(user, pass) if len(u.Name) != 0 { ok = true } else { </s> add if err != nil { // The only error that is returned from r.Cookie is [http.ErrNoCookie]. // Check Basic authentication. user, pass, hasBasic := r.BasicAuth() if hasBasic { _, isAuthenticated = Context.auth.findUser(user, pass) if !isAuthenticated {
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth.go
<mask> return <mask> } else if r == checkSessionNotFound { <mask> log.Debug("auth: invalid cookie value: %s", cookie) <mask> } <mask> } <mask> <mask> } else if strings.HasPrefix(r.URL.Path, "/assets/") || <mask> strings.HasPrefix(r.URL.Path, "/login.") { <mask> // process as usual <mask> // no additional auth requirements </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove } else if strings.HasPrefix(r.URL.Path, "/assets/") || strings.HasPrefix(r.URL.Path, "/login.") { // process as usual // no additional auth requirements } else if Context.auth != nil && Context.auth.AuthRequired() { </s> add log.Debug("auth: invalid cookie value: %s", cookie) } } else if isPublicResource(p) { // Process as usual, no additional auth requirements. } else if authRequired { </s> remove } else if r == checkSessionNotFound { log.Debug("auth: invalid cookie value: %s", cookie) </s> add </s> remove if glProcessCookie(r) { log.Debug("auth: authentication was handled by GL-Inet submodule") ok = true } else if err == nil { r := Context.auth.checkSession(cookie.Value) if r == checkSessionOK { ok = true } else if r < 0 { log.Debug("auth: invalid cookie value: %s", cookie) } } else { // there's no Cookie, check Basic authentication user, pass, ok2 := r.BasicAuth() if ok2 { u := Context.auth.UserFind(user, pass) if len(u.Name) != 0 { ok = true } else { </s> add if err != nil { // The only error that is returned from r.Cookie is [http.ErrNoCookie]. // Check Basic authentication. user, pass, hasBasic := r.BasicAuth() if hasBasic { _, isAuthenticated = Context.auth.findUser(user, pass) if !isAuthenticated { </s> remove if !ok { if r.URL.Path == "/" || r.URL.Path == "/index.html" { if glProcessRedirect(w, r) { log.Debug("auth: redirected to login page by GL-Inet submodule") } else { w.Header().Set("Location", "/login.html") w.WriteHeader(http.StatusFound) } </s> add if isAuthenticated { return false } if p := r.URL.Path; p == "/" || p == "/index.html" { if glProcessRedirect(w, r) { log.Debug("auth: redirected to login page by GL-Inet submodule")
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth.go
log.Debug("auth: invalid cookie value: %s", cookie) } } else if isPublicResource(p) { // Process as usual, no additional auth requirements. } else if authRequired {
<mask> log.Debug("auth: invalid cookie value: %s", cookie) <mask> } <mask> } <mask> <mask> } else if strings.HasPrefix(r.URL.Path, "/assets/") || <mask> strings.HasPrefix(r.URL.Path, "/login.") { <mask> // process as usual <mask> // no additional auth requirements <mask> } else if Context.auth != nil && Context.auth.AuthRequired() { <mask> if optionalAuthThird(w, r) { <mask> return <mask> } <mask> } <mask> </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove } </s> add </s> remove } else if r == checkSessionNotFound { log.Debug("auth: invalid cookie value: %s", cookie) </s> add </s> remove if !ok { if r.URL.Path == "/" || r.URL.Path == "/index.html" { if glProcessRedirect(w, r) { log.Debug("auth: redirected to login page by GL-Inet submodule") } else { w.Header().Set("Location", "/login.html") w.WriteHeader(http.StatusFound) } </s> add if isAuthenticated { return false } if p := r.URL.Path; p == "/" || p == "/index.html" { if glProcessRedirect(w, r) { log.Debug("auth: redirected to login page by GL-Inet submodule") </s> remove if glProcessCookie(r) { log.Debug("auth: authentication was handled by GL-Inet submodule") ok = true } else if err == nil { r := Context.auth.checkSession(cookie.Value) if r == checkSessionOK { ok = true } else if r < 0 { log.Debug("auth: invalid cookie value: %s", cookie) } } else { // there's no Cookie, check Basic authentication user, pass, ok2 := r.BasicAuth() if ok2 { u := Context.auth.UserFind(user, pass) if len(u.Name) != 0 { ok = true } else { </s> add if err != nil { // The only error that is returned from r.Cookie is [http.ErrNoCookie]. // Check Basic authentication. user, pass, hasBasic := r.BasicAuth() if hasBasic { _, isAuthenticated = Context.auth.findUser(user, pass) if !isAuthenticated {
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth.go
h(w, r)
<mask> return <mask> } <mask> } <mask> <mask> handler(w, r) <mask> } <mask> } <mask> <mask> type authHandler struct { <mask> handler http.Handler </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove w.Header().Set("Content-Type", "application/json") err = json.NewEncoder(w).Encode(resp) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "Unable to write response json: %s", err) return } </s> add _ = aghhttp.WriteJSONResponse(w, r, resp) </s> remove // User object type User struct { </s> add // webUser represents a user of the Web UI. type webUser struct { </s> remove db *bbolt.DB blocker *authRateLimiter sessions map[string]*session users []User lock sync.Mutex sessionTTL uint32 </s> add db *bbolt.DB raleLimiter *authRateLimiter sessions map[string]*session users []webUser lock sync.Mutex sessionTTL uint32 </s> remove if !ok { if r.URL.Path == "/" || r.URL.Path == "/index.html" { if glProcessRedirect(w, r) { log.Debug("auth: redirected to login page by GL-Inet submodule") } else { w.Header().Set("Location", "/login.html") w.WriteHeader(http.StatusFound) } </s> add if isAuthenticated { return false } if p := r.URL.Path; p == "/" || p == "/index.html" { if glProcessRedirect(w, r) { log.Debug("auth: redirected to login page by GL-Inet submodule")
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth.go
func (a *Auth) UserAdd(u *webUser, password string) {
<mask> return &authHandler{handler} <mask> } <mask> <mask> // UserAdd - add new user <mask> func (a *Auth) UserAdd(u *User, password string) { <mask> if len(password) == 0 { <mask> return <mask> } <mask> <mask> hash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost) </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove // UserFind - find a user func (a *Auth) UserFind(login, password string) User { </s> add // findUser returns a user if there is one. func (a *Auth) findUser(login, password string) (u webUser, ok bool) { </s> remove for _, u := range a.users { </s> add for _, u = range a.users { </s> remove // cookieTimeFormat is the format to be used in (time.Time).Format for cookie's // expiry field. const cookieTimeFormat = "Mon, 02 Jan 2006 15:04:05 GMT" // cookieExpiryFormat returns the formatted exp to be used in cookie string. // It's quite simple for now, but probably will be expanded in the future. func cookieExpiryFormat(exp time.Time) (formatted string) { return exp.Format(cookieTimeFormat) } func (a *Auth) httpCookie(req loginJSON, addr string) (cookie string, err error) { blocker := a.blocker u := a.UserFind(req.Name, req.Password) if len(u.Name) == 0 { if blocker != nil { blocker.inc(addr) </s> add // newCookie creates a new authentication cookie. func (a *Auth) newCookie(req loginJSON, addr string) (c *http.Cookie, err error) { rateLimiter := a.raleLimiter u, ok := a.findUser(req.Name, req.Password) if !ok { if rateLimiter != nil { rateLimiter.inc(addr) </s> remove func (a *Auth) GetUsers() []User { </s> add func (a *Auth) GetUsers() []webUser { </s> remove return User{} </s> add return webUser{}
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth.go
// findUser returns a user if there is one. func (a *Auth) findUser(login, password string) (u webUser, ok bool) {
<mask> <mask> log.Debug("auth: added user: %s", u.Name) <mask> } <mask> <mask> // UserFind - find a user <mask> func (a *Auth) UserFind(login, password string) User { <mask> a.lock.Lock() <mask> defer a.lock.Unlock() <mask> for _, u := range a.users { <mask> if u.Name == login && <mask> bcrypt.CompareHashAndPassword([]byte(u.PasswordHash), []byte(password)) == nil { </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove for _, u := range a.users { </s> add for _, u = range a.users { </s> remove return u </s> add return u, true </s> remove return User{} </s> add return webUser{} </s> remove for _, u := range a.users { </s> add for _, u = range a.users { </s> remove func (a *Auth) UserAdd(u *User, password string) { </s> add func (a *Auth) UserAdd(u *webUser, password string) {
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth.go
for _, u = range a.users {
<mask> // UserFind - find a user <mask> func (a *Auth) UserFind(login, password string) User { <mask> a.lock.Lock() <mask> defer a.lock.Unlock() <mask> for _, u := range a.users { <mask> if u.Name == login && <mask> bcrypt.CompareHashAndPassword([]byte(u.PasswordHash), []byte(password)) == nil { <mask> return u <mask> } <mask> } </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove // UserFind - find a user func (a *Auth) UserFind(login, password string) User { </s> add // findUser returns a user if there is one. func (a *Auth) findUser(login, password string) (u webUser, ok bool) { </s> remove return u </s> add return u, true </s> remove return User{} </s> add return webUser{} </s> remove for _, u := range a.users { </s> add for _, u = range a.users { </s> remove func (a *Auth) UserAdd(u *User, password string) { </s> add func (a *Auth) UserAdd(u *webUser, password string) {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth.go
return u, true
<mask> defer a.lock.Unlock() <mask> for _, u := range a.users { <mask> if u.Name == login && <mask> bcrypt.CompareHashAndPassword([]byte(u.PasswordHash), []byte(password)) == nil { <mask> return u <mask> } <mask> } <mask> return User{} <mask> } <mask> </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove for _, u := range a.users { </s> add for _, u = range a.users { </s> remove return User{} </s> add return webUser{} </s> remove for _, u := range a.users { </s> add for _, u = range a.users { </s> remove // UserFind - find a user func (a *Auth) UserFind(login, password string) User { </s> add // findUser returns a user if there is one. func (a *Auth) findUser(login, password string) (u webUser, ok bool) { </s> remove return User{} </s> add return webUser{}, false
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth.go
return webUser{}, false
<mask> bcrypt.CompareHashAndPassword([]byte(u.PasswordHash), []byte(password)) == nil { <mask> return u <mask> } <mask> } <mask> return User{} <mask> } <mask> <mask> // getCurrentUser returns the current user. It returns an empty User if the <mask> // user is not found. <mask> func (a *Auth) getCurrentUser(r *http.Request) User { </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove func (a *Auth) getCurrentUser(r *http.Request) User { </s> add func (a *Auth) getCurrentUser(r *http.Request) (u webUser) { </s> remove // UserFind - find a user func (a *Auth) UserFind(login, password string) User { </s> add // findUser returns a user if there is one. func (a *Auth) findUser(login, password string) (u webUser, ok bool) { </s> remove for _, u := range a.users { </s> add for _, u = range a.users { </s> remove return u </s> add return u, true </s> remove return User{} </s> add return webUser{}
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth.go
func (a *Auth) getCurrentUser(r *http.Request) (u webUser) {
<mask> } <mask> <mask> // getCurrentUser returns the current user. It returns an empty User if the <mask> // user is not found. <mask> func (a *Auth) getCurrentUser(r *http.Request) User { <mask> cookie, err := r.Cookie(sessionCookieName) <mask> if err != nil { <mask> // There's no Cookie, check Basic authentication. <mask> user, pass, ok := r.BasicAuth() <mask> if ok { </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove return User{} </s> add return webUser{}, false </s> remove return Context.auth.UserFind(user, pass) </s> add u, _ = Context.auth.findUser(user, pass) return u </s> remove if glProcessCookie(r) { log.Debug("auth: authentication was handled by GL-Inet submodule") ok = true } else if err == nil { r := Context.auth.checkSession(cookie.Value) if r == checkSessionOK { ok = true } else if r < 0 { log.Debug("auth: invalid cookie value: %s", cookie) } } else { // there's no Cookie, check Basic authentication user, pass, ok2 := r.BasicAuth() if ok2 { u := Context.auth.UserFind(user, pass) if len(u.Name) != 0 { ok = true } else { </s> add if err != nil { // The only error that is returned from r.Cookie is [http.ErrNoCookie]. // Check Basic authentication. user, pass, hasBasic := r.BasicAuth() if hasBasic { _, isAuthenticated = Context.auth.findUser(user, pass) if !isAuthenticated { </s> remove // UserFind - find a user func (a *Auth) UserFind(login, password string) User { </s> add // findUser returns a user if there is one. func (a *Auth) findUser(login, password string) (u webUser, ok bool) { </s> remove func optionalAuthThird(w http.ResponseWriter, r *http.Request) (authFirst bool) { authFirst = false </s> add func optionalAuthThird(w http.ResponseWriter, r *http.Request) (mustAuth bool) { if glProcessCookie(r) { log.Debug("auth: authentication is handled by GL-Inet submodule") return false }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth.go
u, _ = Context.auth.findUser(user, pass) return u
<mask> if err != nil { <mask> // There's no Cookie, check Basic authentication. <mask> user, pass, ok := r.BasicAuth() <mask> if ok { <mask> return Context.auth.UserFind(user, pass) <mask> } <mask> <mask> return User{} <mask> } <mask> </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove func (a *Auth) getCurrentUser(r *http.Request) User { </s> add func (a *Auth) getCurrentUser(r *http.Request) (u webUser) { </s> remove if glProcessCookie(r) { log.Debug("auth: authentication was handled by GL-Inet submodule") ok = true } else if err == nil { r := Context.auth.checkSession(cookie.Value) if r == checkSessionOK { ok = true } else if r < 0 { log.Debug("auth: invalid cookie value: %s", cookie) } } else { // there's no Cookie, check Basic authentication user, pass, ok2 := r.BasicAuth() if ok2 { u := Context.auth.UserFind(user, pass) if len(u.Name) != 0 { ok = true } else { </s> add if err != nil { // The only error that is returned from r.Cookie is [http.ErrNoCookie]. // Check Basic authentication. user, pass, hasBasic := r.BasicAuth() if hasBasic { _, isAuthenticated = Context.auth.findUser(user, pass) if !isAuthenticated { </s> remove return User{} </s> add return webUser{} </s> remove return User{} </s> add return webUser{} </s> remove for _, u := range a.users { </s> add for _, u = range a.users {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth.go
return webUser{}
<mask> if ok { <mask> return Context.auth.UserFind(user, pass) <mask> } <mask> <mask> return User{} <mask> } <mask> <mask> a.lock.Lock() <mask> defer a.lock.Unlock() <mask> </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove return Context.auth.UserFind(user, pass) </s> add u, _ = Context.auth.findUser(user, pass) return u </s> remove return User{} </s> add return webUser{} </s> remove return u </s> add return u, true </s> remove func (a *Auth) GetUsers() []User { </s> add func (a *Auth) GetUsers() []webUser { </s> remove return User{} </s> add return webUser{}
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth.go
return webUser{}
<mask> defer a.lock.Unlock() <mask> <mask> s, ok := a.sessions[cookie.Value] <mask> if !ok { <mask> return User{} <mask> } <mask> <mask> for _, u := range a.users { <mask> if u.Name == s.userName { <mask> return u </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove for _, u := range a.users { </s> add for _, u = range a.users { </s> remove return u </s> add return u, true </s> remove for _, u := range a.users { </s> add for _, u = range a.users { </s> remove // UserFind - find a user func (a *Auth) UserFind(login, password string) User { </s> add // findUser returns a user if there is one. func (a *Auth) findUser(login, password string) (u webUser, ok bool) { </s> remove return User{} </s> add return webUser{}
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth.go
for _, u = range a.users {
<mask> if !ok { <mask> return User{} <mask> } <mask> <mask> for _, u := range a.users { <mask> if u.Name == s.userName { <mask> return u <mask> } <mask> } <mask> </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove return User{} </s> add return webUser{} </s> remove return u </s> add return u, true </s> remove for _, u := range a.users { </s> add for _, u = range a.users { </s> remove // UserFind - find a user func (a *Auth) UserFind(login, password string) User { </s> add // findUser returns a user if there is one. func (a *Auth) findUser(login, password string) (u webUser, ok bool) { </s> remove return Context.auth.UserFind(user, pass) </s> add u, _ = Context.auth.findUser(user, pass) return u
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth.go
return webUser{}
<mask> return u <mask> } <mask> } <mask> <mask> return User{} <mask> } <mask> <mask> // GetUsers - get users <mask> func (a *Auth) GetUsers() []User { <mask> a.lock.Lock() </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove func (a *Auth) GetUsers() []User { </s> add func (a *Auth) GetUsers() []webUser { </s> remove for _, u := range a.users { </s> add for _, u = range a.users { </s> remove return User{} </s> add return webUser{}, false </s> remove func (a *Auth) UserAdd(u *User, password string) { </s> add func (a *Auth) UserAdd(u *webUser, password string) { </s> remove return User{} </s> add return webUser{}
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth.go
func (a *Auth) GetUsers() []webUser {
<mask> return User{} <mask> } <mask> <mask> // GetUsers - get users <mask> func (a *Auth) GetUsers() []User { <mask> a.lock.Lock() <mask> users := a.users <mask> a.lock.Unlock() <mask> return users <mask> } </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove return User{} </s> add return webUser{} </s> remove for _, u := range a.users { </s> add for _, u = range a.users { </s> remove users := []User{u} </s> add users := []webUser{u} </s> remove return User{} </s> add return webUser{} </s> remove // UserFind - find a user func (a *Auth) UserFind(login, password string) User { </s> add // findUser returns a user if there is one. func (a *Auth) findUser(login, password string) (u webUser, ok bool) {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth.go
users := []webUser{{
<mask> func TestAuth(t *testing.T) { <mask> dir := t.TempDir() <mask> fn := filepath.Join(dir, "sessions.db") <mask> <mask> users := []User{{ <mask> Name: "name", <mask> PasswordHash: "$2y$05$..vyzAECIhJPfaQiOK17IukcQnqEgKJHy0iETyYqxn3YXJl8yZuo2", <mask> }} <mask> a := InitAuth(fn, nil, 60, nil) <mask> s := session{} </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove users := []User{ </s> add users := []webUser{ </s> remove user := User{Name: "name"} </s> add user := webUser{Name: "name"} </s> remove users := []User{u} </s> add users := []webUser{u} </s> remove u := User{ </s> add u := webUser{ </s> remove Context.auth.RemoveSession(sess) </s> add Context.auth.RemoveSession(c.Value)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth_test.go
user := webUser{Name: "name"}
<mask> }} <mask> a := InitAuth(fn, nil, 60, nil) <mask> s := session{} <mask> <mask> user := User{Name: "name"} <mask> a.UserAdd(&user, "password") <mask> <mask> assert.Equal(t, checkSessionNotFound, a.checkSession("notfound")) <mask> a.RemoveSession("notfound") <mask> </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove users := []User{{ </s> add users := []webUser{{ </s> remove users := []User{ </s> add users := []webUser{ </s> remove u := a.UserFind("name", "password") </s> add u, ok := a.findUser("name", "password") assert.True(t, ok) </s> remove Context.auth.RemoveSession(sess) </s> add Context.auth.RemoveSession(c.Value) </s> remove w.Header().Set("Location", "/login.html") </s> add c = &http.Cookie{ Name: sessionCookieName, Value: "", Path: "/", Expires: time.Unix(0, 0),
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth_test.go
u, ok := a.findUser("name", "password") assert.True(t, ok)
<mask> s.expire = uint32(time.Now().UTC().Unix() + 2) <mask> a.storeSession(sess, &s) <mask> a.Close() <mask> <mask> u := a.UserFind("name", "password") <mask> assert.NotEmpty(t, u.Name) <mask> <mask> time.Sleep(3 * time.Second) <mask> <mask> // load and remove expired sessions </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove if len(cookie) == 0 { log.Info("auth: failed to login user %q from ip %v", req.Name, ip) time.Sleep(1 * time.Second) http.Error(w, "invalid username or password", http.StatusBadRequest) return } </s> add </s> remove user := User{Name: "name"} </s> add user := webUser{Name: "name"} </s> remove // UserFind - find a user func (a *Auth) UserFind(login, password string) User { </s> add // findUser returns a user if there is one. func (a *Auth) findUser(login, password string) (u webUser, ok bool) { </s> remove db *bbolt.DB blocker *authRateLimiter sessions map[string]*session users []User lock sync.Mutex sessionTTL uint32 </s> add db *bbolt.DB raleLimiter *authRateLimiter sessions map[string]*session users []webUser lock sync.Mutex sessionTTL uint32 </s> remove u := &User{ </s> add u := &webUser{
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth_test.go
users := []webUser{
<mask> func TestAuthHTTP(t *testing.T) { <mask> dir := t.TempDir() <mask> fn := filepath.Join(dir, "sessions.db") <mask> <mask> users := []User{ <mask> {Name: "name", PasswordHash: "$2y$05$..vyzAECIhJPfaQiOK17IukcQnqEgKJHy0iETyYqxn3YXJl8yZuo2"}, <mask> } <mask> Context.auth = InitAuth(fn, users, 60, nil) <mask> <mask> handlerCalled := false </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove users := []User{{ </s> add users := []webUser{{ </s> remove user := User{Name: "name"} </s> add user := webUser{Name: "name"} </s> remove users := []User{u} </s> add users := []webUser{u} </s> remove u := User{ </s> add u := webUser{ </s> remove sessionTTL: sessionTTL, blocker: blocker, sessions: make(map[string]*session), users: users, </s> add sessionTTL: sessionTTL, raleLimiter: rateLimiter, sessions: make(map[string]*session), users: users,
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth_test.go
cookie, err := Context.auth.newCookie(loginJSON{Name: "name", Password: "password"}, "")
<mask> handler2(&w, &r) <mask> assert.True(t, handlerCalled) <mask> <mask> // perform login <mask> cookie, err := Context.auth.httpCookie(loginJSON{Name: "name", Password: "password"}, "") <mask> require.NoError(t, err) <mask> assert.NotEmpty(t, cookie) <mask> <mask> // get / <mask> handler2 = optionalAuth(handler) </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove assert.NotEmpty(t, cookie) </s> add require.NotNil(t, cookie) </s> remove r.Header.Set("Cookie", cookie) </s> add r.Header.Set("Cookie", cookie.String()) </s> remove r.Header.Set("Cookie", cookie) </s> add r.Header.Set("Cookie", cookie.String()) </s> remove u := a.UserFind("name", "password") </s> add u, ok := a.findUser("name", "password") assert.True(t, ok) </s> remove var cookie string cookie, err = Context.auth.httpCookie(req, remoteAddr) </s> add cookie, err := Context.auth.newCookie(req, remoteAddr)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth_test.go
require.NotNil(t, cookie)
<mask> <mask> // perform login <mask> cookie, err := Context.auth.httpCookie(loginJSON{Name: "name", Password: "password"}, "") <mask> require.NoError(t, err) <mask> assert.NotEmpty(t, cookie) <mask> <mask> // get / <mask> handler2 = optionalAuth(handler) <mask> w.hdr = make(http.Header) <mask> r.Header.Set("Cookie", cookie) </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove cookie, err := Context.auth.httpCookie(loginJSON{Name: "name", Password: "password"}, "") </s> add cookie, err := Context.auth.newCookie(loginJSON{Name: "name", Password: "password"}, "") </s> remove r.Header.Set("Cookie", cookie) </s> add r.Header.Set("Cookie", cookie.String()) </s> remove r.Header.Set("Cookie", cookie) </s> add r.Header.Set("Cookie", cookie.String()) </s> remove var cookie string cookie, err = Context.auth.httpCookie(req, remoteAddr) </s> add cookie, err := Context.auth.newCookie(req, remoteAddr) </s> remove ok := false </s> add isAuthenticated := false
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth_test.go
r.Header.Set("Cookie", cookie.String())
<mask> <mask> // get / <mask> handler2 = optionalAuth(handler) <mask> w.hdr = make(http.Header) <mask> r.Header.Set("Cookie", cookie) <mask> r.URL = &url.URL{Path: "/"} <mask> handlerCalled = false <mask> handler2(&w, &r) <mask> assert.True(t, handlerCalled) <mask> r.Header.Del("Cookie") </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove r.Header.Set("Cookie", cookie) </s> add r.Header.Set("Cookie", cookie.String()) </s> remove cookie, err := Context.auth.httpCookie(loginJSON{Name: "name", Password: "password"}, "") </s> add cookie, err := Context.auth.newCookie(loginJSON{Name: "name", Password: "password"}, "") </s> remove assert.NotEmpty(t, cookie) </s> add require.NotNil(t, cookie) </s> remove users := []User{ </s> add users := []webUser{
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth_test.go
r.Header.Set("Cookie", cookie.String())
<mask> <mask> // get login page with a valid cookie - we're redirected to / <mask> handler2 = optionalAuth(handler) <mask> w.hdr = make(http.Header) <mask> r.Header.Set("Cookie", cookie) <mask> r.URL = &url.URL{Path: loginURL} <mask> handlerCalled = false <mask> handler2(&w, &r) <mask> assert.NotEmpty(t, w.hdr.Get("Location")) <mask> assert.False(t, handlerCalled) </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove r.Header.Set("Cookie", cookie) </s> add r.Header.Set("Cookie", cookie.String()) </s> remove assert.NotEmpty(t, cookie) </s> add require.NotNil(t, cookie) </s> remove cookie, err := Context.auth.httpCookie(loginJSON{Name: "name", Password: "password"}, "") </s> add cookie, err := Context.auth.newCookie(loginJSON{Name: "name", Password: "password"}, "") </s> remove if !ok { if r.URL.Path == "/" || r.URL.Path == "/index.html" { if glProcessRedirect(w, r) { log.Debug("auth: redirected to login page by GL-Inet submodule") } else { w.Header().Set("Location", "/login.html") w.WriteHeader(http.StatusFound) } </s> add if isAuthenticated { return false } if p := r.URL.Path; p == "/" || p == "/index.html" { if glProcessRedirect(w, r) { log.Debug("auth: redirected to login page by GL-Inet submodule") </s> remove ok := false </s> add isAuthenticated := false
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/auth_test.go
_ = aghhttp.WriteJSONResponse(w, r, data)
<mask> }) <mask> <mask> data.Tags = clientTags <mask> <mask> w.Header().Set("Content-Type", "application/json") <mask> e := json.NewEncoder(w).Encode(data) <mask> if e != nil { <mask> aghhttp.Error(r, w, http.StatusInternalServerError, "failed to encode to json: %v", e) <mask> <mask> return <mask> } <mask> } <mask> <mask> // Convert JSON object to Client object <mask> func jsonToClient(cj clientJSON) (c *Client) { <mask> return &Client{ </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove w.Header().Set("Content-Type", "application/json") err = json.NewEncoder(w).Encode(data) if err != nil { aghhttp.Error( r, w, http.StatusInternalServerError, "Unable to marshal default addresses to json: %s", err, ) return } </s> add _ = aghhttp.WriteJSONResponse(w, r, data) </s> remove w.Header().Set("Content-Type", "application/json") err = json.NewEncoder(w).Encode(resp) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "Unable to write response json: %s", err) return } </s> add _ = aghhttp.WriteJSONResponse(w, r, resp) </s> remove w.Header().Set("Content-Type", "application/json") err = json.NewEncoder(w).Encode(data) if err != nil { aghhttp.Error( r, w, http.StatusInternalServerError, "Unable to marshal default addresses to json: %s", err, ) return } </s> add _ = aghhttp.WriteJSONResponse(w, r, data) </s> remove w.Header().Set("Content-Type", "application/json") err := json.NewEncoder(w).Encode(data) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "Couldn't write response: %s", err) } </s> add _ = aghhttp.WriteJSONResponse(w, r, data) </s> remove w.Header().Set("Content-Type", "application/json") err = json.NewEncoder(w).Encode(result) if err != nil { aghhttp.Error( r, w, http.StatusInternalServerError, "Failed to marshal DHCP found json: %s", err, ) } </s> add
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/clientshttp.go
_ = aghhttp.WriteJSONResponse(w, r, data)
<mask> idStr: cj, <mask> }) <mask> } <mask> <mask> w.Header().Set("Content-Type", "application/json") <mask> err := json.NewEncoder(w).Encode(data) <mask> if err != nil { <mask> aghhttp.Error(r, w, http.StatusInternalServerError, "Couldn't write response: %s", err) <mask> } <mask> } <mask> <mask> // findRuntime looks up the IP in runtime and temporary storages, like <mask> // /etc/hosts tables, DHCP leases, or blocklists. cj is guaranteed to be <mask> // non-nil. </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove w.Header().Set("Content-Type", "application/json") err = json.NewEncoder(w).Encode(resp) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "encoding the response: %s", err) return } </s> add _ = aghhttp.WriteJSONResponse(w, r, resp) </s> remove w.Header().Set("Content-Type", "application/json") err = json.NewEncoder(w).Encode(resp) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "Unable to write response json: %s", err) return } </s> add _ = aghhttp.WriteJSONResponse(w, r, resp) </s> remove w.Header().Set("Content-Type", "application/json") e := json.NewEncoder(w).Encode(data) if e != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "failed to encode to json: %v", e) return } </s> add _ = aghhttp.WriteJSONResponse(w, r, data) </s> remove w.Header().Set("Content-Type", "application/json") err = json.NewEncoder(w).Encode(data) if err != nil { aghhttp.Error( r, w, http.StatusInternalServerError, "Unable to marshal default addresses to json: %s", err, ) return } </s> add _ = aghhttp.WriteJSONResponse(w, r, data) </s> remove w.Header().Set("Content-Type", "application/json") err = json.NewEncoder(w).Encode(result) if err != nil { aghhttp.Error( r, w, http.StatusInternalServerError, "Failed to marshal DHCP found json: %s", err, ) } </s> add
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/clientshttp.go
BindHost net.IP `yaml:"bind_host"` // BindHost is the IP address of the HTTP server to bind to BindPort int `yaml:"bind_port"` // BindPort is the port the HTTP server BetaBindPort int `yaml:"beta_bind_port"` // BetaBindPort is the port for new client Users []webUser `yaml:"users"` // Users that can access HTTP server
<mask> // Raw file data to avoid re-reading of configuration file <mask> // It's reset after config is parsed <mask> fileData []byte <mask> <mask> BindHost net.IP `yaml:"bind_host"` // BindHost is the IP address of the HTTP server to bind to <mask> BindPort int `yaml:"bind_port"` // BindPort is the port the HTTP server <mask> BetaBindPort int `yaml:"beta_bind_port"` // BetaBindPort is the port for new client <mask> Users []User `yaml:"users"` // Users that can access HTTP server <mask> // AuthAttempts is the maximum number of failed login attempts a user <mask> // can do before being blocked. <mask> AuthAttempts uint `yaml:"auth_attempts"` <mask> // AuthBlockMin is the duration, in minutes, of the block of new login <mask> // attempts after AuthAttempts unsuccessful login attempts. </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove // Perform the following tasks: // . Search for another DHCP server running // . Check if a static IP is configured for the network interface // Respond with results </s> add // findActiveServerReq is the JSON structure for the request to find active DHCP // servers. type findActiveServerReq struct { Interface string `json:"interface"` } // handleDHCPFindActiveServer performs the following tasks: // 1. searches for another DHCP server in the network; // 2. check if a static IP is configured for the network interface; // 3. responds with the results. </s> remove return fmt.Sprintf( "%s=%s; Path=/; HttpOnly; Expires=%s", sessionCookieName, hex.EncodeToString(sess), cookieExpiryFormat(now.Add(cookieTTL)), ), nil </s> add return &http.Cookie{ Name: sessionCookieName, Value: hex.EncodeToString(sess), Path: "/", Expires: now.Add(cookieTTL), HttpOnly: true, SameSite: http.SameSiteLaxMode, }, nil </s> remove // This use of ReadAll is safe, because request's body is now limited. body, err := io.ReadAll(r.Body) </s> add if aghhttp.WriteTextPlainDeprecated(w, r) { return } req := &findActiveServerReq{} err := json.NewDecoder(r.Body).Decode(req)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/config.go
_ = aghhttp.WriteJSONResponse(w, r, resp)
<mask> if runtime.GOOS != "windows" { <mask> resp.IsDHCPAvailable = Context.dhcpServer != nil <mask> } <mask> <mask> w.Header().Set("Content-Type", "application/json") <mask> err = json.NewEncoder(w).Encode(resp) <mask> if err != nil { <mask> aghhttp.Error(r, w, http.StatusInternalServerError, "Unable to write response json: %s", err) <mask> <mask> return <mask> } <mask> } <mask> <mask> type profileJSON struct { <mask> Name string `json:"name"` <mask> } </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove w.Header().Set("Content-Type", "application/json") err = json.NewEncoder(w).Encode(data) if err != nil { aghhttp.Error( r, w, http.StatusInternalServerError, "Unable to marshal default addresses to json: %s", err, ) return } </s> add _ = aghhttp.WriteJSONResponse(w, r, data) </s> remove func handleI18nCurrentLanguage(w http.ResponseWriter, _ *http.Request) { w.Header().Set("Content-Type", "text/plain") log.Printf("config.Language is %s", config.Language) _, err := fmt.Fprintf(w, "%s\n", config.Language) if err != nil { msg := fmt.Sprintf("Unable to write response json: %s", err) log.Println(msg) http.Error(w, msg, http.StatusInternalServerError) </s> add // languageJSON is the JSON structure for language requests and responses. type languageJSON struct { Language string `json:"language"` } </s> remove w.Header().Set("Content-Type", "application/json") err = json.NewEncoder(w).Encode(resp) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "encoding the response: %s", err) return } </s> add _ = aghhttp.WriteJSONResponse(w, r, resp) </s> remove w.Header().Set("Content-Type", "application/json") err = json.NewEncoder(w).Encode(data) if err != nil { aghhttp.Error( r, w, http.StatusInternalServerError, "Unable to marshal default addresses to json: %s", err, ) return } </s> add _ = aghhttp.WriteJSONResponse(w, r, data) </s> remove w.Header().Set("Content-Type", "application/json") err = json.NewEncoder(w).Encode(result) if err != nil { aghhttp.Error( r, w, http.StatusInternalServerError, "Failed to marshal DHCP found json: %s", err, ) } </s> add
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/control.go
aghhttp.Error(r, w, http.StatusMethodNotAllowed, "only %s is allowed", method)
<mask> return func(w http.ResponseWriter, r *http.Request) { <mask> log.Debug("%s %v", r.Method, r.URL) <mask> <mask> if r.Method != method { <mask> http.Error(w, "This request must be "+method, http.StatusMethodNotAllowed) <mask> return <mask> } <mask> <mask> if method == http.MethodPost || method == http.MethodPut || method == http.MethodDelete { <mask> Context.controlLock.Lock() </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove return authFirst </s> add return true </s> remove if r.URL.Path == "/login.html" { // redirect to dashboard if already authenticated authRequired := Context.auth != nil && Context.auth.AuthRequired() </s> add p := r.URL.Path authRequired := Context.auth != nil && Context.auth.AuthRequired() if p == "/login.html" { </s> remove changeLanguage(lang) { </s> add changeLanguage(config) { </s> remove } else if r == checkSessionNotFound { log.Debug("auth: invalid cookie value: %s", cookie) </s> add
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/control.go
if r.Header.Get(aghhttp.HdrNameContentType) != aghhttp.HdrValApplicationJSON { aghhttp.Error( r, w, http.StatusUnsupportedMediaType, "only %s is allowed", aghhttp.HdrValApplicationJSON, ) return }
<mask> <mask> if method == http.MethodPost || method == http.MethodPut || method == http.MethodDelete { <mask> Context.controlLock.Lock() <mask> defer Context.controlLock.Unlock() <mask> } <mask> <mask> handler(w, r) <mask> } </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove http.Error(w, "This request must be "+method, http.StatusMethodNotAllowed) </s> add aghhttp.Error(r, w, http.StatusMethodNotAllowed, "only %s is allowed", method) </s> remove if !ok { if r.URL.Path == "/" || r.URL.Path == "/index.html" { if glProcessRedirect(w, r) { log.Debug("auth: redirected to login page by GL-Inet submodule") } else { w.Header().Set("Location", "/login.html") w.WriteHeader(http.StatusFound) } </s> add if isAuthenticated { return false } if p := r.URL.Path; p == "/" || p == "/index.html" { if glProcessRedirect(w, r) { log.Debug("auth: redirected to login page by GL-Inet submodule") </s> remove } else if r == checkSessionNotFound { log.Debug("auth: invalid cookie value: %s", cookie) </s> add </s> remove changeLanguage(lang) { </s> add changeLanguage(config) { </s> remove } </s> add
[ "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/control.go
_ = aghhttp.WriteJSONResponse(w, r, data)
<mask> for _, iface := range ifaces { <mask> data.Interfaces[iface.Name] = iface <mask> } <mask> <mask> w.Header().Set("Content-Type", "application/json") <mask> err = json.NewEncoder(w).Encode(data) <mask> if err != nil { <mask> aghhttp.Error( <mask> r, <mask> w, <mask> http.StatusInternalServerError, <mask> "Unable to marshal default addresses to json: %s", <mask> err, <mask> ) <mask> <mask> return <mask> } <mask> } <mask> <mask> type checkConfReqEnt struct { <mask> IP net.IP `json:"ip"` <mask> Port int `json:"port"` </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove w.Header().Set("Content-Type", "application/json") err = json.NewEncoder(w).Encode(data) if err != nil { aghhttp.Error( r, w, http.StatusInternalServerError, "Unable to marshal default addresses to json: %s", err, ) return } </s> add _ = aghhttp.WriteJSONResponse(w, r, data) </s> remove w.Header().Set("Content-Type", "application/json") err = json.NewEncoder(w).Encode(result) if err != nil { aghhttp.Error( r, w, http.StatusInternalServerError, "Failed to marshal DHCP found json: %s", err, ) } </s> add </s> remove w.Header().Set("Content-Type", "application/json") err = json.NewEncoder(w).Encode(resp) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "Unable to write response json: %s", err) return } </s> add _ = aghhttp.WriteJSONResponse(w, r, resp) </s> remove err := json.NewEncoder(w).Encode(data) if err != nil { aghhttp.Error( r, w, http.StatusInternalServerError, "Failed to marshal json with TLS status: %s", err, ) } </s> add _ = aghhttp.WriteJSONResponse(w, r, data) </s> remove w.Header().Set("Content-Type", "application/json") e := json.NewEncoder(w).Encode(data) if e != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "failed to encode to json: %v", e) return } </s> add _ = aghhttp.WriteJSONResponse(w, r, data)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/controlinstall.go
_ = aghhttp.WriteJSONResponse(w, r, resp)
<mask> } else if !req.DNS.IP.IsUnspecified() { <mask> resp.StaticIP = handleStaticIP(req.DNS.IP, req.SetStaticIP) <mask> } <mask> <mask> w.Header().Set("Content-Type", "application/json") <mask> err = json.NewEncoder(w).Encode(resp) <mask> if err != nil { <mask> aghhttp.Error(r, w, http.StatusInternalServerError, "encoding the response: %s", err) <mask> <mask> return <mask> } <mask> } <mask> <mask> // handleStaticIP - handles static IP request <mask> // It either checks if we have a static IP <mask> // Or if set=true, it tries to set it </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove err = json.NewEncoder(w).Encode(resp) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "writing body: %s", err) } </s> add _ = aghhttp.WriteJSONResponse(w, r, resp) </s> remove w.Header().Set("Content-Type", "application/json") err = json.NewEncoder(w).Encode(resp) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "Unable to write response json: %s", err) return } </s> add _ = aghhttp.WriteJSONResponse(w, r, resp) </s> remove w.Header().Set("Content-Type", "application/json") err := json.NewEncoder(w).Encode(data) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "Couldn't write response: %s", err) } </s> add _ = aghhttp.WriteJSONResponse(w, r, data) </s> remove w.Header().Set("Content-Type", "application/json") err = json.NewEncoder(w).Encode(data) if err != nil { aghhttp.Error( r, w, http.StatusInternalServerError, "Unable to marshal default addresses to json: %s", err, ) return } </s> add _ = aghhttp.WriteJSONResponse(w, r, data) </s> remove w.Header().Set("Content-Type", "application/json") err = json.NewEncoder(w).Encode(data) if err != nil { aghhttp.Error( r, w, http.StatusInternalServerError, "Unable to marshal default addresses to json: %s", err, ) return } </s> add _ = aghhttp.WriteJSONResponse(w, r, data)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/controlinstall.go
u := &webUser{
<mask> <mask> return <mask> } <mask> <mask> u := &User{ <mask> Name: req.Username, <mask> } <mask> Context.auth.UserAdd(u, req.Password) <mask> <mask> err = config.write() </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove u := User{ </s> add u := webUser{ </s> remove users := []User{u} </s> add users := []webUser{u} </s> remove for _, u := range a.users { </s> add for _, u = range a.users { </s> remove // cookieTimeFormat is the format to be used in (time.Time).Format for cookie's // expiry field. const cookieTimeFormat = "Mon, 02 Jan 2006 15:04:05 GMT" // cookieExpiryFormat returns the formatted exp to be used in cookie string. // It's quite simple for now, but probably will be expanded in the future. func cookieExpiryFormat(exp time.Time) (formatted string) { return exp.Format(cookieTimeFormat) } func (a *Auth) httpCookie(req loginJSON, addr string) (cookie string, err error) { blocker := a.blocker u := a.UserFind(req.Name, req.Password) if len(u.Name) == 0 { if blocker != nil { blocker.inc(addr) </s> add // newCookie creates a new authentication cookie. func (a *Auth) newCookie(req loginJSON, addr string) (c *http.Cookie, err error) { rateLimiter := a.raleLimiter u, ok := a.findUser(req.Name, req.Password) if !ok { if rateLimiter != nil { rateLimiter.inc(addr) </s> remove return u </s> add return u, true
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/controlinstall.go
_ = aghhttp.WriteJSONResponse(w, r, data)
<mask> } <mask> <mask> data.Interfaces = ifaces <mask> <mask> w.Header().Set("Content-Type", "application/json") <mask> err = json.NewEncoder(w).Encode(data) <mask> if err != nil { <mask> aghhttp.Error( <mask> r, <mask> w, <mask> http.StatusInternalServerError, <mask> "Unable to marshal default addresses to json: %s", <mask> err, <mask> ) <mask> <mask> return <mask> } <mask> } <mask> <mask> // registerBetaInstallHandlers registers the install handlers for new client <mask> // with the structures it supports. <mask> // </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove w.Header().Set("Content-Type", "application/json") err = json.NewEncoder(w).Encode(data) if err != nil { aghhttp.Error( r, w, http.StatusInternalServerError, "Unable to marshal default addresses to json: %s", err, ) return } </s> add _ = aghhttp.WriteJSONResponse(w, r, data) </s> remove err := json.NewEncoder(w).Encode(data) if err != nil { aghhttp.Error( r, w, http.StatusInternalServerError, "Failed to marshal json with TLS status: %s", err, ) } </s> add _ = aghhttp.WriteJSONResponse(w, r, data) </s> remove w.Header().Set("Content-Type", "application/json") err = json.NewEncoder(w).Encode(result) if err != nil { aghhttp.Error( r, w, http.StatusInternalServerError, "Failed to marshal DHCP found json: %s", err, ) } </s> add </s> remove w.Header().Set("Content-Type", "application/json") err = json.NewEncoder(w).Encode(resp) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "Unable to write response json: %s", err) return } </s> add _ = aghhttp.WriteJSONResponse(w, r, resp) </s> remove w.Header().Set("Content-Type", "application/json") err = json.NewEncoder(w).Encode(resp) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "encoding the response: %s", err) return } </s> add _ = aghhttp.WriteJSONResponse(w, r, resp)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/controlinstall.go
<mask> } <mask> <mask> // Get the latest available version from the Internet <mask> func handleGetVersionJSON(w http.ResponseWriter, r *http.Request) { <mask> w.Header().Set("Content-Type", "application/json") <mask> <mask> resp := &versionResponse{} <mask> if Context.disableUpdate { <mask> resp.Disabled = true <mask> err := json.NewEncoder(w).Encode(resp) <mask> if err != nil { </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove w.Header().Set("Content-Type", "application/json") err = json.NewEncoder(w).Encode(result) if err != nil { aghhttp.Error( r, w, http.StatusInternalServerError, "Failed to marshal DHCP found json: %s", err, ) } </s> add </s> remove w.Header().Set("Content-Type", "application/json") </s> add </s> remove err = json.NewEncoder(w).Encode(resp) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "writing body: %s", err) } </s> add _ = aghhttp.WriteJSONResponse(w, r, resp) </s> remove if r.URL.Path == "/login.html" { // redirect to dashboard if already authenticated authRequired := Context.auth != nil && Context.auth.AuthRequired() </s> add p := r.URL.Path authRequired := Context.auth != nil && Context.auth.AuthRequired() if p == "/login.html" { </s> remove func optionalAuthThird(w http.ResponseWriter, r *http.Request) (authFirst bool) { authFirst = false </s> add func optionalAuthThird(w http.ResponseWriter, r *http.Request) (mustAuth bool) { if glProcessCookie(r) { log.Debug("auth: authentication is handled by GL-Inet submodule") return false }
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/controlupdate.go
_ = aghhttp.WriteJSONResponse(w, r, resp)
<mask> <mask> return <mask> } <mask> <mask> err = json.NewEncoder(w).Encode(resp) <mask> if err != nil { <mask> aghhttp.Error(r, w, http.StatusInternalServerError, "writing body: %s", err) <mask> } <mask> } <mask> <mask> // requestVersionInfo sets the VersionInfo field of resp if it can reach the <mask> // update server. <mask> func requestVersionInfo(resp *versionResponse, recheck bool) (err error) { </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove w.Header().Set("Content-Type", "application/json") err = json.NewEncoder(w).Encode(resp) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "encoding the response: %s", err) return } </s> add _ = aghhttp.WriteJSONResponse(w, r, resp) </s> remove w.Header().Set("Content-Type", "application/json") err = json.NewEncoder(w).Encode(resp) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "Unable to write response json: %s", err) return } </s> add _ = aghhttp.WriteJSONResponse(w, r, resp) </s> remove w.Header().Set("Content-Type", "application/json") </s> add </s> remove language := strings.TrimSpace(string(body)) if language == "" { msg := "empty language specified" log.Println(msg) http.Error(w, msg, http.StatusBadRequest) </s> add langReq := &languageJSON{} err := json.NewDecoder(r.Body).Decode(langReq) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "reading req: %s", err) </s> remove w.Header().Set("Content-Type", "application/json") err = json.NewEncoder(w).Encode(data) if err != nil { aghhttp.Error( r, w, http.StatusInternalServerError, "Unable to marshal default addresses to json: %s", err, ) return } </s> add _ = aghhttp.WriteJSONResponse(w, r, data)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/controlupdate.go
log.Info(version.Full())
<mask> // configure log level and output <mask> configureLogger(args) <mask> <mask> // Print the first message after logger is configured. <mask> log.Println(version.Full()) <mask> log.Debug("current working directory is %s", Context.workDir) <mask> if args.runningAsService { <mask> log.Info("AdGuard Home is running as a service") <mask> } <mask> </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove // Perform the following tasks: // . Search for another DHCP server running // . Check if a static IP is configured for the network interface // Respond with results </s> add // findActiveServerReq is the JSON structure for the request to find active DHCP // servers. type findActiveServerReq struct { Interface string `json:"interface"` } // handleDHCPFindActiveServer performs the following tasks: // 1. searches for another DHCP server in the network; // 2. check if a static IP is configured for the network interface; // 3. responds with the results. </s> remove // This use of ReadAll is safe, because request's body is now limited. body, err := io.ReadAll(r.Body) </s> add if aghhttp.WriteTextPlainDeprecated(w, r) { return } req := &findActiveServerReq{} err := json.NewDecoder(r.Body).Decode(req) </s> remove func handleI18nCurrentLanguage(w http.ResponseWriter, _ *http.Request) { w.Header().Set("Content-Type", "text/plain") log.Printf("config.Language is %s", config.Language) _, err := fmt.Fprintf(w, "%s\n", config.Language) if err != nil { msg := fmt.Sprintf("Unable to write response json: %s", err) log.Println(msg) http.Error(w, msg, http.StatusInternalServerError) </s> add // languageJSON is the JSON structure for language requests and responses. type languageJSON struct { Language string `json:"language"` } </s> remove BindHost net.IP `yaml:"bind_host"` // BindHost is the IP address of the HTTP server to bind to BindPort int `yaml:"bind_port"` // BindPort is the port the HTTP server BetaBindPort int `yaml:"beta_bind_port"` // BetaBindPort is the port for new client Users []User `yaml:"users"` // Users that can access HTTP server </s> add BindHost net.IP `yaml:"bind_host"` // BindHost is the IP address of the HTTP server to bind to BindPort int `yaml:"bind_port"` // BindPort is the port the HTTP server BetaBindPort int `yaml:"beta_bind_port"` // BetaBindPort is the port for new client Users []webUser `yaml:"users"` // Users that can access HTTP server </s> remove w.Header().Set("Content-Type", "application/json") err := json.NewEncoder(w).Encode(data) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "Couldn't write response: %s", err) } </s> add _ = aghhttp.WriteJSONResponse(w, r, data)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/home.go
var rateLimiter *authRateLimiter
<mask> } <mask> <mask> sessFilename := filepath.Join(Context.getDataDir(), "sessions.db") <mask> GLMode = args.glinetMode <mask> var arl *authRateLimiter <mask> if config.AuthAttempts > 0 && config.AuthBlockMin > 0 { <mask> arl = newAuthRateLimiter( <mask> time.Duration(config.AuthBlockMin)*time.Minute, <mask> config.AuthAttempts, <mask> ) </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove arl = newAuthRateLimiter( </s> add rateLimiter = newAuthRateLimiter( </s> remove if blocker := Context.auth.blocker; blocker != nil { if left := blocker.check(remoteAddr); left > 0 { </s> add if rateLimiter := Context.auth.raleLimiter; rateLimiter != nil { if left := rateLimiter.check(remoteAddr); left > 0 { </s> remove if glProcessCookie(r) { log.Debug("auth: authentication was handled by GL-Inet submodule") ok = true } else if err == nil { r := Context.auth.checkSession(cookie.Value) if r == checkSessionOK { ok = true } else if r < 0 { log.Debug("auth: invalid cookie value: %s", cookie) } } else { // there's no Cookie, check Basic authentication user, pass, ok2 := r.BasicAuth() if ok2 { u := Context.auth.UserFind(user, pass) if len(u.Name) != 0 { ok = true } else { </s> add if err != nil { // The only error that is returned from r.Cookie is [http.ErrNoCookie]. // Check Basic authentication. user, pass, hasBasic := r.BasicAuth() if hasBasic { _, isAuthenticated = Context.auth.findUser(user, pass) if !isAuthenticated { </s> remove func (a *Auth) UserAdd(u *User, password string) { </s> add func (a *Auth) UserAdd(u *webUser, password string) { </s> remove if r.URL.Path == "/login.html" { // redirect to dashboard if already authenticated authRequired := Context.auth != nil && Context.auth.AuthRequired() </s> add p := r.URL.Path authRequired := Context.auth != nil && Context.auth.AuthRequired() if p == "/login.html" {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/home.go
rateLimiter = newAuthRateLimiter(
<mask> sessFilename := filepath.Join(Context.getDataDir(), "sessions.db") <mask> GLMode = args.glinetMode <mask> var arl *authRateLimiter <mask> if config.AuthAttempts > 0 && config.AuthBlockMin > 0 { <mask> arl = newAuthRateLimiter( <mask> time.Duration(config.AuthBlockMin)*time.Minute, <mask> config.AuthAttempts, <mask> ) <mask> } else { <mask> log.Info("authratelimiter is disabled") </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove var arl *authRateLimiter </s> add var rateLimiter *authRateLimiter </s> remove if blocker := Context.auth.blocker; blocker != nil { if left := blocker.check(remoteAddr); left > 0 { </s> add if rateLimiter := Context.auth.raleLimiter; rateLimiter != nil { if left := rateLimiter.check(remoteAddr); left > 0 { </s> remove if glProcessCookie(r) { log.Debug("auth: authentication was handled by GL-Inet submodule") ok = true } else if err == nil { r := Context.auth.checkSession(cookie.Value) if r == checkSessionOK { ok = true } else if r < 0 { log.Debug("auth: invalid cookie value: %s", cookie) } } else { // there's no Cookie, check Basic authentication user, pass, ok2 := r.BasicAuth() if ok2 { u := Context.auth.UserFind(user, pass) if len(u.Name) != 0 { ok = true } else { </s> add if err != nil { // The only error that is returned from r.Cookie is [http.ErrNoCookie]. // Check Basic authentication. user, pass, hasBasic := r.BasicAuth() if hasBasic { _, isAuthenticated = Context.auth.findUser(user, pass) if !isAuthenticated { </s> remove func (a *Auth) UserAdd(u *User, password string) { </s> add func (a *Auth) UserAdd(u *webUser, password string) { </s> remove } else if strings.HasPrefix(r.URL.Path, "/assets/") || strings.HasPrefix(r.URL.Path, "/login.") { // process as usual // no additional auth requirements } else if Context.auth != nil && Context.auth.AuthRequired() { </s> add log.Debug("auth: invalid cookie value: %s", cookie) } } else if isPublicResource(p) { // Process as usual, no additional auth requirements. } else if authRequired {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/home.go
rateLimiter,
<mask> Context.auth = InitAuth( <mask> sessFilename, <mask> config.Users, <mask> config.WebSessionTTLHours*60*60, <mask> arl, <mask> ) <mask> if Context.auth == nil { <mask> log.Fatalf("Couldn't initialize Auth module") <mask> } <mask> config.Users = nil </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove if r.URL.Path == "/login.html" { // redirect to dashboard if already authenticated authRequired := Context.auth != nil && Context.auth.AuthRequired() </s> add p := r.URL.Path authRequired := Context.auth != nil && Context.auth.AuthRequired() if p == "/login.html" { </s> remove r := Context.auth.checkSession(cookie.Value) if r == checkSessionOK { </s> add // Redirect to the dashboard if already authenticated. res := Context.auth.checkSession(cookie.Value) if res == checkSessionOK { </s> remove func optionalAuth(handler func(http.ResponseWriter, *http.Request)) func(http.ResponseWriter, *http.Request) { </s> add // TODO(a.garipov): Use [http.Handler] consistently everywhere throughout the // project. func optionalAuth( h func(http.ResponseWriter, *http.Request), ) (wrapped func(http.ResponseWriter, *http.Request)) { </s> remove } else if strings.HasPrefix(r.URL.Path, "/assets/") || strings.HasPrefix(r.URL.Path, "/login.") { // process as usual // no additional auth requirements } else if Context.auth != nil && Context.auth.AuthRequired() { </s> add log.Debug("auth: invalid cookie value: %s", cookie) } } else if isPublicResource(p) { // Process as usual, no additional auth requirements. } else if authRequired {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/home.go
"encoding/json"
<mask> package home <mask> <mask> import ( <mask> "fmt" <mask> "io" <mask> "net/http" <mask> "strings" <mask> <mask> "github.com/AdguardTeam/AdGuardHome/internal/aghhttp" <mask> "github.com/AdguardTeam/golibs/log" </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove "strings" </s> add </s> remove "io" </s> add </s> remove "strings" </s> add
[ "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/i18n.go
<mask> import ( <mask> "fmt" <mask> "io" <mask> "net/http" <mask> "strings" <mask> <mask> "github.com/AdguardTeam/AdGuardHome/internal/aghhttp" <mask> "github.com/AdguardTeam/golibs/log" <mask> "github.com/AdguardTeam/golibs/stringutil" <mask> ) </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove "fmt" "io" </s> add "encoding/json" </s> remove "io" </s> add </s> remove "strings" </s> add
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/i18n.go
// languageJSON is the JSON structure for language requests and responses. type languageJSON struct { Language string `json:"language"` }
<mask> "zh-hk", <mask> "zh-tw", <mask> ) <mask> <mask> func handleI18nCurrentLanguage(w http.ResponseWriter, _ *http.Request) { <mask> w.Header().Set("Content-Type", "text/plain") <mask> log.Printf("config.Language is %s", config.Language) <mask> _, err := fmt.Fprintf(w, "%s\n", config.Language) <mask> if err != nil { <mask> msg := fmt.Sprintf("Unable to write response json: %s", err) <mask> log.Println(msg) <mask> http.Error(w, msg, http.StatusInternalServerError) <mask> <mask> return <mask> } <mask> } <mask> </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove return } </s> add func handleI18nCurrentLanguage(w http.ResponseWriter, r *http.Request) { log.Printf("home: language is %s", config.Language) _ = aghhttp.WriteJSONResponse(w, r, &languageJSON{ Language: config.Language, }) </s> remove // This use of ReadAll is safe, because request's body is now limited. body, err := io.ReadAll(r.Body) if err != nil { msg := fmt.Sprintf("failed to read request body: %s", err) log.Println(msg) http.Error(w, msg, http.StatusBadRequest) </s> add if aghhttp.WriteTextPlainDeprecated(w, r) { </s> remove w.Header().Set("Content-Type", "application/json") err = json.NewEncoder(w).Encode(resp) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "Unable to write response json: %s", err) return } </s> add _ = aghhttp.WriteJSONResponse(w, r, resp) </s> remove language := strings.TrimSpace(string(body)) if language == "" { msg := "empty language specified" log.Println(msg) http.Error(w, msg, http.StatusBadRequest) </s> add langReq := &languageJSON{} err := json.NewDecoder(r.Body).Decode(langReq) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "reading req: %s", err) </s> remove msg := fmt.Sprintf("failed to read request body: %s", err) log.Error(msg) http.Error(w, msg, http.StatusBadRequest) </s> add aghhttp.Error(r, w, http.StatusBadRequest, "reading req: %s", err)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/i18n.go
func handleI18nCurrentLanguage(w http.ResponseWriter, r *http.Request) { log.Printf("home: language is %s", config.Language) _ = aghhttp.WriteJSONResponse(w, r, &languageJSON{ Language: config.Language, })
<mask> msg := fmt.Sprintf("Unable to write response json: %s", err) <mask> log.Println(msg) <mask> http.Error(w, msg, http.StatusInternalServerError) <mask> <mask> return <mask> } <mask> } <mask> <mask> func handleI18nChangeLanguage(w http.ResponseWriter, r *http.Request) { <mask> // This use of ReadAll is safe, because request's body is now limited. <mask> body, err := io.ReadAll(r.Body) </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove // This use of ReadAll is safe, because request's body is now limited. body, err := io.ReadAll(r.Body) if err != nil { msg := fmt.Sprintf("failed to read request body: %s", err) log.Println(msg) http.Error(w, msg, http.StatusBadRequest) </s> add if aghhttp.WriteTextPlainDeprecated(w, r) { </s> remove msg := fmt.Sprintf("failed to read request body: %s", err) log.Error(msg) http.Error(w, msg, http.StatusBadRequest) </s> add aghhttp.Error(r, w, http.StatusBadRequest, "reading req: %s", err) </s> remove // This use of ReadAll is safe, because request's body is now limited. body, err := io.ReadAll(r.Body) </s> add if aghhttp.WriteTextPlainDeprecated(w, r) { return } req := &findActiveServerReq{} err := json.NewDecoder(r.Body).Decode(req) </s> remove func handleI18nCurrentLanguage(w http.ResponseWriter, _ *http.Request) { w.Header().Set("Content-Type", "text/plain") log.Printf("config.Language is %s", config.Language) _, err := fmt.Fprintf(w, "%s\n", config.Language) if err != nil { msg := fmt.Sprintf("Unable to write response json: %s", err) log.Println(msg) http.Error(w, msg, http.StatusInternalServerError) </s> add // languageJSON is the JSON structure for language requests and responses. type languageJSON struct { Language string `json:"language"` } </s> remove // Perform the following tasks: // . Search for another DHCP server running // . Check if a static IP is configured for the network interface // Respond with results </s> add // findActiveServerReq is the JSON structure for the request to find active DHCP // servers. type findActiveServerReq struct { Interface string `json:"interface"` } // handleDHCPFindActiveServer performs the following tasks: // 1. searches for another DHCP server in the network; // 2. check if a static IP is configured for the network interface; // 3. responds with the results.
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/i18n.go
if aghhttp.WriteTextPlainDeprecated(w, r) {
<mask> } <mask> } <mask> <mask> func handleI18nChangeLanguage(w http.ResponseWriter, r *http.Request) { <mask> // This use of ReadAll is safe, because request's body is now limited. <mask> body, err := io.ReadAll(r.Body) <mask> if err != nil { <mask> msg := fmt.Sprintf("failed to read request body: %s", err) <mask> log.Println(msg) <mask> http.Error(w, msg, http.StatusBadRequest) <mask> <mask> return <mask> } <mask> <mask> language := strings.TrimSpace(string(body)) <mask> if language == "" { </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove msg := fmt.Sprintf("failed to read request body: %s", err) log.Error(msg) http.Error(w, msg, http.StatusBadRequest) </s> add aghhttp.Error(r, w, http.StatusBadRequest, "reading req: %s", err) </s> remove return } </s> add func handleI18nCurrentLanguage(w http.ResponseWriter, r *http.Request) { log.Printf("home: language is %s", config.Language) _ = aghhttp.WriteJSONResponse(w, r, &languageJSON{ Language: config.Language, }) </s> remove // This use of ReadAll is safe, because request's body is now limited. body, err := io.ReadAll(r.Body) </s> add if aghhttp.WriteTextPlainDeprecated(w, r) { return } req := &findActiveServerReq{} err := json.NewDecoder(r.Body).Decode(req) </s> remove language := strings.TrimSpace(string(body)) if language == "" { msg := "empty language specified" log.Println(msg) http.Error(w, msg, http.StatusBadRequest) </s> add langReq := &languageJSON{} err := json.NewDecoder(r.Body).Decode(langReq) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "reading req: %s", err) </s> remove // Perform the following tasks: // . Search for another DHCP server running // . Check if a static IP is configured for the network interface // Respond with results </s> add // findActiveServerReq is the JSON structure for the request to find active DHCP // servers. type findActiveServerReq struct { Interface string `json:"interface"` } // handleDHCPFindActiveServer performs the following tasks: // 1. searches for another DHCP server in the network; // 2. check if a static IP is configured for the network interface; // 3. responds with the results.
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/i18n.go
langReq := &languageJSON{} err := json.NewDecoder(r.Body).Decode(langReq) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "reading req: %s", err)
<mask> <mask> return <mask> } <mask> <mask> language := strings.TrimSpace(string(body)) <mask> if language == "" { <mask> msg := "empty language specified" <mask> log.Println(msg) <mask> http.Error(w, msg, http.StatusBadRequest) <mask> <mask> return <mask> } <mask> <mask> if !allowedLanguages.Has(language) { </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove ifaceName := strings.TrimSpace(string(body)) </s> add ifaceName := req.Interface </s> remove if !allowedLanguages.Has(language) { msg := fmt.Sprintf("unknown language specified: %s", language) log.Println(msg) http.Error(w, msg, http.StatusBadRequest) </s> add lang := langReq.Language if !allowedLanguages.Has(lang) { aghhttp.Error(r, w, http.StatusBadRequest, "unknown language: %q", lang) </s> remove msg := "empty interface name specified" log.Error(msg) http.Error(w, msg, http.StatusBadRequest) </s> add aghhttp.Error(r, w, http.StatusBadRequest, "empty interface name") </s> remove // This use of ReadAll is safe, because request's body is now limited. body, err := io.ReadAll(r.Body) if err != nil { msg := fmt.Sprintf("failed to read request body: %s", err) log.Println(msg) http.Error(w, msg, http.StatusBadRequest) </s> add if aghhttp.WriteTextPlainDeprecated(w, r) { </s> remove func handleI18nCurrentLanguage(w http.ResponseWriter, _ *http.Request) { w.Header().Set("Content-Type", "text/plain") log.Printf("config.Language is %s", config.Language) _, err := fmt.Fprintf(w, "%s\n", config.Language) if err != nil { msg := fmt.Sprintf("Unable to write response json: %s", err) log.Println(msg) http.Error(w, msg, http.StatusInternalServerError) </s> add // languageJSON is the JSON structure for language requests and responses. type languageJSON struct { Language string `json:"language"` }
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/i18n.go
lang := langReq.Language if !allowedLanguages.Has(lang) { aghhttp.Error(r, w, http.StatusBadRequest, "unknown language: %q", lang)
<mask> <mask> return <mask> } <mask> <mask> if !allowedLanguages.Has(language) { <mask> msg := fmt.Sprintf("unknown language specified: %s", language) <mask> log.Println(msg) <mask> http.Error(w, msg, http.StatusBadRequest) <mask> <mask> return <mask> } <mask> <mask> func() { </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove language := strings.TrimSpace(string(body)) if language == "" { msg := "empty language specified" log.Println(msg) http.Error(w, msg, http.StatusBadRequest) </s> add langReq := &languageJSON{} err := json.NewDecoder(r.Body).Decode(langReq) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "reading req: %s", err) </s> remove // This use of ReadAll is safe, because request's body is now limited. body, err := io.ReadAll(r.Body) if err != nil { msg := fmt.Sprintf("failed to read request body: %s", err) log.Println(msg) http.Error(w, msg, http.StatusBadRequest) </s> add if aghhttp.WriteTextPlainDeprecated(w, r) { </s> remove ifaceName := strings.TrimSpace(string(body)) </s> add ifaceName := req.Interface </s> remove msg := "empty interface name specified" log.Error(msg) http.Error(w, msg, http.StatusBadRequest) </s> add aghhttp.Error(r, w, http.StatusBadRequest, "empty interface name") </s> remove func handleI18nCurrentLanguage(w http.ResponseWriter, _ *http.Request) { w.Header().Set("Content-Type", "text/plain") log.Printf("config.Language is %s", config.Language) _, err := fmt.Fprintf(w, "%s\n", config.Language) if err != nil { msg := fmt.Sprintf("Unable to write response json: %s", err) log.Println(msg) http.Error(w, msg, http.StatusInternalServerError) </s> add // languageJSON is the JSON structure for language requests and responses. type languageJSON struct { Language string `json:"language"` }
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/i18n.go
config.Language = lang log.Printf("home: language is set to %s", lang)
<mask> func() { <mask> config.Lock() <mask> defer config.Unlock() <mask> <mask> config.Language = language <mask> }() <mask> <mask> onConfigModified() <mask> aghhttp.OK(w) <mask> } </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove if !allowedLanguages.Has(language) { msg := fmt.Sprintf("unknown language specified: %s", language) log.Println(msg) http.Error(w, msg, http.StatusBadRequest) </s> add lang := langReq.Language if !allowedLanguages.Has(lang) { aghhttp.Error(r, w, http.StatusBadRequest, "unknown language: %q", lang) </s> remove language := strings.TrimSpace(string(body)) if language == "" { msg := "empty language specified" log.Println(msg) http.Error(w, msg, http.StatusBadRequest) </s> add langReq := &languageJSON{} err := json.NewDecoder(r.Body).Decode(langReq) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "reading req: %s", err) </s> remove return User{} </s> add return webUser{} </s> remove return u </s> add return u, true </s> remove // This use of ReadAll is safe, because request's body is now limited. body, err := io.ReadAll(r.Body) if err != nil { msg := fmt.Sprintf("failed to read request body: %s", err) log.Println(msg) http.Error(w, msg, http.StatusBadRequest) </s> add if aghhttp.WriteTextPlainDeprecated(w, r) {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/i18n.go
log.Info(version.Full()) log.Info("service: control action: %s", action)
<mask> // package. It's a noop for other GOOS values. <mask> chooseSystem() <mask> <mask> action := opts.serviceControlAction <mask> log.Printf("service: control action: %s", action) <mask> <mask> if action == "reload" { <mask> sendSigReload() <mask> <mask> return </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove for _, u := range a.users { </s> add for _, u = range a.users { </s> remove for _, u := range a.users { </s> add for _, u = range a.users { </s> remove return User{} </s> add return webUser{} </s> remove // cookieTimeFormat is the format to be used in (time.Time).Format for cookie's // expiry field. const cookieTimeFormat = "Mon, 02 Jan 2006 15:04:05 GMT" // cookieExpiryFormat returns the formatted exp to be used in cookie string. // It's quite simple for now, but probably will be expanded in the future. func cookieExpiryFormat(exp time.Time) (formatted string) { return exp.Format(cookieTimeFormat) } func (a *Auth) httpCookie(req loginJSON, addr string) (cookie string, err error) { blocker := a.blocker u := a.UserFind(req.Name, req.Password) if len(u.Name) == 0 { if blocker != nil { blocker.inc(addr) </s> add // newCookie creates a new authentication cookie. func (a *Auth) newCookie(req loginJSON, addr string) (c *http.Cookie, err error) { rateLimiter := a.raleLimiter u, ok := a.findUser(req.Name, req.Password) if !ok { if rateLimiter != nil { rateLimiter.inc(addr) </s> remove // UserFind - find a user func (a *Auth) UserFind(login, password string) User { </s> add // findUser returns a user if there is one. func (a *Auth) findUser(login, password string) (u webUser, ok bool) {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/service.go
<mask> return data, nil <mask> } <mask> <mask> func marshalTLS(w http.ResponseWriter, r *http.Request, data tlsConfig) { <mask> w.Header().Set("Content-Type", "application/json") <mask> <mask> if data.CertificateChain != "" { <mask> encoded := base64.StdEncoding.EncodeToString([]byte(data.CertificateChain)) <mask> data.CertificateChain = encoded <mask> } <mask> </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove w.Header().Set("Content-Type", "application/json") </s> add </s> remove w.Header().Set("Content-Type", "application/json") err = json.NewEncoder(w).Encode(result) if err != nil { aghhttp.Error( r, w, http.StatusInternalServerError, "Failed to marshal DHCP found json: %s", err, ) } </s> add </s> remove func optionalAuthThird(w http.ResponseWriter, r *http.Request) (authFirst bool) { authFirst = false </s> add func optionalAuthThird(w http.ResponseWriter, r *http.Request) (mustAuth bool) { if glProcessCookie(r) { log.Debug("auth: authentication is handled by GL-Inet submodule") return false } </s> remove // This use of ReadAll is safe, because request's body is now limited. body, err := io.ReadAll(r.Body) if err != nil { msg := fmt.Sprintf("failed to read request body: %s", err) log.Println(msg) http.Error(w, msg, http.StatusBadRequest) </s> add if aghhttp.WriteTextPlainDeprecated(w, r) { </s> remove func parseCookie(cookie string) string { pairs := strings.Split(cookie, ";") for _, pair := range pairs { pair = strings.TrimSpace(pair) kv := strings.SplitN(pair, "=", 2) if len(kv) != 2 { continue } if kv[0] == sessionCookieName { return kv[1] } } return "" } </s> add
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/tls.go
_ = aghhttp.WriteJSONResponse(w, r, data)
<mask> data.PrivateKeySaved = true <mask> data.PrivateKey = "" <mask> } <mask> <mask> err := json.NewEncoder(w).Encode(data) <mask> if err != nil { <mask> aghhttp.Error( <mask> r, <mask> w, <mask> http.StatusInternalServerError, <mask> "Failed to marshal json with TLS status: %s", <mask> err, <mask> ) <mask> } <mask> } <mask> <mask> // registerWebHandlers registers HTTP handlers for TLS configuration <mask> func (t *TLSMod) registerWebHandlers() { <mask> httpRegister(http.MethodGet, "/control/tls/status", t.handleTLSStatus) </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove w.Header().Set("Content-Type", "application/json") err = json.NewEncoder(w).Encode(data) if err != nil { aghhttp.Error( r, w, http.StatusInternalServerError, "Unable to marshal default addresses to json: %s", err, ) return } </s> add _ = aghhttp.WriteJSONResponse(w, r, data) </s> remove w.Header().Set("Content-Type", "application/json") err = json.NewEncoder(w).Encode(result) if err != nil { aghhttp.Error( r, w, http.StatusInternalServerError, "Failed to marshal DHCP found json: %s", err, ) } </s> add </s> remove w.Header().Set("Content-Type", "application/json") err = json.NewEncoder(w).Encode(data) if err != nil { aghhttp.Error( r, w, http.StatusInternalServerError, "Unable to marshal default addresses to json: %s", err, ) return } </s> add _ = aghhttp.WriteJSONResponse(w, r, data) </s> remove language := strings.TrimSpace(string(body)) if language == "" { msg := "empty language specified" log.Println(msg) http.Error(w, msg, http.StatusBadRequest) </s> add langReq := &languageJSON{} err := json.NewDecoder(r.Body).Decode(langReq) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "reading req: %s", err) </s> remove w.Header().Set("Content-Type", "application/json") err = json.NewEncoder(w).Encode(resp) if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "Unable to write response json: %s", err) return } </s> add _ = aghhttp.WriteJSONResponse(w, r, resp)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/tls.go
u := webUser{
<mask> if err != nil { <mask> log.Fatalf("Can't use password \"%s\": bcrypt.GenerateFromPassword: %s", passStr, err) <mask> return nil <mask> } <mask> u := User{ <mask> Name: nameStr, <mask> PasswordHash: string(hash), <mask> } <mask> users := []User{u} <mask> diskConf["users"] = users </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove users := []User{u} </s> add users := []webUser{u} </s> remove users := []User{{ </s> add users := []webUser{{ </s> remove users := []User{ </s> add users := []webUser{ </s> remove // This use of ReadAll is safe, because request's body is now limited. body, err := io.ReadAll(r.Body) if err != nil { msg := fmt.Sprintf("failed to read request body: %s", err) log.Println(msg) http.Error(w, msg, http.StatusBadRequest) </s> add if aghhttp.WriteTextPlainDeprecated(w, r) { </s> remove func (a *Auth) GetUsers() []User { </s> add func (a *Auth) GetUsers() []webUser {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/upgrade.go
users := []webUser{u}
<mask> u := User{ <mask> Name: nameStr, <mask> PasswordHash: string(hash), <mask> } <mask> users := []User{u} <mask> diskConf["users"] = users <mask> return nil <mask> } <mask> <mask> // clients: </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove u := User{ </s> add u := webUser{ </s> remove users := []User{{ </s> add users := []webUser{{ </s> remove users := []User{ </s> add users := []webUser{ </s> remove u := &User{ </s> add u := &webUser{ </s> remove func (a *Auth) GetUsers() []User { </s> add func (a *Auth) GetUsers() []webUser {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
internal/home/upgrade.go
'requestBody': 'content': 'application/json': 'schema': '$ref': '#/components/schemas/DhcpFindActiveReq'
<mask> 'tags': <mask> - 'dhcp' <mask> 'operationId': 'checkActiveDhcp' <mask> 'summary': 'Searches for an active DHCP server on the network' <mask> 'responses': <mask> '200': <mask> 'description': 'OK.' <mask> 'content': <mask> 'application/json': <mask> 'schema': </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove 'text/plain': 'examples': 'response': 'value': 'en' </s> add 'application/json': 'schema': '$ref': '#/components/schemas/LanguageSettings' </s> remove 'requestBody': 'content': 'text/plain': 'schema': 'type': 'string' 'enum': - 'EARLY_CHILDHOOD' - 'YOUNG' - 'TEEN' - 'MATURE' 'example': 'sensitivity=TEEN' 'description': | Age sensitivity for parental filtering, EARLY_CHILDHOOD is 3 YOUNG is 10 TEEN is 13 MATURE is 17 'required': true </s> add </s> remove 'type': 'string' 'example': 'en' </s> add '$ref': '#/components/schemas/LanguageSettings' </s> remove 'text/plain': </s> add 'application/json':
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
openapi/openapi.yaml
<mask> 'tags': <mask> - 'parental' <mask> 'operationId': 'parentalEnable' <mask> 'summary': 'Enable parental filtering' <mask> 'requestBody': <mask> 'content': <mask> 'text/plain': <mask> 'schema': <mask> 'type': 'string' <mask> 'enum': <mask> - 'EARLY_CHILDHOOD' <mask> - 'YOUNG' <mask> - 'TEEN' <mask> - 'MATURE' <mask> 'example': 'sensitivity=TEEN' <mask> 'description': | <mask> Age sensitivity for parental filtering, <mask> EARLY_CHILDHOOD is 3 <mask> YOUNG is 10 <mask> TEEN is 13 <mask> MATURE is 17 <mask> 'required': true <mask> 'responses': <mask> '200': <mask> 'description': 'OK.' <mask> '/parental/disable': <mask> 'post': </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove 'text/plain': 'examples': 'response': 'value': 'en' </s> add 'application/json': 'schema': '$ref': '#/components/schemas/LanguageSettings' </s> remove 'type': 'string' 'example': 'en' </s> add '$ref': '#/components/schemas/LanguageSettings' </s> remove 'text/plain': </s> add 'application/json':
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
openapi/openapi.yaml
'application/json':
<mask> 'summary': > <mask> Change current language. Argument must be an ISO 639-1 two-letter code. <mask> 'requestBody': <mask> 'content': <mask> 'text/plain': <mask> 'schema': <mask> 'type': 'string' <mask> 'example': 'en' <mask> 'description': > <mask> New language. It must be known to the server and must be an ISO 639-1 </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove 'type': 'string' 'example': 'en' </s> add '$ref': '#/components/schemas/LanguageSettings' </s> remove 'requestBody': 'content': 'text/plain': 'schema': 'type': 'string' 'enum': - 'EARLY_CHILDHOOD' - 'YOUNG' - 'TEEN' - 'MATURE' 'example': 'sensitivity=TEEN' 'description': | Age sensitivity for parental filtering, EARLY_CHILDHOOD is 3 YOUNG is 10 TEEN is 13 MATURE is 17 'required': true </s> add
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
openapi/openapi.yaml
'$ref': '#/components/schemas/LanguageSettings'
<mask> 'requestBody': <mask> 'content': <mask> 'text/plain': <mask> 'schema': <mask> 'type': 'string' <mask> 'example': 'en' <mask> 'description': > <mask> New language. It must be known to the server and must be an ISO 639-1 <mask> two-letter code. <mask> 'responses': <mask> '200': </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove 'text/plain': </s> add 'application/json': </s> remove 'requestBody': 'content': 'text/plain': 'schema': 'type': 'string' 'enum': - 'EARLY_CHILDHOOD' - 'YOUNG' - 'TEEN' - 'MATURE' 'example': 'sensitivity=TEEN' 'description': | Age sensitivity for parental filtering, EARLY_CHILDHOOD is 3 YOUNG is 10 TEEN is 13 MATURE is 17 'required': true </s> add </s> remove 'text/plain': 'examples': 'response': 'value': 'en' </s> add 'application/json': 'schema': '$ref': '#/components/schemas/LanguageSettings'
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
openapi/openapi.yaml
'application/json': 'schema': '$ref': '#/components/schemas/LanguageSettings'
<mask> 'responses': <mask> '200': <mask> 'description': 'OK.' <mask> 'content': <mask> 'text/plain': <mask> 'examples': <mask> 'response': <mask> 'value': 'en' <mask> '/install/get_addresses_beta': <mask> 'get': <mask> 'tags': <mask> - 'install' <mask> 'operationId': 'installGetAddressesBeta' </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove 'requestBody': 'content': 'text/plain': 'schema': 'type': 'string' 'enum': - 'EARLY_CHILDHOOD' - 'YOUNG' - 'TEEN' - 'MATURE' 'example': 'sensitivity=TEEN' 'description': | Age sensitivity for parental filtering, EARLY_CHILDHOOD is 3 YOUNG is 10 TEEN is 13 MATURE is 17 'required': true </s> add </s> remove 'type': 'string' 'example': 'en' </s> add '$ref': '#/components/schemas/LanguageSettings' </s> remove 'text/plain': </s> add 'application/json':
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
openapi/openapi.yaml
'DhcpFindActiveReq': 'description': > Request for checking for other DHCP servers in the network. 'properties': 'interface': 'description': 'The name of the network interface' 'example': 'eth0' 'type': 'string' 'type': 'object'
<mask> '$ref': '#/components/schemas/NetInterface' <mask> <mask> 'DhcpSearchResult': <mask> 'type': 'object' <mask> 'description': > <mask> Information about a DHCP server discovered in the current network. <mask> 'properties': </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove 'type': 'string' 'example': 'en' </s> add '$ref': '#/components/schemas/LanguageSettings' </s> remove 'text/plain': </s> add 'application/json': </s> remove // Perform the following tasks: // . Search for another DHCP server running // . Check if a static IP is configured for the network interface // Respond with results </s> add // findActiveServerReq is the JSON structure for the request to find active DHCP // servers. type findActiveServerReq struct { Interface string `json:"interface"` } // handleDHCPFindActiveServer performs the following tasks: // 1. searches for another DHCP server in the network; // 2. check if a static IP is configured for the network interface; // 3. responds with the results.
[ "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
openapi/openapi.yaml
'LanguageSettings': 'description': 'Language settings object.' 'properties': 'language': 'description': 'The current language or the language to set.' 'type': 'string' 'required': - 'language' 'type': 'object'
<mask> 'message': <mask> 'description': 'The error message, an opaque string.' <mask> 'type': 'string' <mask> 'type': 'object' <mask> 'securitySchemes': <mask> 'basicAuth': <mask> 'type': 'http' <mask> 'scheme': 'basic' </s> Pull request: HOFTIX-csrf Merge in DNS/adguard-home from HOFTIX-csrf to master Squashed commit of the following: commit 75ab27bf6c52b80ab4e7347d7c254fa659eac244 Author: Ainar Garipov <[email protected]> Date: Thu Sep 29 18:45:54 2022 +0300 all: imp cookie security; rm plain-text apis </s> remove 'type': 'string' 'example': 'en' </s> add '$ref': '#/components/schemas/LanguageSettings' </s> remove 'text/plain': </s> add 'application/json': </s> remove 'requestBody': 'content': 'text/plain': 'schema': 'type': 'string' 'enum': - 'EARLY_CHILDHOOD' - 'YOUNG' - 'TEEN' - 'MATURE' 'example': 'sensitivity=TEEN' 'description': | Age sensitivity for parental filtering, EARLY_CHILDHOOD is 3 YOUNG is 10 TEEN is 13 MATURE is 17 'required': true </s> add
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756b14a61de138889130c239406dae43f1f115cb
openapi/openapi.yaml
"bootstrap_dns_desc": "Bootstrap DNS servers are used to resolve IP addresses of the DOH/DOT resolvers you specify as upstreams.", "setup_guide": "Setup guide", "dns_addresses": "DNS addresses"
<mask> "reset_settings": "Reset settings", <mask> "update_announcement": "AdGuard Home {{version}} is now available! <0>Click here</0> for more info.", <mask> "upstream_parallel": "Use parallel queries to speed up resolving by simultaneously querying all upstream servers", <mask> "bootstrap_dns": "Bootstrap DNS servers", <mask> "bootstrap_dns_desc": "Bootstrap DNS servers are used to resolve IP addresses of the DOH/DOT resolvers you specify as upstreams." <mask> } </s> + client: added setup guide page and DNS addresses popover Closes #605 </s> remove <div className="col col-sm-6 col-lg-3"> <Version { ...this.props.dashboard } /> </div> </s> add {!dashboard.processing && <div className="col col-sm-6 col-lg-3"> <Version { ...this.props.dashboard } /> </div> }
[ "keep", "keep", "keep", "keep", "replace", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756c5ac0d3c9b685f95cc755ad098cef74e0c517
client/src/__locales/en.json
import SetupGuide from '../../containers/SetupGuide';
<mask> import Dashboard from '../../containers/Dashboard'; <mask> import Settings from '../../containers/Settings'; <mask> import Filters from '../../containers/Filters'; <mask> import Logs from '../../containers/Logs'; <mask> import Footer from '../ui/Footer'; <mask> import Toasts from '../Toasts'; <mask> import Status from '../ui/Status'; <mask> import UpdateTopline from '../ui/UpdateTopline'; <mask> import EncryptionTopline from '../ui/EncryptionTopline'; <mask> import i18n from '../../i18n'; </s> + client: added setup guide page and DNS addresses popover Closes #605 </s> remove import Tabs from '../../components/ui/Tabs'; import Icons from '../../components/ui/Icons'; </s> add import Guide from '../../components/ui/Guide'; </s> remove import { REPOSITORY } from '../../helpers/constants'; </s> add </s> remove const { dnsVersion, dnsAddress, dnsPort } = props; </s> add const { dnsVersion, dnsAddresses, dnsPort } = props;
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756c5ac0d3c9b685f95cc755ad098cef74e0c517
client/src/components/App/index.js
import Footer from '../ui/Footer';
<mask> import Filters from '../../containers/Filters'; <mask> import Logs from '../../containers/Logs'; <mask> import SetupGuide from '../../containers/SetupGuide'; <mask> import Toasts from '../Toasts'; <mask> import Status from '../ui/Status'; <mask> import UpdateTopline from '../ui/UpdateTopline'; <mask> import EncryptionTopline from '../ui/EncryptionTopline'; <mask> import i18n from '../../i18n'; <mask> <mask> class App extends Component { </s> + client: added setup guide page and DNS addresses popover Closes #605 </s> remove import Footer from '../ui/Footer'; </s> add import SetupGuide from '../../containers/SetupGuide'; </s> remove import { REPOSITORY } from '../../helpers/constants'; </s> add </s> remove import Tabs from '../../components/ui/Tabs'; import Icons from '../../components/ui/Icons'; </s> add import Guide from '../../components/ui/Guide'; </s> remove const { dnsVersion, dnsAddress, dnsPort } = props; </s> add const { dnsVersion, dnsAddresses, dnsPort } = props;
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756c5ac0d3c9b685f95cc755ad098cef74e0c517
client/src/components/App/index.js
<Route path="/guide" component={SetupGuide} />
<mask> <Route path="/settings" component={Settings} /> <mask> <Route path="/filters" component={Filters} /> <mask> <Route path="/logs" component={Logs} /> <mask> </Fragment> <mask> } <mask> </div> <mask> <Footer /> <mask> <Toasts /> <mask> </Fragment> </s> + client: added setup guide page and DNS addresses popover Closes #605 </s> remove <div className="col col-sm-6 col-lg-3"> <Version { ...this.props.dashboard } /> </div> </s> add {!dashboard.processing && <div className="col col-sm-6 col-lg-3"> <Version { ...this.props.dashboard } /> </div> } </s> remove <Icons /> <Tabs> <div label="Router"> <div className="tab__title"> <Trans>install_devices_router</Trans> </div> <div className="tab__text"> <p><Trans>install_devices_router_desc</Trans></p> <ol> <li><Trans>install_devices_router_list_1</Trans></li> <li><Trans>install_devices_router_list_2</Trans></li> <li><Trans>install_devices_router_list_3</Trans></li> </ol> </div> </div> <div label="Windows"> <div className="tab__title"> Windows </div> <div className="tab__text"> <ol> <li><Trans>install_devices_windows_list_1</Trans></li> <li><Trans>install_devices_windows_list_2</Trans></li> <li><Trans>install_devices_windows_list_3</Trans></li> <li><Trans>install_devices_windows_list_4</Trans></li> <li><Trans>install_devices_windows_list_5</Trans></li> <li><Trans>install_devices_windows_list_6</Trans></li> </ol> </div> </div> <div label="macOS"> <div className="tab__title"> macOS </div> <div className="tab__text"> <ol> <li><Trans>install_devices_macos_list_1</Trans></li> <li><Trans>install_devices_macos_list_2</Trans></li> <li><Trans>install_devices_macos_list_3</Trans></li> <li><Trans>install_devices_macos_list_4</Trans></li> </ol> </div> </div> <div label="Android"> <div className="tab__title"> Android </div> <div className="tab__text"> <ol> <li><Trans>install_devices_android_list_1</Trans></li> <li><Trans>install_devices_android_list_2</Trans></li> <li><Trans>install_devices_android_list_3</Trans></li> <li><Trans>install_devices_android_list_4</Trans></li> <li><Trans>install_devices_android_list_5</Trans></li> </ol> </div> </div> <div label="iOS"> <div className="tab__title"> iOS </div> <div className="tab__text"> <ol> <li><Trans>install_devices_ios_list_1</Trans></li> <li><Trans>install_devices_ios_list_2</Trans></li> <li><Trans>install_devices_ios_list_3</Trans></li> <li><Trans>install_devices_ios_list_4</Trans></li> </ol> </div> </div> </Tabs> </s> add <Guide /> </s> remove <Trans>faq</Trans> </a> </s> add <Trans>setup_guide</Trans> </NavLink> </s> remove <div className="nav-version__text"> <Trans>address</Trans>: <span className="nav-version__value">{dnsAddress}:{dnsPort}</span> </s> add <div className="nav-version__link"> <div className="popover__trigger popover__trigger--address"> <Trans>dns_addresses</Trans> </div> <div className="popover__body popover__body--address"> <div className="popover__list"> {dnsAddresses .map(ip => <li key={ip}>{getDnsAddress(ip, dnsPort)}</li>) } </div> </div> </s> remove const { dnsVersion, dnsAddress, dnsPort } = props; </s> add const { dnsVersion, dnsAddresses, dnsPort } = props;
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756c5ac0d3c9b685f95cc755ad098cef74e0c517
client/src/components/App/index.js
.nav-version__link { position: relative; display: inline-block; border-bottom: 1px dashed #495057; cursor: pointer; }
<mask> } <mask> <mask> .header-brand-img { <mask> height: 32px; <mask> } <mask> </s> + client: added setup guide page and DNS addresses popover Closes #605 </s> remove <div className="col col-sm-6 col-lg-3"> <Version { ...this.props.dashboard } /> </div> </s> add {!dashboard.processing && <div className="col col-sm-6 col-lg-3"> <Version { ...this.props.dashboard } /> </div> } </s> remove const { dnsVersion, dnsAddress, dnsPort } = props; </s> add const { dnsVersion, dnsAddresses, dnsPort } = props;
[ "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756c5ac0d3c9b685f95cc755ad098cef74e0c517
client/src/components/Header/Header.css
<mask> import PropTypes from 'prop-types'; <mask> import enhanceWithClickOutside from 'react-click-outside'; <mask> import classnames from 'classnames'; <mask> import { Trans, withNamespaces } from 'react-i18next'; <mask> import { REPOSITORY } from '../../helpers/constants'; <mask> <mask> class Menu extends Component { <mask> handleClickOutside = () => { <mask> this.props.closeMenu(); <mask> }; </s> + client: added setup guide page and DNS addresses popover Closes #605 </s> remove import Tabs from '../../components/ui/Tabs'; import Icons from '../../components/ui/Icons'; </s> add import Guide from '../../components/ui/Guide'; </s> remove const { dnsVersion, dnsAddress, dnsPort } = props; </s> add const { dnsVersion, dnsAddresses, dnsPort } = props; </s> remove import Footer from '../ui/Footer'; </s> add import SetupGuide from '../../containers/SetupGuide';
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756c5ac0d3c9b685f95cc755ad098cef74e0c517
client/src/components/Header/Menu.js
<NavLink to="/guide" href="/guide" className="nav-link">
<mask> <Trans>query_log</Trans> <mask> </NavLink> <mask> </li> <mask> <li className="nav-item"> <mask> <a href={`${REPOSITORY.URL}/wiki`} className="nav-link" target="_blank" rel="noopener noreferrer"> <mask> <svg className="nav-icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="#66b574" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><circle cx="12" cy="12" r="10"></circle><path d="M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"></path><line x1="12" y1="17" x2="12" y2="17"></line></svg> <mask> <Trans>faq</Trans> <mask> </a> <mask> </li> <mask> </ul> </s> + client: added setup guide page and DNS addresses popover Closes #605 </s> remove <Trans>faq</Trans> </a> </s> add <Trans>setup_guide</Trans> </NavLink> </s> remove <div className="nav-version__text"> <Trans>address</Trans>: <span className="nav-version__value">{dnsAddress}:{dnsPort}</span> </s> add <div className="nav-version__link"> <div className="popover__trigger popover__trigger--address"> <Trans>dns_addresses</Trans> </div> <div className="popover__body popover__body--address"> <div className="popover__list"> {dnsAddresses .map(ip => <li key={ip}>{getDnsAddress(ip, dnsPort)}</li>) } </div> </div> </s> remove import Footer from '../ui/Footer'; </s> add import SetupGuide from '../../containers/SetupGuide';
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756c5ac0d3c9b685f95cc755ad098cef74e0c517
client/src/components/Header/Menu.js
<Trans>setup_guide</Trans> </NavLink>
<mask> </li> <mask> <li className="nav-item"> <mask> <a href={`${REPOSITORY.URL}/wiki`} className="nav-link" target="_blank" rel="noopener noreferrer"> <mask> <svg className="nav-icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="#66b574" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><circle cx="12" cy="12" r="10"></circle><path d="M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"></path><line x1="12" y1="17" x2="12" y2="17"></line></svg> <mask> <Trans>faq</Trans> <mask> </a> <mask> </li> <mask> </ul> <mask> </div> <mask> </Fragment> <mask> ); </s> + client: added setup guide page and DNS addresses popover Closes #605 </s> remove <a href={`${REPOSITORY.URL}/wiki`} className="nav-link" target="_blank" rel="noopener noreferrer"> </s> add <NavLink to="/guide" href="/guide" className="nav-link"> </s> remove <div className="nav-version__text"> <Trans>address</Trans>: <span className="nav-version__value">{dnsAddress}:{dnsPort}</span> </s> add <div className="nav-version__link"> <div className="popover__trigger popover__trigger--address"> <Trans>dns_addresses</Trans> </div> <div className="popover__body popover__body--address"> <div className="popover__list"> {dnsAddresses .map(ip => <li key={ip}>{getDnsAddress(ip, dnsPort)}</li>) } </div> </div> </s> remove <div className="col col-sm-6 col-lg-3"> <Version { ...this.props.dashboard } /> </div> </s> add {!dashboard.processing && <div className="col col-sm-6 col-lg-3"> <Version { ...this.props.dashboard } /> </div> } </s> remove <Icons /> <Tabs> <div label="Router"> <div className="tab__title"> <Trans>install_devices_router</Trans> </div> <div className="tab__text"> <p><Trans>install_devices_router_desc</Trans></p> <ol> <li><Trans>install_devices_router_list_1</Trans></li> <li><Trans>install_devices_router_list_2</Trans></li> <li><Trans>install_devices_router_list_3</Trans></li> </ol> </div> </div> <div label="Windows"> <div className="tab__title"> Windows </div> <div className="tab__text"> <ol> <li><Trans>install_devices_windows_list_1</Trans></li> <li><Trans>install_devices_windows_list_2</Trans></li> <li><Trans>install_devices_windows_list_3</Trans></li> <li><Trans>install_devices_windows_list_4</Trans></li> <li><Trans>install_devices_windows_list_5</Trans></li> <li><Trans>install_devices_windows_list_6</Trans></li> </ol> </div> </div> <div label="macOS"> <div className="tab__title"> macOS </div> <div className="tab__text"> <ol> <li><Trans>install_devices_macos_list_1</Trans></li> <li><Trans>install_devices_macos_list_2</Trans></li> <li><Trans>install_devices_macos_list_3</Trans></li> <li><Trans>install_devices_macos_list_4</Trans></li> </ol> </div> </div> <div label="Android"> <div className="tab__title"> Android </div> <div className="tab__text"> <ol> <li><Trans>install_devices_android_list_1</Trans></li> <li><Trans>install_devices_android_list_2</Trans></li> <li><Trans>install_devices_android_list_3</Trans></li> <li><Trans>install_devices_android_list_4</Trans></li> <li><Trans>install_devices_android_list_5</Trans></li> </ol> </div> </div> <div label="iOS"> <div className="tab__title"> iOS </div> <div className="tab__text"> <ol> <li><Trans>install_devices_ios_list_1</Trans></li> <li><Trans>install_devices_ios_list_2</Trans></li> <li><Trans>install_devices_ios_list_3</Trans></li> <li><Trans>install_devices_ios_list_4</Trans></li> </ol> </div> </div> </Tabs> </s> add <Guide />
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756c5ac0d3c9b685f95cc755ad098cef74e0c517
client/src/components/Header/Menu.js
import { getDnsAddress } from '../../helpers/helpers';
<mask> import PropTypes from 'prop-types'; <mask> import { Trans, withNamespaces } from 'react-i18next'; <mask> <mask> function Version(props) { <mask> const { dnsVersion, dnsAddresses, dnsPort } = props; <mask> return ( <mask> <div className="nav-version"> </s> + client: added setup guide page and DNS addresses popover Closes #605 </s> remove const { dnsVersion, dnsAddress, dnsPort } = props; </s> add const { dnsVersion, dnsAddresses, dnsPort } = props; </s> remove import { REPOSITORY } from '../../helpers/constants'; </s> add </s> remove import Tabs from '../../components/ui/Tabs'; import Icons from '../../components/ui/Icons'; </s> add import Guide from '../../components/ui/Guide'; </s> remove import Footer from '../ui/Footer'; </s> add import SetupGuide from '../../containers/SetupGuide';
[ "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756c5ac0d3c9b685f95cc755ad098cef74e0c517
client/src/components/Header/Version.js
const { dnsVersion, dnsAddresses, dnsPort } = props;
<mask> import PropTypes from 'prop-types'; <mask> import { Trans, withNamespaces } from 'react-i18next'; <mask> <mask> function Version(props) { <mask> const { dnsVersion, dnsAddress, dnsPort } = props; <mask> return ( <mask> <div className="nav-version"> <mask> <div className="nav-version__text"> <mask> <Trans>version</Trans>: <span className="nav-version__value">{dnsVersion}</span> <mask> </div> </s> + client: added setup guide page and DNS addresses popover Closes #605 </s> remove import { REPOSITORY } from '../../helpers/constants'; </s> add </s> remove <div className="nav-version__text"> <Trans>address</Trans>: <span className="nav-version__value">{dnsAddress}:{dnsPort}</span> </s> add <div className="nav-version__link"> <div className="popover__trigger popover__trigger--address"> <Trans>dns_addresses</Trans> </div> <div className="popover__body popover__body--address"> <div className="popover__list"> {dnsAddresses .map(ip => <li key={ip}>{getDnsAddress(ip, dnsPort)}</li>) } </div> </div> </s> remove import Tabs from '../../components/ui/Tabs'; import Icons from '../../components/ui/Icons'; </s> add import Guide from '../../components/ui/Guide'; </s> remove <div className="col col-sm-6 col-lg-3"> <Version { ...this.props.dashboard } /> </div> </s> add {!dashboard.processing && <div className="col col-sm-6 col-lg-3"> <Version { ...this.props.dashboard } /> </div> }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756c5ac0d3c9b685f95cc755ad098cef74e0c517
client/src/components/Header/Version.js
<div className="nav-version__link"> <div className="popover__trigger popover__trigger--address"> <Trans>dns_addresses</Trans> </div> <div className="popover__body popover__body--address"> <div className="popover__list"> {dnsAddresses .map(ip => <li key={ip}>{getDnsAddress(ip, dnsPort)}</li>) } </div> </div>
<mask> <div className="nav-version"> <mask> <div className="nav-version__text"> <mask> <Trans>version</Trans>: <span className="nav-version__value">{dnsVersion}</span> <mask> </div> <mask> <div className="nav-version__text"> <mask> <Trans>address</Trans>: <span className="nav-version__value">{dnsAddress}:{dnsPort}</span> <mask> </div> <mask> </div> <mask> ); <mask> } <mask> </s> + client: added setup guide page and DNS addresses popover Closes #605 </s> remove const { dnsVersion, dnsAddress, dnsPort } = props; </s> add const { dnsVersion, dnsAddresses, dnsPort } = props; </s> remove <Icons /> <Tabs> <div label="Router"> <div className="tab__title"> <Trans>install_devices_router</Trans> </div> <div className="tab__text"> <p><Trans>install_devices_router_desc</Trans></p> <ol> <li><Trans>install_devices_router_list_1</Trans></li> <li><Trans>install_devices_router_list_2</Trans></li> <li><Trans>install_devices_router_list_3</Trans></li> </ol> </div> </div> <div label="Windows"> <div className="tab__title"> Windows </div> <div className="tab__text"> <ol> <li><Trans>install_devices_windows_list_1</Trans></li> <li><Trans>install_devices_windows_list_2</Trans></li> <li><Trans>install_devices_windows_list_3</Trans></li> <li><Trans>install_devices_windows_list_4</Trans></li> <li><Trans>install_devices_windows_list_5</Trans></li> <li><Trans>install_devices_windows_list_6</Trans></li> </ol> </div> </div> <div label="macOS"> <div className="tab__title"> macOS </div> <div className="tab__text"> <ol> <li><Trans>install_devices_macos_list_1</Trans></li> <li><Trans>install_devices_macos_list_2</Trans></li> <li><Trans>install_devices_macos_list_3</Trans></li> <li><Trans>install_devices_macos_list_4</Trans></li> </ol> </div> </div> <div label="Android"> <div className="tab__title"> Android </div> <div className="tab__text"> <ol> <li><Trans>install_devices_android_list_1</Trans></li> <li><Trans>install_devices_android_list_2</Trans></li> <li><Trans>install_devices_android_list_3</Trans></li> <li><Trans>install_devices_android_list_4</Trans></li> <li><Trans>install_devices_android_list_5</Trans></li> </ol> </div> </div> <div label="iOS"> <div className="tab__title"> iOS </div> <div className="tab__text"> <ol> <li><Trans>install_devices_ios_list_1</Trans></li> <li><Trans>install_devices_ios_list_2</Trans></li> <li><Trans>install_devices_ios_list_3</Trans></li> <li><Trans>install_devices_ios_list_4</Trans></li> </ol> </div> </div> </Tabs> </s> add <Guide /> </s> remove <div className="col col-sm-6 col-lg-3"> <Version { ...this.props.dashboard } /> </div> </s> add {!dashboard.processing && <div className="col col-sm-6 col-lg-3"> <Version { ...this.props.dashboard } /> </div> }
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756c5ac0d3c9b685f95cc755ad098cef74e0c517
client/src/components/Header/Version.js
dnsVersion: PropTypes.string.isRequired, dnsAddresses: PropTypes.array.isRequired, dnsPort: PropTypes.number.isRequired,
<mask> ); <mask> } <mask> <mask> Version.propTypes = { <mask> dnsVersion: PropTypes.string, <mask> dnsAddress: PropTypes.string, <mask> dnsPort: PropTypes.number, <mask> }; <mask> <mask> export default withNamespaces()(Version); </s> + client: added setup guide page and DNS addresses popover Closes #605 </s> remove import { REPOSITORY } from '../../helpers/constants'; </s> add </s> remove const { dnsVersion, dnsAddress, dnsPort } = props; </s> add const { dnsVersion, dnsAddresses, dnsPort } = props; </s> remove <div className="col col-sm-6 col-lg-3"> <Version { ...this.props.dashboard } /> </div> </s> add {!dashboard.processing && <div className="col col-sm-6 col-lg-3"> <Version { ...this.props.dashboard } /> </div> }
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756c5ac0d3c9b685f95cc755ad098cef74e0c517
client/src/components/Header/Version.js
{!dashboard.processing && <div className="col col-sm-6 col-lg-3"> <Version { ...this.props.dashboard } /> </div> }
<mask> isMenuOpen={isMenuOpen} <mask> toggleMenuOpen={this.toggleMenuOpen} <mask> closeMenu={this.closeMenu} <mask> /> <mask> <div className="col col-sm-6 col-lg-3"> <mask> <Version <mask> { ...this.props.dashboard } <mask> /> <mask> </div> <mask> </div> <mask> </div> <mask> </div> <mask> ); <mask> } </s> + client: added setup guide page and DNS addresses popover Closes #605 </s> remove <Icons /> <Tabs> <div label="Router"> <div className="tab__title"> <Trans>install_devices_router</Trans> </div> <div className="tab__text"> <p><Trans>install_devices_router_desc</Trans></p> <ol> <li><Trans>install_devices_router_list_1</Trans></li> <li><Trans>install_devices_router_list_2</Trans></li> <li><Trans>install_devices_router_list_3</Trans></li> </ol> </div> </div> <div label="Windows"> <div className="tab__title"> Windows </div> <div className="tab__text"> <ol> <li><Trans>install_devices_windows_list_1</Trans></li> <li><Trans>install_devices_windows_list_2</Trans></li> <li><Trans>install_devices_windows_list_3</Trans></li> <li><Trans>install_devices_windows_list_4</Trans></li> <li><Trans>install_devices_windows_list_5</Trans></li> <li><Trans>install_devices_windows_list_6</Trans></li> </ol> </div> </div> <div label="macOS"> <div className="tab__title"> macOS </div> <div className="tab__text"> <ol> <li><Trans>install_devices_macos_list_1</Trans></li> <li><Trans>install_devices_macos_list_2</Trans></li> <li><Trans>install_devices_macos_list_3</Trans></li> <li><Trans>install_devices_macos_list_4</Trans></li> </ol> </div> </div> <div label="Android"> <div className="tab__title"> Android </div> <div className="tab__text"> <ol> <li><Trans>install_devices_android_list_1</Trans></li> <li><Trans>install_devices_android_list_2</Trans></li> <li><Trans>install_devices_android_list_3</Trans></li> <li><Trans>install_devices_android_list_4</Trans></li> <li><Trans>install_devices_android_list_5</Trans></li> </ol> </div> </div> <div label="iOS"> <div className="tab__title"> iOS </div> <div className="tab__text"> <ol> <li><Trans>install_devices_ios_list_1</Trans></li> <li><Trans>install_devices_ios_list_2</Trans></li> <li><Trans>install_devices_ios_list_3</Trans></li> <li><Trans>install_devices_ios_list_4</Trans></li> </ol> </div> </div> </Tabs> </s> add <Guide /> </s> remove <div className="nav-version__text"> <Trans>address</Trans>: <span className="nav-version__value">{dnsAddress}:{dnsPort}</span> </s> add <div className="nav-version__link"> <div className="popover__trigger popover__trigger--address"> <Trans>dns_addresses</Trans> </div> <div className="popover__body popover__body--address"> <div className="popover__list"> {dnsAddresses .map(ip => <li key={ip}>{getDnsAddress(ip, dnsPort)}</li>) } </div> </div> </s> remove const { dnsVersion, dnsAddress, dnsPort } = props; </s> add const { dnsVersion, dnsAddresses, dnsPort } = props;
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756c5ac0d3c9b685f95cc755ad098cef74e0c517
client/src/components/Header/index.js
.popover__trigger--address { top: 0; margin: 0; line-height: 1.2; } .popover__trigger--address:after { display: none; }
<mask> } <mask> <mask> .popover__body { <mask> content: ""; <mask> display: flex; <mask> position: absolute; <mask> bottom: calc(100% + 3px); <mask> left: 50%; </s> + client: added setup guide page and DNS addresses popover Closes #605 </s> remove const { dnsVersion, dnsAddress, dnsPort } = props; </s> add const { dnsVersion, dnsAddresses, dnsPort } = props; </s> remove <div className="col col-sm-6 col-lg-3"> <Version { ...this.props.dashboard } /> </div> </s> add {!dashboard.processing && <div className="col col-sm-6 col-lg-3"> <Version { ...this.props.dashboard } /> </div> }
[ "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756c5ac0d3c9b685f95cc755ad098cef74e0c517
client/src/components/ui/Popover.css
.popover__list--bold { font-weight: 700; }
<mask> stroke: #66b574; <mask> } <mask> <mask> .popover__list-title { <mask> margin-bottom: 3px; <mask> } <mask> <mask> .popover__list-item { <mask> margin-bottom: 2px; </s> + client: added setup guide page and DNS addresses popover Closes #605 </s> remove const { dnsVersion, dnsAddress, dnsPort } = props; </s> add const { dnsVersion, dnsAddresses, dnsPort } = props; </s> remove <div className="col col-sm-6 col-lg-3"> <Version { ...this.props.dashboard } /> </div> </s> add {!dashboard.processing && <div className="col col-sm-6 col-lg-3"> <Version { ...this.props.dashboard } /> </div> }
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756c5ac0d3c9b685f95cc755ad098cef74e0c517
client/src/components/ui/Popover.css
import Guide from '../../components/ui/Guide';
<mask> import { reduxForm, formValueSelector } from 'redux-form'; <mask> import { Trans, withNamespaces } from 'react-i18next'; <mask> import flow from 'lodash/flow'; <mask> <mask> import Tabs from '../../components/ui/Tabs'; <mask> import Icons from '../../components/ui/Icons'; <mask> import Controls from './Controls'; <mask> import AddressList from './AddressList'; <mask> <mask> let Devices = props => ( <mask> <div className="setup__step"> </s> + client: added setup guide page and DNS addresses popover Closes #605 </s> remove import { REPOSITORY } from '../../helpers/constants'; </s> add </s> remove const { dnsVersion, dnsAddress, dnsPort } = props; </s> add const { dnsVersion, dnsAddresses, dnsPort } = props; </s> remove import Footer from '../ui/Footer'; </s> add import SetupGuide from '../../containers/SetupGuide';
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756c5ac0d3c9b685f95cc755ad098cef74e0c517
client/src/install/Setup/Devices.js
<Guide />
<mask> isDns={true} <mask> /> <mask> </div> <mask> </div> <mask> <Icons /> <mask> <Tabs> <mask> <div label="Router"> <mask> <div className="tab__title"> <mask> <Trans>install_devices_router</Trans> <mask> </div> <mask> <div className="tab__text"> <mask> <p><Trans>install_devices_router_desc</Trans></p> <mask> <ol> <mask> <li><Trans>install_devices_router_list_1</Trans></li> <mask> <li><Trans>install_devices_router_list_2</Trans></li> <mask> <li><Trans>install_devices_router_list_3</Trans></li> <mask> </ol> <mask> </div> <mask> </div> <mask> <div label="Windows"> <mask> <div className="tab__title"> <mask> Windows <mask> </div> <mask> <div className="tab__text"> <mask> <ol> <mask> <li><Trans>install_devices_windows_list_1</Trans></li> <mask> <li><Trans>install_devices_windows_list_2</Trans></li> <mask> <li><Trans>install_devices_windows_list_3</Trans></li> <mask> <li><Trans>install_devices_windows_list_4</Trans></li> <mask> <li><Trans>install_devices_windows_list_5</Trans></li> <mask> <li><Trans>install_devices_windows_list_6</Trans></li> <mask> </ol> <mask> </div> <mask> </div> <mask> <div label="macOS"> <mask> <div className="tab__title"> <mask> macOS <mask> </div> <mask> <div className="tab__text"> <mask> <ol> <mask> <li><Trans>install_devices_macos_list_1</Trans></li> <mask> <li><Trans>install_devices_macos_list_2</Trans></li> <mask> <li><Trans>install_devices_macos_list_3</Trans></li> <mask> <li><Trans>install_devices_macos_list_4</Trans></li> <mask> </ol> <mask> </div> <mask> </div> <mask> <div label="Android"> <mask> <div className="tab__title"> <mask> Android <mask> </div> <mask> <div className="tab__text"> <mask> <ol> <mask> <li><Trans>install_devices_android_list_1</Trans></li> <mask> <li><Trans>install_devices_android_list_2</Trans></li> <mask> <li><Trans>install_devices_android_list_3</Trans></li> <mask> <li><Trans>install_devices_android_list_4</Trans></li> <mask> <li><Trans>install_devices_android_list_5</Trans></li> <mask> </ol> <mask> </div> <mask> </div> <mask> <div label="iOS"> <mask> <div className="tab__title"> <mask> iOS <mask> </div> <mask> <div className="tab__text"> <mask> <ol> <mask> <li><Trans>install_devices_ios_list_1</Trans></li> <mask> <li><Trans>install_devices_ios_list_2</Trans></li> <mask> <li><Trans>install_devices_ios_list_3</Trans></li> <mask> <li><Trans>install_devices_ios_list_4</Trans></li> <mask> </ol> <mask> </div> <mask> </div> <mask> </Tabs> <mask> </div> <mask> <Controls /> <mask> </div> <mask> ); <mask> </s> + client: added setup guide page and DNS addresses popover Closes #605 </s> remove <div className="col col-sm-6 col-lg-3"> <Version { ...this.props.dashboard } /> </div> </s> add {!dashboard.processing && <div className="col col-sm-6 col-lg-3"> <Version { ...this.props.dashboard } /> </div> } </s> remove <div className="nav-version__text"> <Trans>address</Trans>: <span className="nav-version__value">{dnsAddress}:{dnsPort}</span> </s> add <div className="nav-version__link"> <div className="popover__trigger popover__trigger--address"> <Trans>dns_addresses</Trans> </div> <div className="popover__body popover__body--address"> <div className="popover__list"> {dnsAddresses .map(ip => <li key={ip}>{getDnsAddress(ip, dnsPort)}</li>) } </div> </div> </s> remove const { dnsVersion, dnsAddress, dnsPort } = props; </s> add const { dnsVersion, dnsAddresses, dnsPort } = props; </s> remove <Trans>faq</Trans> </a> </s> add <Trans>setup_guide</Trans> </NavLink>
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/756c5ac0d3c9b685f95cc755ad098cef74e0c517
client/src/install/Setup/Devices.js