Преглед на файлове

AMBARI-13056. Ambari should use relative URLs when specifying target after login (rlevas)

Robert Levas преди 10 години
родител
ревизия
cb95865423
променени са 1 файла, в които са добавени 18 реда и са изтрити 2 реда
  1. 18 2
      ambari-web/app/router.js

+ 18 - 2
ambari-web/app/router.js

@@ -308,9 +308,25 @@ App.Router = Em.Router.extend({
         }
       }
       if (transitionToApp) {
-        if (!Em.isNone(router.get('preferedPath'))) {
-          window.location = router.get('preferedPath');
+        var preferredPath = router.get('preferedPath');
+        // If the preferred path is relative, allow a redirect to it.
+        // If the path is not relative, silently ignore it - if the path is an absolute URL, the user
+        // may be routed to a different server where the [possibility exists for a phishing attack.
+        if (!Em.isNone(preferredPath)) {
+          if (preferredPath.startsWith('/') || preferredPath.startsWith('#')) {
+            console.log("INFO: Routing to preferred path: " + preferredPath);
+          }
+          else {
+            console.log("WARNING: Ignoring preferred path since it is not a relative URL: " + preferredPath);
+            preferredPath = null;
+          }
+
+          // Unset preferedPath
           router.set('preferedPath', null);
+        }
+
+        if (!Em.isNone(preferredPath)) {
+          window.location = preferredPath;
         } else {
           router.getSection(function (route) {
             router.transitionTo(route);