SimpleSallap:SimpleMCP: Require auth line only for https

Also send 401 error response when appropriate
This commit is contained in:
hanishkvc 2025-12-09 21:01:25 +05:30
parent 9d895b0ed3
commit e04afaa6ff
2 changed files with 8 additions and 3 deletions

View File

@ -43,7 +43,11 @@ class Sec(DictyDataclassMixin):
certFile: str = "" certFile: str = ""
keyFile: str = "" keyFile: str = ""
bearerAuth: str = "" bearerAuth: str = ""
bAuthAlways: bool = True bAuthAlways: bool = False
"""
if true, expects authorization line irrespective of http / https
if false, authorization line needed only for https
"""
@dataclass @dataclass

View File

@ -80,14 +80,14 @@ class ProxyHandler(http.server.BaseHTTPRequestHandler):
bearer_transform() bearer_transform()
authline = self.headers['Authorization'] authline = self.headers['Authorization']
if authline == None: if authline == None:
return mTC.TCOutResponse(False, 400, "WARN:No auth line") return mTC.TCOutResponse(False, 401, "WARN:No auth line")
authlineA = authline.strip().split(' ') authlineA = authline.strip().split(' ')
if len(authlineA) != 2: if len(authlineA) != 2:
return mTC.TCOutResponse(False, 400, "WARN:Invalid auth line") return mTC.TCOutResponse(False, 400, "WARN:Invalid auth line")
if authlineA[0] != 'Bearer': if authlineA[0] != 'Bearer':
return mTC.TCOutResponse(False, 400, "WARN:Invalid auth type") return mTC.TCOutResponse(False, 400, "WARN:Invalid auth type")
if authlineA[1] != gMe.op.bearerTransformed: if authlineA[1] != gMe.op.bearerTransformed:
return mTC.TCOutResponse(False, 400, "WARN:Invalid auth") return mTC.TCOutResponse(False, 401, "WARN:Invalid auth")
return mTC.TCOutResponse(True, 200, "Auth Ok") return mTC.TCOutResponse(True, 200, "Auth Ok")
def send_mcp(self, statusCode: int, statusMessage: str, body: Any): def send_mcp(self, statusCode: int, statusMessage: str, body: Any):
@ -130,6 +130,7 @@ class ProxyHandler(http.server.BaseHTTPRequestHandler):
def mcp_run(self, body: bytes): def mcp_run(self, body: bytes):
oRPC = json.loads(body) oRPC = json.loads(body)
print(f"DBUG:PH:MCP:Method:{oRPC['method']}")
if oRPC["method"] == "tools/call": if oRPC["method"] == "tools/call":
self.mcp_toolscall(oRPC) self.mcp_toolscall(oRPC)
elif oRPC["method"] == "tools/list": elif oRPC["method"] == "tools/list":