|
1162 | 1162 | $scope.vm.loaded = false; |
1163 | 1163 | $scope.vm.error = void(0); |
1164 | 1164 |
|
1165 | | - return ramlParser.loadPath($window.resolveUrl(url), null, $scope.options) |
1166 | | - .then(function (raml) { |
1167 | | - $scope.vm.raml = raml; |
1168 | | - }) |
1169 | | - .catch(function (error) { |
1170 | | - $scope.vm.error = angular.extend(error, { |
1171 | | - /*jshint camelcase: false */ |
1172 | | - buffer: (error.context_mark || error.problem_mark).buffer |
1173 | | - /*jshint camelcase: true */ |
1174 | | - }); |
1175 | | - }) |
1176 | | - .finally(function () { |
1177 | | - $scope.vm.loaded = true; |
1178 | | - }) |
1179 | | - ; |
| 1165 | + if(RAML.LoaderUtils.ramlOriginValidate(url, $scope.options)) { |
| 1166 | + $scope.vm.error = {buffer : 'RAML origin check failed. Raml does not reside underneath the path:' + RAML.LoaderUtils.allowedRamlOrigin($scope.options)}; |
| 1167 | + } else { |
| 1168 | + return ramlParser.loadPath($window.resolveUrl(url), null, $scope.options) |
| 1169 | + .then(function (raml) { |
| 1170 | + $scope.vm.raml = raml; |
| 1171 | + }) |
| 1172 | + .catch(function (error) { |
| 1173 | + $scope.vm.error = angular.extend(error, { |
| 1174 | + /*jshint camelcase: false */ |
| 1175 | + buffer: (error.context_mark || error.problem_mark).buffer |
| 1176 | + /*jshint camelcase: true */ |
| 1177 | + }); |
| 1178 | + }) |
| 1179 | + .finally(function () { |
| 1180 | + $scope.vm.loaded = true; |
| 1181 | + }) |
| 1182 | + ; |
| 1183 | + } |
1180 | 1184 | } |
1181 | 1185 | }) |
1182 | 1186 | ; |
|
1596 | 1600 | restrict: 'E', |
1597 | 1601 | templateUrl: 'directives/raml-initializer.tpl.html', |
1598 | 1602 | replace: true, |
1599 | | - controller: 'RamlInitializerController' |
| 1603 | + controller: 'RamlInitializerController', |
| 1604 | + scope: { |
| 1605 | + options: '=' |
| 1606 | + } |
1600 | 1607 | }; |
1601 | 1608 | }) |
1602 | 1609 | .controller('RamlInitializerController', ['$scope', '$window', 'ramlParser', function RamlInitializerController( |
|
1633 | 1640 |
|
1634 | 1641 | function loadFromUrl(url) { |
1635 | 1642 | $scope.vm.ramlUrl = url; |
1636 | | - return loadFromPromise(ramlParser.loadPath($window.resolveUrl(url)), {isLoadingFromUrl: true}); |
| 1643 | + |
| 1644 | + if(RAML.LoaderUtils.ramlOriginValidate(url, $scope.options)) { |
| 1645 | + $scope.vm.isLoadedFromUrl = true; |
| 1646 | + $scope.vm.error = {message : 'RAML origin check failed. Raml does not reside underneath the path:' + RAML.LoaderUtils.allowedRamlOrigin($scope.options)}; |
| 1647 | + } else { |
| 1648 | + return loadFromPromise(ramlParser.loadPath($window.resolveUrl(url)), {isLoadingFromUrl: true}); |
| 1649 | + } |
1637 | 1650 | } |
1638 | 1651 |
|
1639 | 1652 | function loadFromString(string) { |
|
1775 | 1788 | }; |
1776 | 1789 |
|
1777 | 1790 | $scope.getDocumentationContent = function (content, selected) { |
1778 | | - var lines = content.split('\n'); |
| 1791 | + var lines = content.split(/\r|\n/); |
1779 | 1792 | var index = lines.indexOf(selected); |
1780 | 1793 | var result = []; |
1781 | 1794 | var regex = /(^#|^##)+\s(.*)$/gim; |
@@ -4517,6 +4530,41 @@ RAML.Inspector = (function() { |
4517 | 4530 | }); |
4518 | 4531 | })(); |
4519 | 4532 |
|
| 4533 | +(function() { |
| 4534 | + 'use strict'; |
| 4535 | + |
| 4536 | + RAML.LoaderUtils = { |
| 4537 | + |
| 4538 | + allowedRamlOrigin : function(options) { |
| 4539 | + var basepath='../'; |
| 4540 | + if(typeof options.ramlOriginCheck === 'string') { |
| 4541 | + basepath = options.ramlOriginCheck; |
| 4542 | + } |
| 4543 | + return basepath; |
| 4544 | + }, |
| 4545 | + |
| 4546 | + // prevent loading stuff from other hosts and/or services |
| 4547 | + ramlOriginValidate: function (url, options) { |
| 4548 | + var absolutePath = function(href) { |
| 4549 | + var link = document.createElement('a'); |
| 4550 | + link.href = href; |
| 4551 | + return link.href; |
| 4552 | + }; |
| 4553 | + |
| 4554 | + var isSameBasePath = function(href, basepath) { |
| 4555 | + var absoluteBasepath=absolutePath(basepath); |
| 4556 | + var absoluteRamlPath=absolutePath(href); |
| 4557 | + return absoluteRamlPath.indexOf(absoluteBasepath, 0) === 0; |
| 4558 | + }; |
| 4559 | + |
| 4560 | + var decodedRamlUrl=decodeURIComponent(url); |
| 4561 | + return options && options.ramlOriginCheck && !isSameBasePath(decodedRamlUrl, RAML.LoaderUtils.allowedRamlOrigin(options)); |
| 4562 | + } |
| 4563 | + |
| 4564 | + |
| 4565 | + }; |
| 4566 | +})(); |
| 4567 | + |
4520 | 4568 | (function() { |
4521 | 4569 | 'use strict'; |
4522 | 4570 |
|
|
0 commit comments