Skip to content

Commit 1619d16

Browse files
committed
Don't allow reading video motion when external communication is possible (#331)
1 parent 6222be2 commit 1619d16

3 files changed

Lines changed: 30 additions & 2 deletions

File tree

src/engine/runtime.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,12 @@ class Runtime extends EventEmitter {
508508
*/
509509
this.enforcePrivacy = true;
510510

511+
/**
512+
* If true, an external communication method exists and enforcePrivacy is enabled.
513+
* Do not update this directly. Must be changed via public functions that call Runtime.updatePrivacy().
514+
*/
515+
this.privacyRestrictionsActive = false;
516+
511517
/**
512518
* Internal map of opaque identifiers to the callback to run that function.
513519
* @type {Map<string, function>}
@@ -3427,12 +3433,12 @@ class Runtime extends EventEmitter {
34273433
}
34283434

34293435
updatePrivacy () {
3430-
const enforceRestrictions = (
3436+
this.privacyRestrictionsActive = (
34313437
this.enforcePrivacy &&
34323438
Object.values(this.externalCommunicationMethods).some(i => i)
34333439
);
34343440
if (this.renderer && this.renderer.setPrivateSkinAccess) {
3435-
this.renderer.setPrivateSkinAccess(!enforceRestrictions);
3441+
this.renderer.setPrivateSkinAccess(!this.privacyRestrictionsActive);
34363442
}
34373443
}
34383444

src/extensions/scratch3_video_sensing/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,10 @@ class Scratch3VideoSensingBlocks {
531531
* @returns {number} the motion amount or direction of the stage or sprite
532532
*/
533533
videoOn (args, util) {
534+
if (this.runtime.privacyRestrictionsActive) {
535+
return -1;
536+
}
537+
534538
this.detect.analyzeFrame();
535539

536540
let state = this.detect;
@@ -554,6 +558,10 @@ class Scratch3VideoSensingBlocks {
554558
* reference
555559
*/
556560
whenMotionGreaterThan (args, util) {
561+
if (this.runtime.privacyRestrictionsActive) {
562+
return false;
563+
}
564+
557565
this.detect.analyzeFrame();
558566
const state = this._analyzeLocalMotion(util.target);
559567
return state.motionAmount > Number(args.REFERENCE);

test/integration/tw_privacy.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,17 @@ test('custom extensions', async t => {
114114
t.equal(vm.renderer.privateSkinAccess, false);
115115
t.end();
116116
});
117+
118+
test('hasExternalCommunicationMethod', t => {
119+
const vm = new VM();
120+
t.equal(vm.runtime.privacyRestrictionsActive, false);
121+
vm.runtime.setExternalCommunicationMethod('cloudVariables', true);
122+
t.equal(vm.runtime.privacyRestrictionsActive, true);
123+
vm.runtime.setExternalCommunicationMethod('customExtensions', true);
124+
t.equal(vm.runtime.privacyRestrictionsActive, true);
125+
vm.runtime.setExternalCommunicationMethod('cloudVariables', false);
126+
t.equal(vm.runtime.privacyRestrictionsActive, true);
127+
vm.runtime.setExternalCommunicationMethod('customExtensions', false);
128+
t.equal(vm.runtime.privacyRestrictionsActive, false);
129+
t.end();
130+
});

0 commit comments

Comments
 (0)