Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/requestHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,14 @@ function getUserReqHandler(userRule, recorder) {
// construct the original headers as the reqheaders
req.headers = util.getHeaderFromRawHeaders(req.rawHeaders);

// refer to https://github.com/alibaba/anyproxy/issues/555
// prevent request to proxy port
const selfIpAddresses = util.getAllIpAddress()
selfIpAddresses.push('localhost')

const isSelfIpAddress = selfIpAddresses.find((ip) => host === `${ip}:${reqHandlerCtx.httpServerPort}` && req.method !== 'CONNECT')
if (isSelfIpAddress) return userRes.writeHead(405).end()

logUtil.printLog(color.green(`received request to: ${req.method} ${host}${path}`));

/**
Expand Down