Test Case 5: Editing the “Allow” Header

Last Updated : Apr 24, 2018 |

Use case

The Allow header indicates the methods supported by the user agent. For example, Allow: INVITE, ACK, BYE, INFO, OPTIONS, CANCEL. The OPTIONS method is used to query a user agent or server about its capabilities and discover its current availability. The response to the request lists the capabilities of the user agent or server. This listing might not be desired probably due to security reasons. In this case, the SBC can strip the OPTIONS method from the Allow header before sending out the message.

Script

within session "INVITE"
{
	/*Look for INVITE messages only.  This is specified with the extra condition %METHOD="INVITE" in the "where" clause*/

act on request where %DIRECTION="INBOUND" and %ENTRY_POINT="AFTER_NETWORK" and %METHOD="INVITE"
{

/*There could be i.multiple methods in Allow or ii. OPTIONS could be the only method in Allow.  If there are multiple methods in Allow, OPTIONS could be i. in the beginning 2. in the middle/the end */					

/*If OPTIONS is in the middle/end in Allow, it would be of the form Allow:<Methods>,OPTIONS,<More methods> or Allow:<Methods>,OPTIONS. So, we try to match "Allow"  against the regex ,OPTIONS */
				if(%HEADERS["Allow"][1].regex_match(", OPTIONS"))then
				{
				/*<string1>regex_replace(“<regex1>”,”<string2>”) looks for regex1(regular expression)  in string1 and replaces it with string2(plain string). Here we replace ,OPTIONS with  an empty string, indirectly removing ,OPTIONS*/
						%HEADERS["Allow"][1].regex_replace(", OPTIONS","");
					}
								else
								{
								/*Nested if-else*/
								/*If OPTIONS is in the beginning in Allow, it would be of the form
								Allow: OPTIONS,<More methods>. So, we try to match "Allow" against the regex OPTIONS, */
										if(%HEADERS["Allow"][1].regex_match(" OPTIONS,"))then
										{
								/* We replace OPTIONS, with an empty string, indirectly removing OPTIONS,*/
												%HEADERS["Allow"][1].regex_replace(" OPTIONS,", "");
										}
										else
										{
								/*If OPTIONS is the only method in Allow, it would be of the form
Allow: OPTIONS. So, we try to match "Allow" against the regex OPTIONS */
 													if(%HEADERS["Allow"][1].regex_match(" OPTIONS"))then
													{
													/*Since OPTIONS is the only method in Allow, we remove the entire header*/
													/*remove(%HEADERS[“<Header-name>”][<Posn>] removes the header specified in
													<Header-name> in Position <Posn>.Here we remove the Allow header*/
																remove(%HEADERS["Allow"][1]);
													}
										}
								}
				}
}

Description

This script is useful while operating on headers such as Allow, Supported, Content-Type, whose values can not be extracted individually as compared to headers like From, To, or Contact.

Limitations

The regular expression in regex_replace can not include the $ symbol.