Files
pmg/proxy/interceptor.go
T
Sahil BansalandGitHub 5b0517f92a add event type & logging interceptor for unknown hosts (#157)
* add event type & logging interceptor for unknown hosts

* update logging

* add break

* rename host_observation interceptor to audit_logger

* restore MITMDecider and make AuditLogger telemetry skip MITM on CONNECT
2026-02-12 13:48:01 +05:30

84 lines
2.3 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package proxy
import (
"net/http"
"net/url"
"time"
)
// ResponseAction determines how the proxy should handle a request
type ResponseAction int
const (
// ActionAllow forwards the request unchanged
ActionAllow ResponseAction = iota
// ActionBlock blocks the request with an error response
ActionBlock
// ActionModifyRequest modifies the request before forwarding
ActionModifyRequest
// ActionModifyResponse modifies the response after receiving
ActionModifyResponse
)
// RequestContext provides request information to interceptors
// This is passed to ShouldIntercept and HandleRequest methods
type RequestContext struct {
URL *url.URL
Method string
Headers http.Header
// Body is not currently used by the interceptors, but it is here for future use
Body []byte
Hostname string
RequestID string
StartTime time.Time
// Interceptor can store custom data
Data map[string]interface{}
}
// InterceptorResponse defines how the proxy should handle the request
type InterceptorResponse struct {
// Action to take
Action ResponseAction
// For Action = Block: error message to return
BlockMessage string
BlockCode int
// For Action = ModifyRequest: modified headers/body
ModifiedHeaders http.Header
// ModifiedBody is not currently used by the interceptors, but it is here for future use
ModifiedBody []byte
// For Action = ModifyResponse: response modification function
ResponseModifier ResponseModifierFunc
}
// ResponseModifierFunc modifies HTTP response
// It receives the status code, headers, and body, and returns modified versions
type ResponseModifierFunc func(statusCode int, headers http.Header, body []byte) (int, http.Header, []byte, error)
// Interceptor processes HTTP/HTTPS requests and can modify or block them
type Interceptor interface {
// Name returns the interceptor name for logging
Name() string
// ShouldIntercept determines if this interceptor handles the given request
ShouldIntercept(ctx *RequestContext) bool
// HandleRequest processes the request and returns response action
// Called for each request matching ShouldIntercept
HandleRequest(ctx *RequestContext) (*InterceptorResponse, error)
}
// MITMDecider is optional; implement to control whether CONNECT requests are MITMd.
type MITMDecider interface {
ShouldMITM(ctx *RequestContext) bool
}