File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import (
1111 "encoding/json"
1212 "io/fs"
1313 "log"
14+ "net"
1415 "net/http"
1516 "os"
1617 "os/signal"
@@ -67,11 +68,12 @@ func verifySession(token string) bool {
6768 if len (sig ) != len (expected ) || subtle .ConstantTimeCompare (sig , expected ) != 1 {
6869 return false
6970 }
70- parts2 := strings .SplitN (string (payload ), "@" , 2 )
71- if len (parts2 ) != 2 {
71+ payloadStr := string (payload )
72+ atIdx := strings .LastIndex (payloadStr , "@" )
73+ if atIdx < 0 {
7274 return false
7375 }
74- expiry , err := strconv .ParseInt (parts2 [ 1 ], 10 , 64 )
76+ expiry , err := strconv .ParseInt (payloadStr [ atIdx + 1 : ], 10 , 64 )
7577 if err != nil || time .Now ().Unix () > expiry {
7678 return false
7779 }
@@ -108,6 +110,9 @@ func handleLogin(w http.ResponseWriter, r *http.Request) {
108110 return
109111 }
110112 ip := r .RemoteAddr
113+ if host , _ , err := net .SplitHostPort (ip ); err == nil {
114+ ip = host
115+ }
111116 loginMu .Lock ()
112117 fe := failCount [ip ]
113118 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