File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import (
1212 "errors"
1313 "io/fs"
1414 "log"
15+ "net"
1516 "net/http"
1617 "os"
1718 "os/signal"
@@ -68,11 +69,12 @@ func verifySession(token string) bool {
6869 if len (sig ) != len (expected ) || subtle .ConstantTimeCompare (sig , expected ) != 1 {
6970 return false
7071 }
71- parts2 := strings .SplitN (string (payload ), "@" , 2 )
72- if len (parts2 ) != 2 {
72+ payloadStr := string (payload )
73+ atIdx := strings .LastIndex (payloadStr , "@" )
74+ if atIdx < 0 {
7375 return false
7476 }
75- expiry , err := strconv .ParseInt (parts2 [ 1 ], 10 , 64 )
77+ expiry , err := strconv .ParseInt (payloadStr [ atIdx + 1 : ], 10 , 64 )
7678 if err != nil || time .Now ().Unix () > expiry {
7779 return false
7880 }
@@ -109,6 +111,9 @@ func handleLogin(w http.ResponseWriter, r *http.Request) {
109111 return
110112 }
111113 ip := r .RemoteAddr
114+ if host , _ , err := net .SplitHostPort (ip ); err == nil {
115+ ip = host
116+ }
112117 loginMu .Lock ()
113118 fe := failCount [ip ]
114119 now := time .Now ()
Original file line number Diff line number Diff line change @@ -204,6 +204,10 @@ <h1>🐳 <span id="appTitle">Docker Image Watcher</span> <small id="status"></sm
204204 bar . parentElement . classList . add ( 'checking' ) ;
205205 try {
206206 const res = await fetch ( '/api/images' ) ;
207+ if ( res . status === 401 ) {
208+ window . location . href = '/login.html' ;
209+ return ;
210+ }
207211 const groups = await res . json ( ) ;
208212 render ( groups ) ;
209213 bar . textContent = t . images ( groups . length ) ;
You can’t perform that action at this time.
0 commit comments