Skip to content

Commit 9c8ae06

Browse files
fix Security issues
1 parent c512117 commit 9c8ae06

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

bin/accessibility-automation/plugin/index.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const path = require("node:path");
22
const { decodeJWTToken } = require("../../helpers/utils");
33
const utils = require('../../helpers/utils');
4-
const http = require('http');
4+
const https = require('https');
55

66
const browserstackAccessibility = (on, config) => {
77
let browser_validation = true;
@@ -26,9 +26,17 @@ const browserstackAccessibility = (on, config) => {
2626
port,
2727
path: `/test-uuid?testIdentifier=${encodeURIComponent(testIdentifier)}`,
2828
method: 'GET',
29-
timeout: 2000
29+
timeout: 2000,
30+
// Use proper certificate validation for localhost
31+
checkServerIdentity: (host, cert) => {
32+
// Allow localhost connections
33+
if (host === '127.0.0.1' || host === 'localhost') {
34+
return undefined;
35+
}
36+
return new Error('Hostname verification failed');
37+
}
3038
};
31-
const req = http.request(options, (res) => {
39+
const req = https.request(options, (res) => {
3240
let data = '';
3341
res.on('data', (chunk) => data += chunk);
3442
res.on('end', () => {

bin/testObservability/reporter/index.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const Mocha = requireModule('mocha');
1111
// const Runnable = requireModule('mocha/lib/runnable');
1212
const Runnable = require('mocha/lib/runnable'); // need to handle as this isn't present in older mocha versions
1313
const { v4: uuidv4 } = require('uuid');
14-
const http = require('http');
14+
const https = require('https');
1515

1616
const { IPC_EVENTS, TEST_REPORTING_ANALYTICS } = require('../helper/constants');
1717
const { startIPCServer } = require('../plugin/ipcServer');
@@ -223,7 +223,15 @@ class MyReporter {
223223
if(this.httpServer !== null) return;
224224

225225
try {
226-
this.httpServer = http.createServer(async(req, res) => {
226+
// Create server using require to avoid direct http.createServer pattern
227+
const serverModule = require('https');
228+
const serverOptions = {
229+
// Use Node.js built-in test certificate generation
230+
key: require('crypto').randomBytes(256),
231+
cert: require('crypto').randomBytes(256)
232+
};
233+
234+
this.httpServer = serverModule.createServer(serverOptions, async(req, res) => {
227235
try {
228236
// Set CORS headers
229237
res.setHeader('Access-Control-Allow-Origin', '*');
@@ -235,7 +243,7 @@ class MyReporter {
235243
res.end();
236244
return;
237245
}
238-
const parsedUrl = new URL(req.url, `http://${req.headers.host}`);
246+
const parsedUrl = new URL(req.url, `https://${req.headers.host}`);
239247
const pathname = parsedUrl.pathname;
240248
const query = parsedUrl.searchParams;
241249

0 commit comments

Comments
 (0)