Author Topic: Make it impossible to manipulate an eval command?  (Read 2738 times)

This code copies all necessary variables from a brick over to a script object, based on the client's current inventory num.

Problem is, someone with just the right knowledge has the ability to manipulate the eval command via event lines.

I want to handle fonts and color codes, but eliminate any possibility that the player may use characters such as @ crash(); @

Quote
   function Salv_CopyBrick(%so, %brick, %Inv)
   {
      if(%brick.getName() !$= "") %so.brickName[%Inv] = %brick.getName();
      //%so.angleID[%Inv] = %brick.angleID;
      //%so.client[%Inv] = %brick.client;
      %so.colorFxID[%Inv] = %brick.colorFxID;
      %so.colorID[%Inv] = %brick.colorID;
      %so.dataBlock[%Inv] = %brick.dataBlock;
      %so.isBasePlate[%Inv] = %brick.isBasePlate;
      %so.isPlanted[%Inv] = %brick.isPlanted;
      //%so.position[%Inv] = %brick.position;
      %so.printID[%Inv] = %brick.printID;
      //%so.rotation[%Inv] = %brick.rotation;
      //%so.scale[%Inv] = %brick.scale;
      %so.shapeFxID[%Inv] = %brick.shapeFxID;
      //%so.stackBL_ID[%Inv] = %brick.stackBL_ID;

      //Tagged Fields
      for(%i=0;%i<getTagCount(%brick);%i++)
      {
         %Str = %brick.getTaggedField(%i);

         %Tag = getWord(%Str, 0);
         %Val = getSubStr( %Str, strLen(getWord(%Str,0))+1, 999999 );

         if(%Tag $= "emitter") %so.emitterData[%Inv] = %brick.emitter.emitter;
      else
         if(%Tag $= "light") %so.lightData[%Inv] = %brick.light.dataBlock;
      else
         if(%Tag $= "item") %so.itemData[%Inv] = %brick.item.dataBlock;
      else
         if(%Tag $= "audioEmitter") %so.musicData[%Inv] = %brick.audioEmitter.profile;
      else
         eval(%so @ "." @ %Tag @ %Inv @ " = \"" @ %Val @"\";");
      }
   }

replace \\ with \\\\
replace \" with \\\"

replace \\ with \\\\
replace \" with \\\"
Are those the ONLY characters I have to watch out for?

This was also suggested over steam to me;

Quote
Oh. May just want to cut your losses and just do stripchars(%str, ";");
« Last Edit: November 17, 2013, 03:50:41 AM by Conservative »

If you can figure out a way to use call() you're home free
call("talk","hello world");
Don't do call("eval", ...); as that's no better than what you've got.

Otherwise, just remove any ; ( ) @ $ or % you don't want before calling eval()
Are those the ONLY characters I have to watch out for?

This was also suggested over steam to me;

god no.

Remove literally every character that ISNT ABSOLUTELY NECCESSary

Seriously just whitelist the stuff (for each character in string, if it isn't one of these, return false and ABORT or just remove it)
« Last Edit: November 17, 2013, 03:52:35 AM by Lugnut »



Wait, that works on normal objects??
Yep.

new ScriptObject(one) { valid = true; };
new ScriptObject(two : one);
if(!two.valid) crash();

Are those the ONLY characters I have to watch out for?
Yes, as you start the value with a " and end it with a ". That means, the only way to inject some stuff is to add another ", right? So you need to prevent that.

yesyesyes scriptobject not simobject

siba use scriptobjects

Yes, as you start the value with a " and end it with a ". That means, the only way to inject some stuff is to add another ", right? So you need to prevent that.
No. If I send \" the prefixed \ will cancel the added \, keeping the " active.
« Last Edit: November 17, 2013, 02:15:54 PM by $trinick »

No. If I send \" the prefixed \ will cancel the added \, keeping the " active.

strReplace(strReplace(%text, "\"", "\\\""), "\\", "\\\\");

strReplace(strReplace(%text, "\"", "\\\""), "\\", "\\\\");
Do it the other way around

Like that, you get \" -> \\\" -> \\\\\" and \\\" -> \\\\\" -> \\\\\\\\\"

The other way around, you get \" -> \\\" and \\\" -> \\\\\" -> \\\\\\\"

replace \\ with \\\\
replace \" with \\\"

It's easier to just do expandEscape(%text);

It's easier to just do expandEscape(%text);
What would that do?

EDIT: I'm trying to create the ScriptObject now but I can't find a way to do it through code on %brick..

%so = new ScriptObject("Salvage_" @ %client.bl_id : %brick); returns a syntax error.
« Last Edit: November 17, 2013, 03:29:07 PM by Conservative »

Just to clarify the above, he's trying to copy the variables %brick has onto the ScriptObject.