Closed Bug 1824479 Opened 3 years ago Closed 2 years ago

WebIDL compiler should permit `[SecureContext]` on namespaces

Categories

(Core :: DOM: Bindings (WebIDL), enhancement)

enhancement

Tracking

()

RESOLVED FIXED
129 Branch
Tracking Status
firefox129 --- fixed

People

(Reporter: jimb, Assigned: edgar)

References

Details

Attachments

(4 files)

Mozilla's WebIDL compiler should be extended to implement marking WebIDL namespaces for exposure only in secure contexts. Right now that's an error.

The WebIDL for the WebGPU specification places the [SecureContext] extended attribute on namespaces, but Mozilla's WebIDL compiler doesn't implement this at the moment.

The WebGPU spec says things like:

[Exposed=(Window, DedicatedWorker), SecureContext]
namespace GPUShaderStage {
    const GPUFlagsConstant VERTEX   = 0x1;
    const GPUFlagsConstant FRAGMENT = 0x2;
    const GPUFlagsConstant COMPUTE  = 0x4;
};

but if we try to put this in dom/webidl/WebGPU.webidl, we get an error from the WebIDL compiler:

 0:02.97 Traceback (most recent call last):
 0:02.97   File "<frozen runpy>", line 198, in _run_module_as_main
 0:02.97   File "<frozen runpy>", line 88, in _run_code
 0:02.97   File "/home/jimb/moz/central/python/mozbuild/mozbuild/action/webidl.py", line 19, in <module>
 0:02.97     sys.exit(log_build_task(main, sys.argv[1:]))
 0:02.97              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 0:02.97   File "/home/jimb/moz/central/python/mozbuild/mozbuild/action/util.py", line 16, in log_build_task
 0:02.97     return f(*args, **kwargs)
 0:02.97            ^^^^^^^^^^^^^^^^^^
 0:02.97   File "/home/jimb/moz/central/python/mozbuild/mozbuild/action/webidl.py", line 15, in main
 0:02.97     manager.generate_build_files()
 0:02.97   File "/home/jimb/moz/central/dom/bindings/mozwebidlcodegen/__init__.py", line 288, in generate_build_files
 0:02.97     self._parse_webidl()
 0:02.97   File "/home/jimb/moz/central/dom/bindings/mozwebidlcodegen/__init__.py", line 384, in _parse_webidl
 0:02.97     parser.parse(data, path)
 0:02.97   File "/home/jimb/moz/central/dom/bindings/parser/WebIDL.py", line 8881, in parse
 0:02.97     self._productions.extend(self.parser.parse(lexer=self.lexer, tracking=True))
 0:02.97                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 0:02.97   File "/home/jimb/moz/central/third_party/python/ply/ply/yacc.py", line 329, in parse
 0:02.98     return self.parseopt(input, lexer, debug, tracking, tokenfunc)
 0:02.98            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 0:02.98   File "/home/jimb/moz/central/third_party/python/ply/ply/yacc.py", line 821, in parseopt
 0:02.98     p.callable(pslice)
 0:02.98   File "/home/jimb/moz/central/dom/bindings/parser/WebIDL.py", line 7059, in p_Definitions
 0:02.98     p[2].addExtendedAttributes(p[1])
 0:02.98   File "/home/jimb/moz/central/dom/bindings/parser/WebIDL.py", line 2099, in addExtendedAttributes
 0:02.98     raise WebIDLError(
 0:02.98 WebIDL.WebIDLError: error: Unknown extended attribute SecureContext on namespace, /home/jimb/moz/central/dom/webidl/WebGPU.webidl line 421:42
 0:02.98  Exposed=(Window /* ,DedicatedWorker */), SecureContext]
 0:02.98                                           ^
 0:03.19 gmake[4]: *** [Makefile:54: webidl.stub] Error 1
 0:03.19 gmake[3]: *** [/home/jimb/moz/central/config/recurse.mk:99: dom/bindings/export] Error 2

The WebIDL for the WebGPU specification places the [SecureContext] extended attribute on namespaces

... or rather, it will once gpuweb#4002 is merged.

Blocks: 1824504

Hi Jim, could you help to try if this WIP patch works for WebGPU, though I have not yet checking the generated code.

Flags: needinfo?(jimb)
Assignee: nobody → echen

Hi, so I just hit that problem.

Without this patch we need to annotate all individual functions with Secure context.
I tried to apply this patch and to annotate the namespace instead of each function, and this works as expected with my code.

I tested building and running the MLS dom tests locally and on try.
https://treeherder.mozilla.org/jobs?repo=try&revision=5ce2c9706c80892112aa6d85eda6deae8ff4736b

I can also confirm that the namespace was not available outside secure contexts by testing on http://example.com.

It would be very helpful if we can land this :)

Thanks for your help in testing and verifying. I am working on getting this landed.

Flags: needinfo?(jimb)
Attachment #9325122 - Attachment description: WIP: Bug 1824479 - Allow SecureContext on namespace; → Bug 1824479 - Allow SecureContext on namespace; r?peterv
Pushed by echen@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/09996ad35c95 Fix error message thrown in IDLPartialInterfaceOrNamespace; r=peterv https://hg.mozilla.org/integration/autoland/rev/a839f895afed Refactor extended attribute handling for IDLInterfaceOrInterfaceMixinOrNamespace; r=peterv https://hg.mozilla.org/integration/autoland/rev/70b2d1903a2c Move `Exposed` handling to IDLInterfaceOrInterfaceMixinOrNamespace; r=peterv https://hg.mozilla.org/integration/autoland/rev/5e8fc5c0a1d7 Allow SecureContext on namespace; r=peterv
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: