Skip to content

Commit 0b30a17

Browse files
Pass copies of data to untrusted code instead of references (#125)
1 parent 0de9caa commit 0b30a17

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

src/loaders/nestjs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export async function setupNestJs(
3535
app.use(cookieParser());
3636

3737
BuiltInLogger.log(
38-
`Kafka: ${process.env.KAFKA_HOSTNAME || "host.docker.internal"}:${
38+
`Kafka: ${process.env.KAFKA_HOSTNAME || "localhost"}:${
3939
process.env.KAFKA_PORT || "9092"
4040
}`
4141
);

src/services/chirpstack/generic-chirpstack-configuration.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { JwtToken } from "./jwt-token";
1919
@Injectable()
2020
export class GenericChirpstackConfigurationService {
2121
baseUrl = `http://${
22-
process.env.CHIRPSTACK_APPLICATION_SERVER_HOSTNAME || "host.docker.internal"
22+
process.env.CHIRPSTACK_APPLICATION_SERVER_HOSTNAME || "localhost"
2323
}:${process.env.CHIRPSTACK_APPLICATION_SERVER_PORT || "8080"}`;
2424

2525
networkServer = `${

src/services/data-management/payload-decoder-executor.service.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,16 @@ export class PayloadDecoderExecutorService {
2424
rawPayload: JSON
2525
): string {
2626
const vm2Logger = new Logger(`${PayloadDecoderExecutorService.name}-VM2`);
27+
28+
// Make copies of inputs to untrusted code to avoid unintended side effects if the code chooses to modify these
29+
const iotDeviceCopy = JSON.parse(JSON.stringify(iotDevice));
30+
const payloadCopy = JSON.parse(JSON.stringify(rawPayload));
31+
2732
const vm = new VM({
2833
timeout: 5000,
2934
sandbox: {
30-
innerIotDevice: iotDevice,
31-
innerPayload: rawPayload,
35+
innerIotDevice: iotDeviceCopy,
36+
innerPayload: payloadCopy,
3237
log(data: any): void {
3338
vm2Logger.debug(data);
3439
},

src/services/kafka/kafka.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class KafkaService implements OnModuleInit, OnModuleDestroy {
3030
const kafkaConfig = {
3131
clientId: process.env.KAFKA_CLIENTID || "os2iot-client",
3232
brokers: [
33-
`${process.env.KAFKA_HOSTNAME || "host.docker.internal"}:${
33+
`${process.env.KAFKA_HOSTNAME || "localhost"}:${
3434
process.env.KAFKA_PORT || "9093"
3535
}`,
3636
],

0 commit comments

Comments
 (0)