@@ -169,7 +169,7 @@ export interface Client {
169169 activeDocumentChanged ( document : vscode . TextDocument ) : void ;
170170 activate ( ) : void ;
171171 selectionChanged ( selection : vscode . Position ) : void ;
172- sendCustomConfigurations ( configs : SourceFileConfigurationItem [ ] ) : void ;
172+ sendCustomConfigurations ( configs : any ) : void ;
173173 resetDatabase ( ) : void ;
174174 deactivate ( ) : void ;
175175 pauseParsing ( ) : void ;
@@ -997,9 +997,27 @@ class DefaultClient implements Client {
997997 this . notifyWhenReady ( ( ) => this . languageClient . sendNotification ( ChangeCompileCommandsNotification , params ) ) ;
998998 }
999999
1000- public sendCustomConfigurations ( configs : SourceFileConfigurationItem [ ] ) : void {
1000+ public sendCustomConfigurations ( configs : any ) : void {
1001+ // configs is marked as 'any' because it is untrusted data coming from a 3rd-party. We need to sanitize it before sending it to the language server.
1002+ if ( ! configs || ! ( configs instanceof Array ) ) {
1003+ return ;
1004+ }
1005+ let sanitized : SourceFileConfigurationItem [ ] = < SourceFileConfigurationItem [ ] > configs ;
1006+ sanitized = sanitized . filter ( item => {
1007+ if ( item && item . uri && item . configuration &&
1008+ item . configuration . includePath && item . configuration . defines && item . configuration . intelliSenseMode && item . configuration . standard ) {
1009+ return true ;
1010+ }
1011+ console . warn ( "discarding invalid SourceFileConfigurationItem: " + item ) ;
1012+ return false ;
1013+ } ) ;
1014+
1015+ if ( sanitized . length === 0 ) {
1016+ return ;
1017+ }
1018+
10011019 let params : CustomConfigurationParams = {
1002- configurationItems : configs
1020+ configurationItems : sanitized
10031021 } ;
10041022 this . notifyWhenReady ( ( ) => this . languageClient . sendNotification ( CustomConfigurationNotification , params ) ) ;
10051023 }
@@ -1104,7 +1122,7 @@ class NullClient implements Client {
11041122 queueTaskWithTimeout ( task : ( ) => Thenable < any > , ms : number , tokenSource ?: CancellationTokenSource ) : Thenable < any > { return task ( ) ; }
11051123 requestWhenReady ( request : ( ) => Thenable < any > ) : Thenable < any > { return ; }
11061124 notifyWhenReady ( notify : ( ) => void ) : void { }
1107- sendCustomConfigurations ( configs : SourceFileConfigurationItem [ ] ) : void { }
1125+ sendCustomConfigurations ( configs : any ) : void { }
11081126 requestGoToDeclaration ( ) : Thenable < void > { return Promise . resolve ( ) ; }
11091127 requestSwitchHeaderSource ( rootPath : string , fileName : string ) : Thenable < string > { return Promise . resolve ( "" ) ; }
11101128 requestNavigationList ( document : vscode . TextDocument ) : Thenable < string > { return Promise . resolve ( "" ) ; }
0 commit comments