Blocking user login via mobile browsers using User-Agent detectionSummary<!-- /*NS Branding Styles*/ --> .ns-kb-css-body-editor-container { p { font-size: 12pt; font-family: Lato; color: var(--now-color--text-primary, #000000); } span { font-size: 12pt; font-family: Lato; color: var(--now-color--text-primary, #000000); } h2 { font-size: 24pt; font-family: Lato; color: var(--now-color--text-primary, black); } h3 { font-size: 18pt; font-family: Lato; color: var(--now-color--text-primary, black); } h4 { font-size: 14pt; font-family: Lato; color: var(--now-color--text-primary, black); } a { font-size: 12pt; font-family: Lato; color: var(--now-color--link-primary, #00718F); } a:hover { font-size: 12pt; color: var(--now-color--link-primary, #024F69); } a:target { font-size: 12pt; color: var(--now-color--link-primary, #032D42); } a:visited { font-size: 12pt; color: var(--now-color--link-primary, #00718f); } ul { font-size: 12pt; font-family: Lato; } li { font-size: 12pt; font-family: Lato; } img { display: ; max-width: ; width: ; height: ; } } When mobile browser access to a ServiceNow instance needs to be restricted, standard API methods alone are insufficient depending on how the mobile web UI is configured. This article explains the behaviour of the glide.ui.m_enabled system property and the `gs.isMobile()` API, and provides a working solution using User-Agent detection combined with the `getFirstPageURL()` script to block mobile browser logins while preserving access for the Classic Mobile App and desktop browsers. Release<!-- /*NS Branding Styles*/ --> .ns-kb-css-body-editor-container { p { font-size: 12pt; font-family: Lato; color: var(--now-color--text-primary, #000000); } span { font-size: 12pt; font-family: Lato; color: var(--now-color--text-primary, #000000); } h2 { font-size: 24pt; font-family: Lato; color: var(--now-color--text-primary, black); } h3 { font-size: 18pt; font-family: Lato; color: var(--now-color--text-primary, black); } h4 { font-size: 14pt; font-family: Lato; color: var(--now-color--text-primary, black); } a { font-size: 12pt; font-family: Lato; color: var(--now-color--link-primary, #00718F); } a:hover { font-size: 12pt; color: var(--now-color--link-primary, #024F69); } a:target { font-size: 12pt; color: var(--now-color--link-primary, #032D42); } a:visited { font-size: 12pt; color: var(--now-color--link-primary, #00718f); } ul { font-size: 12pt; font-family: Lato; } li { font-size: 12pt; font-family: Lato; } img { display: ; max-width: ; width: ; height: ; } } Kingston and later Instructions<!-- /*NS Branding Styles*/ --> .ns-kb-css-body-editor-container { p { font-size: 12pt; font-family: Lato; color: var(--now-color--text-primary, #000000); } span { font-size: 12pt; font-family: Lato; color: var(--now-color--text-primary, #000000); } h2 { font-size: 24pt; font-family: Lato; color: var(--now-color--text-primary, black); } h3 { font-size: 18pt; font-family: Lato; color: var(--now-color--text-primary, black); } h4 { font-size: 14pt; font-family: Lato; color: var(--now-color--text-primary, black); } a { font-size: 12pt; font-family: Lato; color: var(--now-color--link-primary, #00718F); } a:hover { font-size: 12pt; color: var(--now-color--link-primary, #024F69); } a:target { font-size: 12pt; color: var(--now-color--link-primary, #032D42); } a:visited { font-size: 12pt; color: var(--now-color--link-primary, #00718f); } ul { font-size: 12pt; font-family: Lato; } li { font-size: 12pt; font-family: Lato; } img { display: ; max-width: ; width: ; height: ; } } System property: glide.ui.m_enabled The glide.ui.m_enabled system property controls which UI mobile browser users see. When enabled, mobile browsers use the Mobile Web UI, which is the same experience as the Classic Mobile App. When disabled, mobile browsers use the Desktop Web UI, which is the same as the standard desktop browser interface. For reference documentation on disabling the smartphone interface, see Disable the smartphone interface on ServiceNow Docs{:target="_blank"}. API script: gs.isMobile() The `gs.isMobile()` API determines whether a request originates from a mobile device. It returns `true` when a user logs in via the Classic Mobile App or via a mobile browser on the Mobile Web UI. It returns `false` when a user logs in via a mobile browser on the Desktop Web UI (that is, when glide.ui.m_enabled is set to `false`). Because of this behaviour, `gs.isMobile()` cannot reliably identify whether a user is logging in via the Classic Mobile App or via a mobile browser when glide.ui.m_enabled is enabled. ⚠ SME: verify whether a specific gs.isMobile() API documentation page is available on docs.servicenow.com and provide the URL for the Related Links section Identify devices and applications via the User-Agent value in transactions The User-Agent value in the transaction log differs across devices and browsers. Retrieve this value using the following script: var userAgent = GlideTransaction.get().getRequest().getHeader("user-agent"); For example: - Login via iOS Mobile Safari: Mozilla/5.0 (iPhone; CPU iPhone OS 12_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Ve - Login via Mac Chrome: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3 - Login via iOS Classic Mobile App: ServiceNow/6.4 (iPhone; iOS 12.3.1; Scale/2.00) Possible Solution 1 Create a Before Query business rule on the sys_user table: if(gs.isMobile()){ current.addQuery('sys_id','-1'); } This approach only works for the Classic Mobile App and does not work for a mobile browser using the Mobile Web UI. Additionally, this Before Query business rule runs on every transaction that queries the sys_user table, which may cause a potential performance issue. This solution does not work. Possible Solution 2 When a user logs in via a mobile browser, log them out within the getFirstPageURL() script. This script runs only once after login and does not affect performance. The new SPEntryPage().getFirstPageURL() method has the following behaviours. - It works only on the Desktop Web UI. - It runs when a user logs in via a mobile browser on the Desktop Web UI, but it does not run when a user logs in via a mobile browser on the Mobile Web UI. To use this solution, set glide.ui.m_enabled to `false` to force the Desktop Web UI for mobile browser sessions. The `getFirstPageURL()` script can then redirect the user to `/logout.do`. ⚠ SME: verify full navigation paths to locate and update the glide.ui.m_enabled and glide.entry.first.page.script system properties in the instance UI 1. Log in as an admin. 2. Set system property glide.ui.m_enabled to `false`. 3. Set system property glide.entry.first.page.script to `new SPEntryPage().getFirstPageURL()`. 4. Add the following script at the beginning of getFirstPageURL(): var userAgent = GlideTransaction.get().getRequest().getHeader("user-agent"); // User logs in via iOS Mobile Browser. if(userAgent.indexOf('iPhone')>0&&!userAgent.indexOf('ServiceNow')>0){ // Logout the current session gs.setRedirect('/logout.do'); } This solution blocks mobile browser logins without affecting the Classic Mobile App or desktop logins. Related Links<!-- /*NS Branding Styles*/ --> .ns-kb-css-body-editor-container { p { font-size: 12pt; font-family: Lato; color: var(--now-color--text-primary, #000000); } span { font-size: 12pt; font-family: Lato; color: var(--now-color--text-primary, #000000); } h2 { font-size: 24pt; font-family: Lato; color: var(--now-color--text-primary, black); } h3 { font-size: 18pt; font-family: Lato; color: var(--now-color--text-primary, black); } h4 { font-size: 14pt; font-family: Lato; color: var(--now-color--text-primary, black); } a { font-size: 12pt; font-family: Lato; color: var(--now-color--link-primary, #00718F); } a:hover { font-size: 12pt; color: var(--now-color--link-primary, #024F69); } a:target { font-size: 12pt; color: var(--now-color--link-primary, #032D42); } a:visited { font-size: 12pt; color: var(--now-color--link-primary, #00718f); } ul { font-size: 12pt; font-family: Lato; } li { font-size: 12pt; font-family: Lato; } img { display: ; max-width: ; width: ; height: ; } } https://docs.servicenow.com/csh?topicname=t_DisableTheSmartphoneInterface.html&version=latest