Skip to content

RateLimit didn't check if trusted proxy send the header x-forwarded-for #343

Open
@thib3113

Description

@thib3113

Just found this reading the code :

https://github.com/moleculerjs/moleculer-web/blob/master/src/index.js#L1351C47-L1351C47

let opts = Object.assign({}, {
	window: 60 * 1000,
	limit: 30,
	headers: false,
	key: (req) => {
		return req.headers["x-forwarded-for"] ||
			req.connection.remoteAddress ||
			req.socket.remoteAddress ||
			req.connection.socket.remoteAddress;
	}
}, rateLimit);

getting ip from x-forwarded-for without checking if connection.remoteAddress is a trusted proxy is a security problem .

because I can send the header x-forwarded-for manually .

( not a big problem, but keep in mind that someone can bypass the rate limiter ) .

Also, while headers are lowercase in node.js, this is not the case for all implementations. For example, node.js in AWS Lambda does not convert headers to lowercase.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions