File tree Expand file tree Collapse file tree 3 files changed +64
-17
lines changed
Expand file tree Collapse file tree 3 files changed +64
-17
lines changed Original file line number Diff line number Diff line change 4040 $scope . vm . loaded = false ;
4141 $scope . vm . error = void ( 0 ) ;
4242
43- return ramlParser . loadPath ( $window . resolveUrl ( url ) , null , $scope . options )
44- . then ( function ( raml ) {
45- $scope . vm . raml = raml ;
46- } )
47- . catch ( function ( error ) {
48- $scope . vm . error = angular . extend ( error , {
49- /*jshint camelcase: false */
50- buffer : ( error . context_mark || error . problem_mark ) . buffer
51- /*jshint camelcase: true */
52- } ) ;
53- } )
54- . finally ( function ( ) {
55- $scope . vm . loaded = true ;
56- } )
57- ;
43+ if ( RAML . LoaderUtils . ramlOriginValidate ( url , $scope . options ) ) {
44+ $scope . vm . error = { buffer : 'RAML origin check failed. Raml does not reside underneath the path:' + RAML . LoaderUtils . allowedRamlOrigin ( $scope . options ) } ;
45+ } else {
46+ return ramlParser . loadPath ( $window . resolveUrl ( url ) , null , $scope . options )
47+ . then ( function ( raml ) {
48+ $scope . vm . raml = raml ;
49+ } )
50+ . catch ( function ( error ) {
51+ $scope . vm . error = angular . extend ( error , {
52+ /*jshint camelcase: false */
53+ buffer : ( error . context_mark || error . problem_mark ) . buffer
54+ /*jshint camelcase: true */
55+ } ) ;
56+ } )
57+ . finally ( function ( ) {
58+ $scope . vm . loaded = true ;
59+ } )
60+ ;
61+ }
5862 }
5963 } )
6064 ;
Original file line number Diff line number Diff line change 77 restrict : 'E' ,
88 templateUrl : 'directives/raml-initializer.tpl.html' ,
99 replace : true ,
10- controller : 'RamlInitializerController'
10+ controller : 'RamlInitializerController' ,
11+ scope : {
12+ options : '='
13+ }
1114 } ;
1215 } )
1316 . controller ( 'RamlInitializerController' , function RamlInitializerController (
4649
4750 function loadFromUrl ( url ) {
4851 $scope . vm . ramlUrl = url ;
49- return loadFromPromise ( ramlParser . loadPath ( $window . resolveUrl ( url ) ) , { isLoadingFromUrl : true } ) ;
52+
53+ if ( RAML . LoaderUtils . ramlOriginValidate ( url , $scope . options ) ) {
54+ $scope . vm . isLoadedFromUrl = true ;
55+ $scope . vm . error = { message : 'RAML origin check failed. Raml does not reside underneath the path:' + RAML . LoaderUtils . allowedRamlOrigin ( $scope . options ) } ;
56+ } else {
57+ return loadFromPromise ( ramlParser . loadPath ( $window . resolveUrl ( url ) ) , { isLoadingFromUrl : true } ) ;
58+ }
5059 }
5160
5261 function loadFromString ( string ) {
Original file line number Diff line number Diff line change 1+ ( function ( ) {
2+ 'use strict' ;
3+
4+ RAML . LoaderUtils = {
5+
6+ allowedRamlOrigin : function ( options ) {
7+ var basepath = '../' ;
8+ if ( typeof options . ramlOriginCheck === 'string' ) {
9+ basepath = options . ramlOriginCheck ;
10+ }
11+ return basepath ;
12+ } ,
13+
14+ // prevent loading stuff from other hosts and/or services
15+ ramlOriginValidate : function ( url , options ) {
16+ var absolutePath = function ( href ) {
17+ var link = document . createElement ( 'a' ) ;
18+ link . href = href ;
19+ return link . href ;
20+ } ;
21+
22+ var isSameBasePath = function ( href , basepath ) {
23+ var absoluteBasepath = absolutePath ( basepath ) ;
24+ var absoluteRamlPath = absolutePath ( href ) ;
25+ return absoluteRamlPath . indexOf ( absoluteBasepath , 0 ) === 0 ;
26+ } ;
27+
28+ var decodedRamlUrl = decodeURIComponent ( url ) ;
29+ return options && options . ramlOriginCheck && ! isSameBasePath ( decodedRamlUrl , RAML . LoaderUtils . allowedRamlOrigin ( options ) ) ;
30+ }
31+
32+
33+ } ;
34+ } ) ( ) ;
You can’t perform that action at this time.
0 commit comments