Skip to main content

Expressions

A policy is written with Common Expression Language (CEL) expressions to determine on which connections it is applicable. Each policy expression must evaluate to true in order for the policy's actions to take effect against a connection.

Variables

Attributes of the connection are exposed on the conn struct. The following variables are available using this struct:

NameTypeDescription
conn.ClientIPstringThe source IP of the TCP connection to the ngrok endpoint.
conn.Geo.CountryCodestringThe two-letter ISO country code based on the client IP.
conn.Geo.LatitudestringThe approximate latitude based on the client IP.
conn.Geo.LongitudestringThe approximate longitude based on the client IP.
conn.Geo.LatLongRadiusKmstringThe radius in kilometers around the latitude and longitude where the client IP is likely to originate.

Attributes of the request are exposed on the req struct. The following variables are available using this struct:

NameTypeDescription
req.MethodstringThe request method.
req.URLstringThe URL of the request.
req.ParamsmapThe query parameters of the request URL wherein a string key maps to a list of string values.
req.ProtocolstringThe protocol version of the request.
req.HoststringThe host of the request.
req.LocationstringThe 'Location' header of the request.
req.CookieslistThe list of http cookie objects provided in the request.
req.HeadersmapThe headers of the request wherein a string key maps to a list of string values.
req.TrailersmapThe trailers of the request wherein a string key maps to a list of string values.
req.FormmapThe url-encoded form data of the request wherein a string key maps to a list of string values.
req.ContentLengthintThe length of the content associated with the request.
req.ClientTLS.CertCNstringThe subject common name of the client's leaf TLS certificate
req.ClientTLS.CipherSuitestringThe cipher suite negotiated on the connection.
req.ClientTLS.VersionstringThe TLS Version used on the connection.
req.ClientTLS.SNIstringThe Server Name Indication extension sent by the client.

Attributes of the response are exposed on the res struct. The following variables are available for use on outbound policy expressions using this struct:

NameTypeDescription
res.StatusCodestringThe status code of the response.
res.LocationstringThe 'Location' header of the response.
res.CookieslistThe list of http cookie objects provided in the response.
res.HeadersmapThe headers of the response wherein a string key maps to a list of string values.
res.TrailersmapThe trailers of the resposne wherein a string key maps to a list of string values.
res.ContentLengthintThe length of the content associated with the response.
res.ServerTLS.CertCNstringThe subject common name of the leaf TLS certificate.
res.ServerTLS.CipherSuitestringThe cipher suite negotiated on the connection.
res.ServerTLS.VersionstringThe TLS Version used on the connection.
res.ServerTLS.SNIstringThe Server Name Indication extension sent by the client.

Macros

CEL provides a set of predefined macros that can also be used in policy expressions. For convenience, the following custom macros are also supported:

NameReturn TypeDescription
hasReqHeader(string)boolReturns true or false if the provided header key is present on the request.
getReqHeader(string)listReturns a list of header values for the provided key on the request.
hasQueryParam(string)boolReturns true or false if the specified query parameter key is part of the request URL.
getQueryParam(string)listReturns a list of the query parameter values from the request URL for the specified key.
hasReqCookie(string)boolReturns true or false if a cookie exists on the request with the specified name.
getReqCookie(string)boolReturns the cookie struct for the specified cookie name, if it exists on the request.
hasResHeader(string)boolReturns true or false if the provided header key is present on the response.
getResHeader(string)listReturns a list of header values for the provided key on the response.
hasResCookie(string)boolReturns true or false if a cookie exists on the response with the specified name.
getResCookie(string)boolReturns the cookie struct for the specified cookie name, if it exists on the response.