History

GSF.Web: Updated primary login page to use post-based authentication This forces use and validation of anti-forgery tokens

J. Ritchie Carroll committed 5 years ago

Commit 67449d21 parent e60ff236 files · +45 −23Browse files

Showing the changes to Source/Libraries/GSF.Web/Security/Scripts (2 of 6 files). Show all

Unified · Split

2 files
  1. Source/Libraries/GSF.Web/Security/Scripts/Login.js +9 −1
  2. Source/Libraries/GSF.Web/Security/Scripts/ntlm.js +9 −3
Source/Libraries/GSF.Web/Security/Scripts/Login.js+9−1
@@ -29,6 +29,7 @@ · 28 unmodified lines
2929 // boolean unsecureConnection: flag that indicates if connection is secure
3030 // string verificationHeader: HTTP header name used to transmit anti-forgery value
3131 // string verificationValue: server generated anti-forgery verification token value
32+// string useAjaxVerfication: HTTP header named use to indicate an AJAX post
3233 // string redirectPageLabel: user label for redirect location, e.g., main or target
3334
3435 function loadSettings() {
@@ -54,6 +55,7 @@ function authenticateBasic(username, password) { · 19 unmodified lines
5455 $.ajax({
5556 cache: false,
5657 url: securePage,
58+ type: "post",
5759 complete: function (xhr) {
5860 switch (xhr.status) {
5961 case 200:
@@ -70,6 +72,7 @@ function authenticateBasic(username, password) { · 10 unmodified lines
7072
7173 xhr.setRequestHeader("Authorization", "Basic " + btoa(username + ":" + password));
7274 xhr.setRequestHeader(verificationHeader, verificationValue);
75+ xhr.setRequestHeader(useAjaxVerfication, "true");
7376 }
7477 });
7578 }
@@ -85,7 +88,8 @@ function authenticateNTLM(username, password) { · 9 unmodified lines
8588 loginComplete(true);
8689 else
8790 loginFailed(response);
88− }, verificationHeader, verificationValue);
91+ },
92+ verificationHeader, verificationValue, useAjaxVerfication);
8993 }
9094
9195 // Authorize user with pass-through basic authentication without credentials
@@ -94,6 +98,7 @@ function passthroughBasic() { · 2 unmodified lines
9498 $.ajax({
9599 cache: false,
96100 url: securePage,
101+ type: "post",
97102 complete: function (xhr) {
98103 switch (xhr.status) {
99104 case 200:
@@ -106,6 +111,7 @@ function passthroughBasic() { · 6 unmodified lines
106111 },
107112 beforeSend: function (xhr) {
108113 xhr.setRequestHeader(verificationHeader, verificationValue);
114+ xhr.setRequestHeader(useAjaxVerfication, "true");
109115 }
110116 });
111117 }
@@ -116,6 +122,7 @@ function passthroughNTLM() { · 4 unmodified lines
116122 $.ajax({
117123 cache: false,
118124 url: securePage + "?scheme=NTLM",
125+ type: "post",
119126 complete: function (xhr) {
120127 if (xhr.status === 200) {
121128 loginComplete(true);
@@ -131,6 +138,7 @@ function passthroughNTLM() { · 9 unmodified lines
131138 },
132139 beforeSend: function (xhr) {
133140 xhr.setRequestHeader(verificationHeader, verificationValue);
141+ xhr.setRequestHeader(useAjaxVerfication, "true");
134142 }
135143 });
136144 }
Source/Libraries/GSF.Web/Security/Scripts/ntlm.js+9−3
@@ -252,7 +252,7 @@ Ntlm.isChallenge = function(xhr) { · 251 unmodified lines
252252 return header && header.indexOf("NTLM") !== -1;
253253 };
254254
255−Ntlm.authenticate = function(url, handleResponse, verificationHeader, verificationValue) {
255+Ntlm.authenticate = function (url, handleResponse, verificationHeader, verificationValue, useAjaxVerfication) {
256256 if (!Ntlm.domain || !Ntlm.username || !Ntlm.lmHashedPassword || !Ntlm.ntHashedPassword) {
257257 Ntlm.error("No NTLM credentials specified. Use Ntlm.setCredentials(...) before making calls.");
258258 return;
@@ -268,6 +268,7 @@ Ntlm.authenticate = function(url, handleResponse, verificationHeader, verificati · 9 unmodified lines
268268
269269 $.ajax({
270270 url: url,
271+ type: "post",
271272 cache: false,
272273 crossDomain: false,
273274 xhrFields: {
@@ -278,6 +279,7 @@ Ntlm.authenticate = function(url, handleResponse, verificationHeader, verificati · 4 unmodified lines
278279 case 401:
279280 $.ajax({
280281 url: url,
282+ type: "post",
281283 cache: false,
282284 crossDomain: false,
283285 xhrFields: {
@@ -293,8 +295,10 @@ Ntlm.authenticate = function(url, handleResponse, verificationHeader, verificati · 9 unmodified lines
293295
294296 xhr2.setRequestHeader("Authorization", "NTLM " + msg3.toBase64());
295297
296− if (verificationHeader && verificationValue)
298+ if (verificationHeader && verificationValue) {
297299 xhr2.setRequestHeader(verificationHeader, verificationValue);
300+ xhr2.setRequestHeader(useAjaxVerfication, "true");
301+ }
298302 }
299303 });
300304 break;
@@ -307,8 +311,10 @@ Ntlm.authenticate = function(url, handleResponse, verificationHeader, verificati · 6 unmodified lines
307311 const msg1 = Ntlm.createMessage1(hostname);
308312 xhr.setRequestHeader("Authorization", "NTLM " + msg1.toBase64());
309313
310− if (verificationHeader && verificationValue)
314+ if (verificationHeader && verificationValue) {
311315 xhr.setRequestHeader(verificationHeader, verificationValue);
316+ xhr.setRequestHeader(useAjaxVerfication, "true");
317+ }
312318 }
313319 });
314320 };

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t