Beginnings of JavaScript security bits.
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#include "nsJSUtils.h"
|
||||
#include "nscore.h"
|
||||
#include "nsIScriptContext.h"
|
||||
#include "nsIScriptSecurityManager.h"
|
||||
#include "nsIJSScriptObject.h"
|
||||
#include "nsIScriptObjectOwner.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
@@ -75,9 +76,20 @@ GetHTMLFormElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
}
|
||||
|
||||
if (JSVAL_IS_INT(id)) {
|
||||
nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx);
|
||||
nsIScriptSecurityManager *secMan;
|
||||
PRBool ok;
|
||||
if (NS_OK != scriptCX->GetSecurityManager(&secMan)) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
switch(JSVAL_TO_INT(id)) {
|
||||
case HTMLFORMELEMENT_ELEMENTS:
|
||||
{
|
||||
secMan->CheckScriptAccess(scriptCX, obj, "htmlformelement.elements", &ok);
|
||||
if (!ok) {
|
||||
//Need to throw error here
|
||||
return JS_FALSE;
|
||||
}
|
||||
nsIDOMHTMLCollection* prop;
|
||||
if (NS_OK == a->GetElements(&prop)) {
|
||||
// get the js object
|
||||
@@ -90,6 +102,11 @@ GetHTMLFormElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
}
|
||||
case HTMLFORMELEMENT_LENGTH:
|
||||
{
|
||||
secMan->CheckScriptAccess(scriptCX, obj, "htmlformelement.length", &ok);
|
||||
if (!ok) {
|
||||
//Need to throw error here
|
||||
return JS_FALSE;
|
||||
}
|
||||
PRUint32 prop;
|
||||
if (NS_OK == a->GetLength(&prop)) {
|
||||
*vp = INT_TO_JSVAL(prop);
|
||||
@@ -101,6 +118,11 @@ GetHTMLFormElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
}
|
||||
case HTMLFORMELEMENT_NAME:
|
||||
{
|
||||
secMan->CheckScriptAccess(scriptCX, obj, "htmlformelement.name", &ok);
|
||||
if (!ok) {
|
||||
//Need to throw error here
|
||||
return JS_FALSE;
|
||||
}
|
||||
nsAutoString prop;
|
||||
if (NS_OK == a->GetName(prop)) {
|
||||
nsJSUtils::nsConvertStringToJSVal(prop, cx, vp);
|
||||
@@ -112,6 +134,11 @@ GetHTMLFormElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
}
|
||||
case HTMLFORMELEMENT_ACCEPTCHARSET:
|
||||
{
|
||||
secMan->CheckScriptAccess(scriptCX, obj, "htmlformelement.acceptcharset", &ok);
|
||||
if (!ok) {
|
||||
//Need to throw error here
|
||||
return JS_FALSE;
|
||||
}
|
||||
nsAutoString prop;
|
||||
if (NS_OK == a->GetAcceptCharset(prop)) {
|
||||
nsJSUtils::nsConvertStringToJSVal(prop, cx, vp);
|
||||
@@ -123,6 +150,11 @@ GetHTMLFormElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
}
|
||||
case HTMLFORMELEMENT_ACTION:
|
||||
{
|
||||
secMan->CheckScriptAccess(scriptCX, obj, "htmlformelement.action", &ok);
|
||||
if (!ok) {
|
||||
//Need to throw error here
|
||||
return JS_FALSE;
|
||||
}
|
||||
nsAutoString prop;
|
||||
if (NS_OK == a->GetAction(prop)) {
|
||||
nsJSUtils::nsConvertStringToJSVal(prop, cx, vp);
|
||||
@@ -134,6 +166,11 @@ GetHTMLFormElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
}
|
||||
case HTMLFORMELEMENT_ENCTYPE:
|
||||
{
|
||||
secMan->CheckScriptAccess(scriptCX, obj, "htmlformelement.enctype", &ok);
|
||||
if (!ok) {
|
||||
//Need to throw error here
|
||||
return JS_FALSE;
|
||||
}
|
||||
nsAutoString prop;
|
||||
if (NS_OK == a->GetEnctype(prop)) {
|
||||
nsJSUtils::nsConvertStringToJSVal(prop, cx, vp);
|
||||
@@ -145,6 +182,11 @@ GetHTMLFormElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
}
|
||||
case HTMLFORMELEMENT_METHOD:
|
||||
{
|
||||
secMan->CheckScriptAccess(scriptCX, obj, "htmlformelement.method", &ok);
|
||||
if (!ok) {
|
||||
//Need to throw error here
|
||||
return JS_FALSE;
|
||||
}
|
||||
nsAutoString prop;
|
||||
if (NS_OK == a->GetMethod(prop)) {
|
||||
nsJSUtils::nsConvertStringToJSVal(prop, cx, vp);
|
||||
@@ -156,6 +198,11 @@ GetHTMLFormElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
}
|
||||
case HTMLFORMELEMENT_TARGET:
|
||||
{
|
||||
secMan->CheckScriptAccess(scriptCX, obj, "htmlformelement.target", &ok);
|
||||
if (!ok) {
|
||||
//Need to throw error here
|
||||
return JS_FALSE;
|
||||
}
|
||||
nsAutoString prop;
|
||||
if (NS_OK == a->GetTarget(prop)) {
|
||||
nsJSUtils::nsConvertStringToJSVal(prop, cx, vp);
|
||||
@@ -167,6 +214,11 @@ GetHTMLFormElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
}
|
||||
case NSHTMLFORMELEMENT_ENCODING:
|
||||
{
|
||||
secMan->CheckScriptAccess(scriptCX, obj, "nshtmlformelement.encoding", &ok);
|
||||
if (!ok) {
|
||||
//Need to throw error here
|
||||
return JS_FALSE;
|
||||
}
|
||||
nsAutoString prop;
|
||||
nsIDOMNSHTMLFormElement* b;
|
||||
if (NS_OK == a->QueryInterface(kINSHTMLFormElementIID, (void **)&b)) {
|
||||
@@ -188,6 +240,7 @@ GetHTMLFormElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
default:
|
||||
return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp);
|
||||
}
|
||||
NS_RELEASE(secMan);
|
||||
}
|
||||
else if (JSVAL_IS_STRING(id)) {
|
||||
nsIDOMElement* prop;
|
||||
@@ -245,9 +298,20 @@ SetHTMLFormElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
}
|
||||
|
||||
if (JSVAL_IS_INT(id)) {
|
||||
nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx);
|
||||
nsIScriptSecurityManager *secMan;
|
||||
PRBool ok;
|
||||
if (NS_OK != scriptCX->GetSecurityManager(&secMan)) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
switch(JSVAL_TO_INT(id)) {
|
||||
case HTMLFORMELEMENT_NAME:
|
||||
{
|
||||
secMan->CheckScriptAccess(scriptCX, obj, "htmlformelement.name", &ok);
|
||||
if (!ok) {
|
||||
//Need to throw error here
|
||||
return JS_FALSE;
|
||||
}
|
||||
nsAutoString prop;
|
||||
nsJSUtils::nsConvertJSValToString(prop, cx, *vp);
|
||||
|
||||
@@ -257,6 +321,11 @@ SetHTMLFormElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
}
|
||||
case HTMLFORMELEMENT_ACCEPTCHARSET:
|
||||
{
|
||||
secMan->CheckScriptAccess(scriptCX, obj, "htmlformelement.acceptcharset", &ok);
|
||||
if (!ok) {
|
||||
//Need to throw error here
|
||||
return JS_FALSE;
|
||||
}
|
||||
nsAutoString prop;
|
||||
nsJSUtils::nsConvertJSValToString(prop, cx, *vp);
|
||||
|
||||
@@ -266,6 +335,11 @@ SetHTMLFormElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
}
|
||||
case HTMLFORMELEMENT_ACTION:
|
||||
{
|
||||
secMan->CheckScriptAccess(scriptCX, obj, "htmlformelement.action", &ok);
|
||||
if (!ok) {
|
||||
//Need to throw error here
|
||||
return JS_FALSE;
|
||||
}
|
||||
nsAutoString prop;
|
||||
nsJSUtils::nsConvertJSValToString(prop, cx, *vp);
|
||||
|
||||
@@ -275,6 +349,11 @@ SetHTMLFormElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
}
|
||||
case HTMLFORMELEMENT_ENCTYPE:
|
||||
{
|
||||
secMan->CheckScriptAccess(scriptCX, obj, "htmlformelement.enctype", &ok);
|
||||
if (!ok) {
|
||||
//Need to throw error here
|
||||
return JS_FALSE;
|
||||
}
|
||||
nsAutoString prop;
|
||||
nsJSUtils::nsConvertJSValToString(prop, cx, *vp);
|
||||
|
||||
@@ -284,6 +363,11 @@ SetHTMLFormElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
}
|
||||
case HTMLFORMELEMENT_METHOD:
|
||||
{
|
||||
secMan->CheckScriptAccess(scriptCX, obj, "htmlformelement.method", &ok);
|
||||
if (!ok) {
|
||||
//Need to throw error here
|
||||
return JS_FALSE;
|
||||
}
|
||||
nsAutoString prop;
|
||||
nsJSUtils::nsConvertJSValToString(prop, cx, *vp);
|
||||
|
||||
@@ -293,6 +377,11 @@ SetHTMLFormElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
}
|
||||
case HTMLFORMELEMENT_TARGET:
|
||||
{
|
||||
secMan->CheckScriptAccess(scriptCX, obj, "htmlformelement.target", &ok);
|
||||
if (!ok) {
|
||||
//Need to throw error here
|
||||
return JS_FALSE;
|
||||
}
|
||||
nsAutoString prop;
|
||||
nsJSUtils::nsConvertJSValToString(prop, cx, *vp);
|
||||
|
||||
@@ -303,6 +392,7 @@ SetHTMLFormElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
default:
|
||||
return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp);
|
||||
}
|
||||
NS_RELEASE(secMan);
|
||||
}
|
||||
else {
|
||||
return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp);
|
||||
@@ -353,6 +443,21 @@ HTMLFormElementSubmit(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsv
|
||||
|
||||
*rval = JSVAL_NULL;
|
||||
|
||||
nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx);
|
||||
nsIScriptSecurityManager *secMan;
|
||||
if (NS_OK == scriptCX->GetSecurityManager(&secMan)) {
|
||||
PRBool ok;
|
||||
secMan->CheckScriptAccess(scriptCX, obj, "htmlformelement.submit", &ok);
|
||||
if (!ok) {
|
||||
//Need to throw error here
|
||||
return JS_FALSE;
|
||||
}
|
||||
NS_RELEASE(secMan);
|
||||
}
|
||||
else {
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
// If there's no private data, this must be the prototype, so ignore
|
||||
if (nsnull == nativeThis) {
|
||||
return JS_TRUE;
|
||||
@@ -386,6 +491,21 @@ HTMLFormElementReset(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsva
|
||||
|
||||
*rval = JSVAL_NULL;
|
||||
|
||||
nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx);
|
||||
nsIScriptSecurityManager *secMan;
|
||||
if (NS_OK == scriptCX->GetSecurityManager(&secMan)) {
|
||||
PRBool ok;
|
||||
secMan->CheckScriptAccess(scriptCX, obj, "htmlformelement.reset", &ok);
|
||||
if (!ok) {
|
||||
//Need to throw error here
|
||||
return JS_FALSE;
|
||||
}
|
||||
NS_RELEASE(secMan);
|
||||
}
|
||||
else {
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
// If there's no private data, this must be the prototype, so ignore
|
||||
if (nsnull == nativeThis) {
|
||||
return JS_TRUE;
|
||||
@@ -427,6 +547,21 @@ NSHTMLFormElementNamedItem(JSContext *cx, JSObject *obj, uintN argc, jsval *argv
|
||||
|
||||
*rval = JSVAL_NULL;
|
||||
|
||||
nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx);
|
||||
nsIScriptSecurityManager *secMan;
|
||||
if (NS_OK == scriptCX->GetSecurityManager(&secMan)) {
|
||||
PRBool ok;
|
||||
secMan->CheckScriptAccess(scriptCX, obj, "nshtmlformelement.nameditem", &ok);
|
||||
if (!ok) {
|
||||
//Need to throw error here
|
||||
return JS_FALSE;
|
||||
}
|
||||
NS_RELEASE(secMan);
|
||||
}
|
||||
else {
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
// If there's no private data, this must be the prototype, so ignore
|
||||
if (nsnull == nativeThis) {
|
||||
return JS_TRUE;
|
||||
|
||||
Reference in New Issue
Block a user