WebGL——安全(翻译)

https://www.khronos.org/registry/webgl/specs/1.0/#4 原文

4 Security



4.1 Resource Restrictions

WebGL resources such as textures and vertex buffer objects (VBOs) must always contain initialized data, even if they were created without initial user data values. Creating a resource without initial values is commonly used to reserve space for a texture or VBO, which is then modified using texSubImage or bufferSubData calls. If initial data is not provided to these calls, the WebGL implementation must initialize their contents to 0; depth renderbuffers must be cleared to the default 1.0 clear depth. For example, this may require creating a temporary buffer of 0 values the size of a requested VBO, so that it can be initialized correctly. All other forms of loading data into a texture or VBO involve either ArrayBuffers or DOM objects such as images, and are therefore already required to be initialized.
  
   WebGL资源如纹理和顶点缓冲区对象都必须有初始数据,即使在没有初始用户数据值时创建资源。没有初始值的创建资源通常为纹理或VBO用于预留空间一个纹理或VBO,然后调用texSubImage或bufferSubData方法来修改。如果出世数据没有提供给这些调用,WebGL的实现必须初始化其内容为0,深度渲染缓冲区必须清除深度值到默认值1.0,例如,请求一个VBO大小需要创建一个0值的临时缓冲区,以便VBO正确的初始化,给纹理或VBO以其他方式加载数据都需要初始化,这些数据涉及到ArrayBuffers或DOM对象,例如,图片。

   When WebGL resources are accessed by shaders through a call such as drawElements or drawArrays, the WebGL implementation must ensure that the shader cannot access either out of bounds or uninitialized data. See Enabled Vertex Attributes and Range Checking for restrictions which must be enforced by the WebGL implementation.
 
   当通过调用着色器例如drawElements或drawArrays方法来访问WebGL资源,WebGL的实现要确保着色器不能访问越界或者未初始化的数据。顶点属性可用设置和限制范围检查都需要强制实现WebGL。

4.2 Origin Restrictions

In order to prevent information leakage, the HTML5 canvas element has a origin-clean flag. (See HTML5, section 4.8.11.3, "Security with canvas elements".) For a WebGL context, the origin-clean flag must be set to false if any of the following actions occur:
•The texImage2D method is called with an HTMLImageElement or HTMLVideoElement whose origin is not the same as that of the Document object that owns the canvas element.
•The texImage2D method is called with an HTMLCanvasElement whose origin-clean flag is set to false.

Whenever the readPixels method of the 2D context of a canvas element whose origin-clean flag is set to false is called with otherwise correct arguments, the method must raise a SECURITY_ERR exception.

4.3 Supported GLSL Constructs

A WebGL implementation must only accept shaders which conform to The OpenGL ES Shading Language, Version 1.00 [GLES20GLSL], and which do not exceed the minimum functionality mandated in Sections 4 and 5 of Appendix A. In particular, a shader referencing state variables or functions that are available in other versions of GLSL (such as that found in versions of OpenGL for the desktop), must not be allowed to load.

In addition to the reserved identifiers in the aforementioned specification, identifiers starting with "webgl_" and "_webgl_" are reserved for use by WebGL. A shader which declares a function, variable, structure name, or structure field starting with these prefixes must not be allowed to load.

你可能感兴趣的:(WebGL)