diff --git a/app/controllers/core.rb b/app/controllers/core.rb index c9b2388..7421cdf 100644 --- a/app/controllers/core.rb +++ b/app/controllers/core.rb @@ -80,20 +80,11 @@ def saml_request?(effective_uri) def handle_saml_authentication(effective_uri) raise Error::SAMLAuthenticationRequired unless NS::ParsedCli.expect_saml - cookies = BrowserAuthenticator.authenticate(effective_uri.to_s) + # Authenticate using the ferrum browser + BrowserAuthenticator.authenticate(effective_uri.to_s) - # Extract name=value pairs and concatenate into a single string - cookie_string = cookies.map do |cookie| - cookie.split(';').first # Takes only the part before the first semicolon (name=value) - end.join('; ') - - puts cookie_string - - # Now, use these cookies for the scanning process - # NS::Browser.instance.headers['Cookie'] = cookie_string - # Continue scanning - - raise Error::SAMLAuthenticationRequired + # Resume the scan by following the redirect + target.opts[:ignore_main_redirect] = true end # Checks for redirects, an out of scope redirect will raise an Error::HTTPRedirect @@ -103,6 +94,10 @@ def handle_redirection(res) effective_url = target.homepage_res.effective_url # Basically get and follow location of target.url effective_uri = Addressable::URI.parse(effective_url) + if NS::ParsedCli.expect_saml && !saml_request?(effective_uri) + puts 'SAML authentication was expected but not required.' + end + handle_saml_authentication(effective_uri) if saml_request?(effective_uri) handle_scheme_change(effective_url, effective_uri) return if target.in_scope?(effective_url) diff --git a/lib/cms_scanner/browser_authenticator.rb b/lib/cms_scanner/browser_authenticator.rb index d915f72..08d4672 100644 --- a/lib/cms_scanner/browser_authenticator.rb +++ b/lib/cms_scanner/browser_authenticator.rb @@ -12,9 +12,6 @@ def self.authenticate(login_url) puts 'Please log in through the opened browser window. Press enter once done.' gets # Waits for user input - cookies = browser.cookies.all.to_a browser.quit - - cookies end end