The CreatorCon Call for Content is officially open! Get started here.

getting http header information

alizaman
ServiceNow Employee
ServiceNow Employee

Is there any way of extracting the http header information in servicenow.

we got an on premise customer wants to establish if the access to the instance is from trusted source, specially if the users have admin roles.

in the installation exits we can determine their IP address using gs.getSession().getClientIP().toString();

But is there any way we can get the http header information like X-Forwarded-For?

4 REPLIES 4

Alikutty A
Tera Sage

Hi,



Have you tried request.getHeader(' X-Forwarded-For');



I believe this should work on installation exits. You can check the OOB exit for DigestSingleSignOn, it uses a similar call.




Thanks


PS: Hit like, Helpful or Correct depending on the impact of the response


alizaman
ServiceNow Employee
ServiceNow Employee

I have disabled the login exist and tried gs.log to capture the above header but to no avail.


and yes you are right i can see the DigestSingleSignOn script uses the getHeader property.


Deepa Srivastav
Kilo Sage

Try request.getHeader('x-forwarded-for')



or



(below will give you all the headers)



var header = request.headers;


var json = new JSON();


var headerStr = json.encode(header);


gs.log('headers'+headerStr);



Mark Correct if it solved your issue or hit Like and Helpful if you find my response worthy


hi Deepa, i have disabled the OOTB login script and created by overridden with my own script where gs.log fails to capture the header string as you suggested.



but this works


var IP = gs.getSession().getClientIP().toString();


gs.log('IP Address ' + IP);