Skip to content

Commit 1fcd9f8

Browse files
committed
fix possible RCE in jsonpath-plus
1 parent f215e3d commit 1fcd9f8

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

src/azure_auth.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import * as proc from 'child_process';
22
import https = require('https');
3-
import * as jsonpath from 'jsonpath-plus';
43
import request = require('request');
54

65
import { Authenticator } from './auth';
76
import { User } from './config_types';
7+
import { jsonpath } from './json_path';
88

99
/* FIXME: maybe we can extend the User and User.authProvider type to have a proper type.
1010
Currently user.authProvider has `any` type and so we don't have a type for user.authProvider.config.
@@ -94,7 +94,7 @@ export class AzureAuth implements Authenticator {
9494
const tokenPathKey = '$' + tokenPathKeyInConfig.slice(1, -1);
9595
const expiryPathKey = '$' + expiryPathKeyInConfig.slice(1, -1);
9696

97-
config['access-token'] = jsonpath.JSONPath(tokenPathKey, resultObj);
98-
config.expiry = jsonpath.JSONPath(expiryPathKey, resultObj);
97+
config['access-token'] = jsonpath(tokenPathKey, resultObj);
98+
config.expiry = jsonpath(expiryPathKey, resultObj);
9999
}
100100
}

src/gcp_auth.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import * as proc from 'child_process';
22
import https = require('https');
3-
import * as jsonpath from 'jsonpath-plus';
43
import request = require('request');
54

65
import { Authenticator } from './auth';
76
import { User } from './config_types';
7+
import { jsonpath } from './json_path';
88

99
/* FIXME: maybe we can extend the User and User.authProvider type to have a proper type.
1010
Currently user.authProvider has `any` type and so we don't have a type for user.authProvider.config.
@@ -90,7 +90,7 @@ export class GoogleCloudPlatformAuth implements Authenticator {
9090
const tokenPathKey = '$' + tokenPathKeyInConfig.slice(1, -1);
9191
const expiryPathKey = '$' + expiryPathKeyInConfig.slice(1, -1);
9292

93-
config['access-token'] = jsonpath.JSONPath(tokenPathKey, resultObj);
94-
config.expiry = jsonpath.JSONPath(expiryPathKey, resultObj);
93+
config['access-token'] = jsonpath(tokenPathKey, resultObj);
94+
config.expiry = jsonpath(expiryPathKey, resultObj);
9595
}
9696
}

src/json_path.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import {JSONPath} from 'jsonpath-plus';
2+
3+
export function jsonpath(path: string, json: object): any {
4+
return JSONPath({
5+
path,
6+
json,
7+
8+
preventEval: true,
9+
});
10+
}

src/json_path_test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { expect } from 'chai';
2+
import { jsonpath } from './json_path';
3+
4+
describe('jsonpath', () => {
5+
it('should throw if vulnerable for RCE (remote code execution)', () => {
6+
expect(() => {
7+
jsonpath('$..[?(' + '(function a(arr){' + 'a([...arr, ...arr])' + '})([1]);)]', { nonEmpty: 'object' });
8+
}).to.throw();
9+
});
10+
});

0 commit comments

Comments
 (0)