Skip to content

http-auth

The http-auth filter sends the username and password of the AUTH command to an HTTP endpoint. The authentication is accepted when the endpoint answers with a 2xx status and, with json_result, when the JSON response holds the expected value. Otherwise the flow is dropped, and the client gets 535 only if no other flow is left: an OR flow or a flow without an AUTH filter lets the credentials through (see server options).

When the accounts live in another system: an identity provider, an application that already checks passwords, a small service in front of a user database. For one shared account, static-auth needs no endpoint.

credentialsMethod selects the request:

credentialsMethod Request Default method
BASIC_AUTH (default) Authorization: Basic <base64 of username:password> header, no body GET
JSON JSON body, the username at userField ($.username) and the password at passwordField ($.password) POST
FORM_URLENCODED application/x-www-form-urlencoded body, fields userField (username) and passwordField (password) POST

With JSON, the fields are dot separated paths: $.user.login sends {"user": {"login": "…"}}. GET is only possible with BASIC_AUTH; the server does not start with another combination.

With json_result (only with JSON), a 2xx answer is not enough: the response is read as JSON, and the value at json_result.path must equal json_result.value. The comparison is strict and value is a string: a JSON true in the response does not equal "true".

With hmac, each request carries two headers so the endpoint can check that it comes from smtp-relay:

  • X-SMTP-RELAY-TIME: the time of the request, in milliseconds since the epoch;
  • X-SMTP-RELAY (or the name in hmac.header): the hex HMAC, with hmac.secret and hmac.algo (sha256 by default), of <url>\n<method>\n<time>, followed by \n<body> when the request has a body.

The endpoint recomputes the HMAC and should also refuse old times, so a captured request cannot be replayed.

As with every AUTH filter, whether clients must authenticate is set by options.authOptional, and authentication needs TLS unless options.allowInsecureAuth is true. See static-auth.

OptionTypeDescription
credentialsMethod"BASIC_AUTH" | "JSON" | "FORM_URLENCODED"
default "BASIC_AUTH"

How to send the credentials

BASIC_AUTH: in an Authorization: Basic header, without body JSON: in a JSON body, at the userField and passwordField paths FORM_URLENCODED: in an application/x-www-form-urlencoded body, in the userField and passwordField fields

hmacobject

Sign the requests with an HMAC so the endpoint can authenticate them

The request carries the time in milliseconds in the X-SMTP-RELAY-TIME header and the hex HMAC of <url>\n<method>\n<time> (followed by \n<body> when there is a body) in the header header

hmac.algostring
default "sha256"

Hash algorithm of the HMAC, any algorithm of node crypto.getHashes()

hmac.headerstring
default "X-SMTP-RELAY"

Name of the header carrying the signature

hmac.secretrequiredstring

Secret key of the HMAC

json_resultobject

Only with JSON: read the response as JSON and accept the authentication only if the value at path equals value

When not set, the HTTP status alone decides

json_result.pathrequiredstring

Dot separated path of the value in the response, e.g. $.result.allowed

json_result.valuerequiredstring

Expected value, the authentication is accepted if the value at path is equal

method"PUT" | "POST" | "GET"

HTTP method of the request, GET is only allowed with BASIC_AUTH

Defaults to GET with BASIC_AUTH and to POST otherwise

namestring

Name of the component, used in the logs and the output metrics, defaults to <type>_<position in the list>

passwordFieldstring

Field of the password: form field name with FORM_URLENCODED (default password), dot separated path with JSON (default $.password)

typerequired"http-auth"

Type of the component

urlrequiredstring

URL called with the credentials

userFieldstring

Field of the username: form field name with FORM_URLENCODED (default username), dot separated path with JSON (default $.username)

http-auth.jsonc
{
"$schema": "https://raw.githubusercontent.com/loopingz/smtp-relay/main/config.schema.json",
"flows": {
"relay": {
"filters": [
{
"type": "http-auth",
"url": "https://auth.example.com/smtp/login",
"credentialsMethod": "JSON",
// Sends {"login": "...", "secret": "..."}
"userField": "$.login",
"passwordField": "$.secret",
// Accept only if the response is {"result": {"allowed": "yes"}}
"json_result": { "path": "$.result.allowed", "value": "yes" },
"hmac": { "secret": "change-me" }
}
],
"outputs": [{ "type": "aws", "ses": true }]
}
},
"bind": "0.0.0.0",
"options": {
"allowInsecureAuth": false
}
}