handler: Add Www-Authenticate header, update validGitResource (#25)
* Add Www-Authenticate header * Include git-receive-pack in validGitResource
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
#include "../headers/cfHeader.hpp"
|
#include "../headers/cfHeader.hpp"
|
||||||
#include "../headers/xforwardfor.hpp"
|
#include "../headers/xforwardfor.hpp"
|
||||||
#include "../headers/gitProtocolHeader.hpp"
|
#include "../headers/gitProtocolHeader.hpp"
|
||||||
|
#include "../headers/wwwAuthenticateHeader.hpp"
|
||||||
#include "../headers/acceptLanguageHeader.hpp"
|
#include "../headers/acceptLanguageHeader.hpp"
|
||||||
#include "../headers/setCookieHeader.hpp"
|
#include "../headers/setCookieHeader.hpp"
|
||||||
#include "../headers/xrealip.hpp"
|
#include "../headers/xrealip.hpp"
|
||||||
@@ -130,6 +131,7 @@ void CServerHandler::onRequest(const Pistache::Http::Request& req, Pistache::Htt
|
|||||||
std::shared_ptr<const XForwardedForHeader> xForwardedForHeader;
|
std::shared_ptr<const XForwardedForHeader> xForwardedForHeader;
|
||||||
std::shared_ptr<const AuthorizationHeader> authHeader;
|
std::shared_ptr<const AuthorizationHeader> authHeader;
|
||||||
std::shared_ptr<const GitProtocolHeader> gitProtocolHeader;
|
std::shared_ptr<const GitProtocolHeader> gitProtocolHeader;
|
||||||
|
std::shared_ptr<const WwwAuthenticateHeader> wwwAuthenticateHeader;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
hostHeader = Pistache::Http::Header::header_cast<Pistache::Http::Header::Host>(HEADERS.get("Host"));
|
hostHeader = Pistache::Http::Header::header_cast<Pistache::Http::Header::Host>(HEADERS.get("Host"));
|
||||||
@@ -175,6 +177,12 @@ void CServerHandler::onRequest(const Pistache::Http::Request& req, Pistache::Htt
|
|||||||
; // silent ignore
|
; // silent ignore
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
wwwAuthenticateHeader = Pistache::Http::Header::header_cast<WwwAuthenticateHeader>(HEADERS.get("Www-Authenticate"));
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
; // silent ignore
|
||||||
|
}
|
||||||
|
|
||||||
Debug::log(LOG, "New request: {}:{}{}", hostHeader->host(), hostHeader->port().toString(), req.resource());
|
Debug::log(LOG, "New request: {}:{}{}", hostHeader->host(), hostHeader->port().toString(), req.resource());
|
||||||
|
|
||||||
const auto REQUEST_IP = ipForRequest(req);
|
const auto REQUEST_IP = ipForRequest(req);
|
||||||
@@ -202,7 +210,11 @@ void CServerHandler::onRequest(const Pistache::Http::Request& req, Pistache::Htt
|
|||||||
// TODO: ratelimit this, probably.
|
// TODO: ratelimit this, probably.
|
||||||
|
|
||||||
const auto RES = req.resource();
|
const auto RES = req.resource();
|
||||||
bool validGitResource = RES.ends_with("/info/refs") || RES.ends_with("/info/packs") || RES.ends_with("HEAD") || RES.ends_with(".git") || RES.ends_with("/git-upload-pack");
|
bool validGitResource =
|
||||||
|
RES.ends_with("/info/refs") || RES.ends_with("/info/packs") ||
|
||||||
|
RES.ends_with("HEAD") || RES.ends_with(".git") ||
|
||||||
|
RES.ends_with("/git-upload-pack") ||
|
||||||
|
RES.ends_with("/git-receive-pack");
|
||||||
|
|
||||||
if (RES.contains("/objects/")) {
|
if (RES.contains("/objects/")) {
|
||||||
const std::string_view repo = std::string_view{RES}.substr(0, RES.find("/objects/"));
|
const std::string_view repo = std::string_view{RES}.substr(0, RES.find("/objects/"));
|
||||||
|
|||||||
24
src/headers/wwwAuthenticateHeader.hpp
Normal file
24
src/headers/wwwAuthenticateHeader.hpp
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#include <pistache/http_headers.h>
|
||||||
|
#include <pistache/net.h>
|
||||||
|
|
||||||
|
class WwwAuthenticateHeader : public Pistache::Http::Header::Header {
|
||||||
|
public:
|
||||||
|
NAME("Www-Authenticate");
|
||||||
|
|
||||||
|
WwwAuthenticateHeader() = default;
|
||||||
|
|
||||||
|
void parse(const std::string& str) override {
|
||||||
|
m_text = str;
|
||||||
|
}
|
||||||
|
|
||||||
|
void write(std::ostream& os) const override {
|
||||||
|
os << m_text;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string text() const {
|
||||||
|
return m_text;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string m_text = "";
|
||||||
|
};
|
||||||
@@ -12,6 +12,7 @@
|
|||||||
#include "headers/xforwardfor.hpp"
|
#include "headers/xforwardfor.hpp"
|
||||||
#include "headers/cfHeader.hpp"
|
#include "headers/cfHeader.hpp"
|
||||||
#include "headers/gitProtocolHeader.hpp"
|
#include "headers/gitProtocolHeader.hpp"
|
||||||
|
#include "headers/wwwAuthenticateHeader.hpp"
|
||||||
#include "headers/acceptLanguageHeader.hpp"
|
#include "headers/acceptLanguageHeader.hpp"
|
||||||
#include "headers/setCookieHeader.hpp"
|
#include "headers/setCookieHeader.hpp"
|
||||||
#include "headers/xrealip.hpp"
|
#include "headers/xrealip.hpp"
|
||||||
@@ -81,6 +82,7 @@ int main(int argc, char** argv, char** envp) {
|
|||||||
Pistache::Http::Header::Registry::instance().registerHeader<CFConnectingIPHeader>();
|
Pistache::Http::Header::Registry::instance().registerHeader<CFConnectingIPHeader>();
|
||||||
Pistache::Http::Header::Registry::instance().registerHeader<XForwardedForHeader>();
|
Pistache::Http::Header::Registry::instance().registerHeader<XForwardedForHeader>();
|
||||||
Pistache::Http::Header::Registry::instance().registerHeader<GitProtocolHeader>();
|
Pistache::Http::Header::Registry::instance().registerHeader<GitProtocolHeader>();
|
||||||
|
Pistache::Http::Header::Registry::instance().registerHeader<WwwAuthenticateHeader>();
|
||||||
Pistache::Http::Header::Registry::instance().registerHeader<AcceptLanguageHeader>();
|
Pistache::Http::Header::Registry::instance().registerHeader<AcceptLanguageHeader>();
|
||||||
Pistache::Http::Header::Registry::instance().registerHeader<SetCookieHeader>();
|
Pistache::Http::Header::Registry::instance().registerHeader<SetCookieHeader>();
|
||||||
Pistache::Http::Header::Registry::instance().registerHeader<XRealIPHeader>();
|
Pistache::Http::Header::Registry::instance().registerHeader<XRealIPHeader>();
|
||||||
|
|||||||
Reference in New Issue
Block a user