You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.2 KiB

  1. From 13c2dc126d8bb4c57273178fc455dab6f02e1efc Mon Sep 17 00:00:00 2001
  2. From: Alexey Sokolov <alexey+znc@asokolov.org>
  3. Date: Thu, 16 Apr 2015 01:21:57 +0100
  4. Subject: [PATCH] Fix rare conflict of HTTP-Basic auth and cookies.
  5. Fix #946
  6. ---
  7. src/HTTPSock.cpp | 10 +++++++++-
  8. 1 file changed, 9 insertions(+), 1 deletion(-)
  9. --- a/src/HTTPSock.cpp
  10. +++ b/src/HTTPSock.cpp
  11. @@ -122,7 +122,7 @@ void CHTTPSock::ReadLine(const CString&
  12. sLine.Token(2).Base64Decode(sUnhashed);
  13. m_sUser = sUnhashed.Token(0, false, ":");
  14. m_sPass = sUnhashed.Token(1, true, ":");
  15. - m_bLoggedIn = OnLogin(m_sUser, m_sPass, true);
  16. + // Postpone authorization attempt until end of headers, because cookies should be read before that, otherwise session id will be overwritten in GetSession()
  17. } else if (sName.Equals("Content-Length:")) {
  18. m_uPostLen = sLine.Token(1).ToULong();
  19. if (m_uPostLen > MAX_POST_SIZE)
  20. @@ -170,6 +170,14 @@ void CHTTPSock::ReadLine(const CString&
  21. } else if (sLine.empty()) {
  22. m_bGotHeader = true;
  23. + if (!m_sUser.empty()) {
  24. + m_bLoggedIn = OnLogin(m_sUser, m_sPass, true);
  25. + if (!m_bLoggedIn) {
  26. + // Error message already was sent
  27. + return;
  28. + }
  29. + }
  30. +
  31. if (m_bPost) {
  32. m_sPostData = GetInternalReadBuffer();
  33. CheckPost();