Jump to content

How do you deal with the problem of plaintext?


huayan889

Recommended Posts

1. Can You try to replace ARequestInfo.UnparsedParams with ARequestInfo.Params.text or ARequestInfo.FormParams ?

2. Also You can try to encrypt ARequestInfo.Username and ARequestInfo.Password in TUniServerModule.UniGUIServerModuleHTTPCommand

I add this code:

          //replace data
          sAjaxValues.Values[fpCompName] := StringReplace (sAjaxValues.Values[fpCompName],fpValue,'123',[]);
          //NEW Replace In  ARequestInfo.Params
          ARequestInfo.Params.Values ['_fp_'] := '&' + sAjaxValues [sAjaxValues.IndexOfName(fpCompName)];
          sAjaxValues.Values ['_fp_'] := HTTPEncode ('&' + sAjaxValues [sAjaxValues.IndexOfName(fpCompName)]);
          sAjaxValues.Delete (sAjaxValues.IndexOfName (fpCompName));

          //Old code replace data in UnparsedParams 
          ARequestInfo.UnparsedParams := sAjaxValues.DelimitedText;
          //NEW Replace in ARequestInfo.FormParams
          ARequestInfo.FormParams := sAjaxValues.DelimitedText;

 

Link to comment
Share on other sites

Please try with other maner:

will use TUniMainModule.UniGUIMainModuleHandleRequest

procedure TUniMainModule.UniGUIMainModuleHandleRequest(ASession: TObject;  var Handled: Boolean);

var
  sUser,
  sPass,
  fpName,fpValue,
  fpCompName,
  s                 : String;
  I,J               : Integer;

  sAjaxValues,
  sRefererValues    : TStringList;
  REQ               : TIdHTTPRequestInfo; // uIdCustomHTTPServer
begin

Try

//replace  ARequestInfo  with TUniGUISession(ASession).ARequest

//If (sSessionID <> '')
If (POS ('_fp_',TUniGUISession(ASession).ARequest.UnparsedParams)> 0)
AND (UniServerModule.ProtectDataList.Count > 0)
then begin
sAjaxValues := TStringList.Create;
sAjaxValues.Delimiter := '&';
sAjaxValues.StrictDelimiter := True;
sAjaxValues.DelimitedText := uniGUIJSUtils.URIDecode(TUniGUISession(ASession).ARequest.UnparsedParams);
TRY
  if (sAjaxValues.IndexOfName ('_fp_') > 0)
  then begin
      for J := 0 to UniServerModule.ProtectDataList.Count - 1 do begin
        fpCompName := UniServerModule.ProtectDataList.ValueFromIndex [J];
        fpName := sAjaxValues.Values[fpCompName];
        fpValue := '';
        if fpName <> '' then begin
          for I := Length (fpName) downto 1 do begin
              case fpName [I] of
                   '%' : begin
                        delete (fpValue,1,2);
                        break;
                   end
                   else fpValue := fpName [I] + fpValue;
              end;
          end;//for I
          sAjaxValues.Values[fpCompName] := StringReplace (sAjaxValues.Values[fpCompName],fpValue,'123',[]);

          TUniGUISession(ASession).ARequest.Params.Values ['_fp_'] := '&' + sAjaxValues [sAjaxValues.IndexOfName(fpCompName)];
          sAjaxValues.Values ['_fp_'] := HTTPEncode ('&' + sAjaxValues [sAjaxValues.IndexOfName(fpCompName)]);
          sAjaxValues.Delete (sAjaxValues.IndexOfName (fpCompName));

          TUniGUISession(ASession).ARequest.UnparsedParams := sAjaxValues.DelimitedText;

          TUniGUISession(ASession).ARequest.FormParams := sAjaxValues.DelimitedText;
        end;//If
      end;//for J
  end;//If
  sAjaxValues.Clear;
  sAjaxValues.Free;

EXCEPT

END;
end;

 

I test this two functions in Google chrome console and make memory snapshot.

when I use UniGUIServerModuleHTTPCommand, then console show me test value like submittedvalue

when i use UniGUIMainModuleHandleRequest , then console show me test value like lastvalue

So there are some differenses , and maybe last one funcions will giv You the solution.

 

Link to comment
Share on other sites

1 hour ago, irigsoft said:

Please try with other maner:

will use TUniMainModule.UniGUIMainModuleHandleRequest

procedure TUniMainModule.UniGUIMainModuleHandleRequest(ASession: TObject;  var Handled: Boolean);

var
  sUser,
  sPass,
  fpName,fpValue,
  fpCompName,
  s                 : String;
  I,J               : Integer;

  sAjaxValues,
  sRefererValues    : TStringList;
  REQ               : TIdHTTPRequestInfo; // uIdCustomHTTPServer
begin

Try

//replace  ARequestInfo  with TUniGUISession(ASession).ARequest

//If (sSessionID <> '')
If (POS ('_fp_',TUniGUISession(ASession).ARequest.UnparsedParams)> 0)
AND (UniServerModule.ProtectDataList.Count > 0)
then begin
sAjaxValues := TStringList.Create;
sAjaxValues.Delimiter := '&';
sAjaxValues.StrictDelimiter := True;
sAjaxValues.DelimitedText := uniGUIJSUtils.URIDecode(TUniGUISession(ASession).ARequest.UnparsedParams);
TRY
  if (sAjaxValues.IndexOfName ('_fp_') > 0)
  then begin
      for J := 0 to UniServerModule.ProtectDataList.Count - 1 do begin
        fpCompName := UniServerModule.ProtectDataList.ValueFromIndex [J];
        fpName := sAjaxValues.Values[fpCompName];
        fpValue := '';
        if fpName <> '' then begin
          for I := Length (fpName) downto 1 do begin
              case fpName [I] of
                   '%' : begin
                        delete (fpValue,1,2);
                        break;
                   end
                   else fpValue := fpName [I] + fpValue;
              end;
          end;//for I
          sAjaxValues.Values[fpCompName] := StringReplace (sAjaxValues.Values[fpCompName],fpValue,'123',[]);

          TUniGUISession(ASession).ARequest.Params.Values ['_fp_'] := '&' + sAjaxValues [sAjaxValues.IndexOfName(fpCompName)];
          sAjaxValues.Values ['_fp_'] := HTTPEncode ('&' + sAjaxValues [sAjaxValues.IndexOfName(fpCompName)]);
          sAjaxValues.Delete (sAjaxValues.IndexOfName (fpCompName));

          TUniGUISession(ASession).ARequest.UnparsedParams := sAjaxValues.DelimitedText;

          TUniGUISession(ASession).ARequest.FormParams := sAjaxValues.DelimitedText;
        end;//If
      end;//for J
  end;//If
  sAjaxValues.Clear;
  sAjaxValues.Free;

EXCEPT

END;
end;

 

I test this two functions in Google chrome console and make memory snapshot.

when I use UniGUIServerModuleHTTPCommand, then console show me test value like submittedvalue

when i use UniGUIMainModuleHandleRequest , then console show me test value like lastvalue

So there are some differenses , and maybe last one funcions will giv You the solution.

 

run fpcompName=''

image.thumb.png.7f25a518cf06786614769a7a48619138.png

 

Link to comment
Share on other sites

5 hours ago, huayan889 said:

irigsoft:Can you give me a complete test demo?

this is all :

All procedure move from TUniServerModule.UniGUIServerModuleHTTPCommand to TUniMainModule.UniGUIMainModuleHandleRequest

uses    uniGUIJSUtils
  , HTTPApp;

 

 

procedure TUniMainModule.UniGUIMainModuleHandleRequest(ASession: TObject;  var Handled: Boolean);

var
  sUser,
  sPass,
  fpName,fpValue,
  fpCompName,
  s                 : String;
  I,J               : Integer;

  sAjaxValues,
  sRefererValues    : TStringList;
  REQ               : TIdHTTPRequestInfo; // uIdCustomHTTPServer
begin

Try

//replace  ARequestInfo  with TUniGUISession(ASession).ARequest

//If (sSessionID <> '')
If (POS ('_fp_',TUniGUISession(ASession).ARequest.UnparsedParams)> 0)
AND (UniServerModule.ProtectDataList.Count > 0)
then begin
sAjaxValues := TStringList.Create;
sAjaxValues.Delimiter := '&';
sAjaxValues.StrictDelimiter := True;
sAjaxValues.DelimitedText := uniGUIJSUtils.URIDecode(TUniGUISession(ASession).ARequest.UnparsedParams);
TRY
  if (sAjaxValues.IndexOfName ('_fp_') > 0)
  then begin
      for J := 0 to UniServerModule.ProtectDataList.Count - 1 do begin
        fpCompName := UniServerModule.ProtectDataList.ValueFromIndex [J];
        fpName := sAjaxValues.Values[fpCompName];
        fpValue := '';
        if fpName <> '' then begin
          for I := Length (fpName) downto 1 do begin
              case fpName [I] of
                   '%' : begin
                        delete (fpValue,1,2);
                        break;
                   end
                   else fpValue := fpName [I] + fpValue;
              end;
          end;//for I
          sAjaxValues.Values[fpCompName] := StringReplace (sAjaxValues.Values[fpCompName],fpValue,'123',[]);

         TUniGUISession(ASession).ARequest.Params.Values ['_fp_'] := '&' + sAjaxValues [sAjaxValues.IndexOfName(fpCompName)];
          sAjaxValues.Values ['_fp_'] := HTTPEncode ('&' + sAjaxValues [sAjaxValues.IndexOfName(fpCompName)]);
          sAjaxValues.Delete (sAjaxValues.IndexOfName (fpCompName));

          TUniGUISession(ASession).ARequest.UnparsedParams := sAjaxValues.DelimitedText;

          TUniGUISession(ASession).ARequest.FormParams := sAjaxValues.DelimitedText;
        end;//If
      end;//for J
  end;//If
  sAjaxValues.Clear;
  sAjaxValues.Free;

EXCEPT

END;
end;

Link to comment
Share on other sites

LoginForm:

procedure TUniLoginFrm.UniLoginFormReady(Sender: TObject);
begin

    // Add Components for encryption in Application Layer
    if UniServerModule.ProtectDataList.IndexOfName(UniEditUser.Name) <= 0 then
    UniServerModule.ProtectDataList.Add(UniEditUser.Name + '=' + UniEditUser.JSName)
    // add JSName of Element for UserName
    else
    UniServerModule.ProtectDataList.Values[UniEditUser.Name] := UniEditUser.JSName;

    if UniServerModule.ProtectDataList.IndexOfName(UniEditPass.Name) <= 0 then
    UniServerModule.ProtectDataList.Add(UniEditPass.Name + '=' + UniEditPass.JSName)
    // add JSName of Element for UserPass
    else
    UniServerModule.ProtectDataList.Values[UniEditPass.Name] := UniEditPass.JSName;
end;
 

UniMainModule:

procedure TUniMainModule.UniGUIMainModuleHandleRequest(ASession: TObject; var Handled: Boolean);
var
  sUser, sPass, fpName, fpValue, fpCompName, s: String;
  I, J: integer;

  sAjaxValues, sRefererValues: TStringList;
  REQ: TIdHTTPRequestInfo; // uIdCustomHTTPServer
begin

  Try

    // replace  ARequestInfo  with TUniGUISession(ASession).ARequest

    // If (sSessionID <> '')
    If (POS('_fp_', TUniGUISession(ASession).ARequest.UnparsedParams) > 0) AND
      (UniServerModule.ProtectDataList.Count > 0) then
    begin
      sAjaxValues := TStringList.Create;
      sAjaxValues.Delimiter := '&';
      sAjaxValues.StrictDelimiter := true;
      sAjaxValues.DelimitedText := uniGUIJSUtils.URIDecode(TUniGUISession(ASession)
        .ARequest.UnparsedParams);
      TRY
        if (sAjaxValues.IndexOfName('_fp_') > 0) then
        begin
          for J := 0 to UniServerModule.ProtectDataList.Count - 1 do
          begin
            fpCompName := UniServerModule.ProtectDataList.ValueFromIndex[J];
            fpName := sAjaxValues.Values[fpCompName];
            fpValue := '';
            if fpName <> '' then
            begin
              for I := Length(fpName) downto 1 do
              begin
                case fpName[I] of
                  '%':
                    begin
                      delete(fpValue, 1, 2);
                      break;
                    end
                else
                  fpValue := fpName[I] + fpValue;
                end;
              end; // for I
              sAjaxValues.Values[fpCompName] := StringReplace(sAjaxValues.Values[fpCompName],
                fpValue, '123', []);

              TUniGUISession(ASession).ARequest.Params.Values['_fp_'] :=
                '&' + sAjaxValues[sAjaxValues.IndexOfName(fpCompName)];
              sAjaxValues.Values['_fp_'] :=
                HTTPEncode('&' + sAjaxValues[sAjaxValues.IndexOfName(fpCompName)]);
              sAjaxValues.delete(sAjaxValues.IndexOfName(fpCompName));

              TUniGUISession(ASession).ARequest.UnparsedParams := sAjaxValues.DelimitedText;

              TUniGUISession(ASession).ARequest.FormParams := sAjaxValues.DelimitedText;
            end; // If
          end; // for J
        end; // If
        sAjaxValues.Clear;
        sAjaxValues.Free;

      EXCEPT

      END;
    end;
  Finally

  End;
end;

 

UniServerModule:

  public
    { Public declarations }
    ProtectDataList: TStringList;
  end;
 

procedure TUniServerModule.UniGUIServerModuleBeforeInit(Sender: TObject);
begin

  ProtectDataList := TStringList.Create;
 

end;

procedure TUniServerModule.UniGUIServerModuleBeforeShutdown(Sender: TObject);
begin

  ProtectDataList.Clear;
  ProtectDataList.Free;

end;

Link to comment
Share on other sites

Yes, that's all and it's right.

If there is no effect, it may be better for @Sherzod or another member of the uniGui team to help with this
I see in the Google chrome console, the file in which the function for filling in the values is performed and maybe something needs to be changed in the file.

Link to comment
Share on other sites

1 hour ago, irigsoft said:

Yes, that's all and it's right.

If there is no effect, it may be better for @Sherzod or another member of the uniGui team to help with this
I see in the Google chrome console, the file in which the function for filling in the values is performed and maybe something needs to be changed in the file.

Thanks

Link to comment
Share on other sites

10 minutes ago, huayan889 said:

Thanks

Hi, I see that in Your code, You use UniEditUser for Username, but that is not right in LoginForm.

Maybe You must replace UniEditUser with correct component.

I make test with empty uniGui project and just add this uniEdit field: UniEditUser and UniEditPass, they are not user name and password from loginform.

This is possible reason !

Try to replace in this procedure uniEditUser and uniEditPass with component for User and Pass from loginform

 

procedure TUniLoginFrm.UniLoginFormReady(Sender: TObject);
begin

    // Add Components for encryption in Application Layer
    if UniServerModule.ProtectDataList.IndexOfName(UniEditUser.Name) <= 0 then
    UniServerModule.ProtectDataList.Add(UniEditUser.Name + '=' + UniEditUser.JSName)
    // add JSName of Element for UserName
    else
    UniServerModule.ProtectDataList.Values[UniEditUser.Name] := UniEditUser.JSName;

    if UniServerModule.ProtectDataList.IndexOfName(UniEditPass.Name) <= 0 then
    UniServerModule.ProtectDataList.Add(UniEditPass.Name + '=' + UniEditPass.JSName)
    // add JSName of Element for UserPass
    else
    UniServerModule.ProtectDataList.Values[UniEditPass.Name] := UniEditPass.JSName;
end;

 

In Your SQL code You use UniEdit1 and UniEdit2

"UniQuery1.Active := false;
    UniQuery1.SQL.Text := 'select * from ss_customer_info where (customer_id=' + chr(39) +
    UniEdit1.Text + chr(39) + ') and  (admin_id =' + chr(39) + UniEdit2.Text + chr(39) +
    ') and  (admin_pass=' + chr(39) + MD5(cl_decrypt(uniedit2.text)) + chr(39) + ')';
    UniQuery1.Open;"

Link to comment
Share on other sites

 

4 minutes ago, irigsoft said:

Hi, I see that in Your code, You use UniEditUser for Username, but that is not right in LoginForm.

Maybe You must replace UniEditUser with correct component.

I make test with empty uniGui project and just add this uniEdit field: UniEditUser and UniEditPass, they are not user name and password from loginform.

This is posible reason !

OK, I'll revise and test

Link to comment
Share on other sites

3 minutes ago, huayan889 said:

 

OK, I'll revise and test

Try to replace in this procedure uniEditUser and uniEditPass with component for User and Pass from loginform

 

procedure TUniLoginFrm.UniLoginFormReady(Sender: TObject);
begin

    // Add Components for encryption in Application Layer
    if UniServerModule.ProtectDataList.IndexOfName(UniEditUser.Name) <= 0 then
    UniServerModule.ProtectDataList.Add(UniEditUser.Name + '=' + UniEditUser.JSName)
    // add JSName of Element for UserName
    else
    UniServerModule.ProtectDataList.Values[UniEditUser.Name] := UniEditUser.JSName;

    if UniServerModule.ProtectDataList.IndexOfName(UniEditPass.Name) <= 0 then
    UniServerModule.ProtectDataList.Add(UniEditPass.Name + '=' + UniEditPass.JSName)
    // add JSName of Element for UserPass
    else
    UniServerModule.ProtectDataList.Values[UniEditPass.Name] := UniEditPass.JSName;
end;

 

In Your SQL code You use UniEdit1 and UniEdit2

"UniQuery1.Active := false;
    UniQuery1.SQL.Text := 'select * from ss_customer_info where (customer_id=' + chr(39) +
    UniEdit1.Text + chr(39) + ') and  (admin_id =' + chr(39) + UniEdit2.Text + chr(39) +
    ') and  (admin_pass=' + chr(39) + MD5(cl_decrypt(uniedit2.text)) + chr(39) + ')';
    UniQuery1.Open;"

 

Link to comment
Share on other sites

13 minutes ago, irigsoft said:

Try to replace in this procedure uniEditUser and uniEditPass with component for User and Pass from loginform

 

procedure TUniLoginFrm.UniLoginFormReady(Sender: TObject);
begin

    // Add Components for encryption in Application Layer
    if UniServerModule.ProtectDataList.IndexOfName(UniEditUser.Name) <= 0 then
    UniServerModule.ProtectDataList.Add(UniEditUser.Name + '=' + UniEditUser.JSName)
    // add JSName of Element for UserName
    else
    UniServerModule.ProtectDataList.Values[UniEditUser.Name] := UniEditUser.JSName;

    if UniServerModule.ProtectDataList.IndexOfName(UniEditPass.Name) <= 0 then
    UniServerModule.ProtectDataList.Add(UniEditPass.Name + '=' + UniEditPass.JSName)
    // add JSName of Element for UserPass
    else
    UniServerModule.ProtectDataList.Values[UniEditPass.Name] := UniEditPass.JSName;
end;

 

In Your SQL code You use UniEdit1 and UniEdit2

"UniQuery1.Active := false;
    UniQuery1.SQL.Text := 'select * from ss_customer_info where (customer_id=' + chr(39) +
    UniEdit1.Text + chr(39) + ') and  (admin_id =' + chr(39) + UniEdit2.Text + chr(39) +
    ') and  (admin_pass=' + chr(39) + MD5(cl_decrypt(uniedit2.text)) + chr(39) + ')';
    UniQuery1.Open;"

 

      UniQuery1.Active := false;
      UniQuery1.SQL.Text := 'select * from ss_users where (customer_id=' + chr(39) + UniEdit1.Text +
        chr(39) + ') and  (user_account =' + chr(39) + UniEditUser.Text + chr(39) +
        ') and  (user_pass=' + chr(39) + MD5(cl_decrypt(UniEditPass)) + chr(39) + ')';
      UniQuery1.Open;

Link to comment
Share on other sites

27 minutes ago, huayan889 said:

UniQuery1.Active := false;
      UniQuery1.SQL.Text := 'select * from ss_users where (customer_id=' + chr(39) + UniEdit1.Text +
        chr(39) + ') and  (user_account =' + chr(39) + UniEditUser.Text + chr(39) +
        ') and  (user_pass=' + chr(39) + MD5(cl_decrypt(UniEditPass)) + chr(39) + ')';
      UniQuery1.Open;

Sorry for this confusion: You need to replace uniEditUser with uniEdi1 and uniEditPass with uniEdit2 .

This code is correct after replace them:

procedure TUniLoginFrm.UniLoginFormReady(Sender: TObject);
begin

    // Add Components for encryption in Application Layer
    if UniServerModule.ProtectDataList.IndexOfName(UniEdit1.Name) <= 0 then
    UniServerModule.ProtectDataList.Add(UniEdit1.Name + '=' + UniEdit1.JSName)
    // add JSName of Element for UserName
    else
    UniServerModule.ProtectDataList.Values[UniEdit1.Name] := UniEdit1.JSName;

    if UniServerModule.ProtectDataList.IndexOfName(UniEdit2.Name) <= 0 then
    UniServerModule.ProtectDataList.Add(UniEdit2.Name + '=' + UniEdit2.JSName)
    // add JSName of Element for UserPass
    else
    UniServerModule.ProtectDataList.Values[UniEdit2.Name] := UniEdit2.JSName;
end;

Link to comment
Share on other sites

1 minute ago, huayan889 said:

uniedit1 no userpassword

I don't know the correct name of the Edit field for a username in the login form.

I see in your sql code, you gave as an example that you use to enter username uniEdit1.

In my code I use uniEditUser as my username (not with that name in your login form).

So take the correct name of your login form and use it in this procedure to replace uniEditUser and uniEditpass with the correct component name.

If you component name for username is uniEdit1 and for pass is uniEdit2

This code will be correct:

procedure TUniLoginFrm.UniLoginFormReady(Sender: TObject);
begin

    // Add Components for encryption in Application Layer
    if UniServerModule.ProtectDataList.IndexOfName(UniEdit1.Name) <= 0 then
    UniServerModule.ProtectDataList.Add(UniEdit1.Name + '=' + UniEdit1.JSName)
    // add JSName of Element for UserName
    else
    UniServerModule.ProtectDataList.Values[UniEdit1.Name] := UniEdit1.JSName;

    if UniServerModule.ProtectDataList.IndexOfName(UniEdit2.Name) <= 0 then
    UniServerModule.ProtectDataList.Add(UniEdit2.Name + '=' + UniEdit2.JSName)
    // add JSName of Element for UserPass
    else
    UniServerModule.ProtectDataList.Values[UniEdit2.Name] := UniEdit2.JSName;
end;

Link to comment
Share on other sites

15 minutes ago, irigsoft said:

I don't know the correct name of the Edit field for a username in the login form.

I see in your sql code, you gave as an example that you use to enter username uniEdit1.

In my code I use uniEditUser as my username (not with that name in your login form).

So take the correct name of your login form and use it in this procedure to replace uniEditUser and uniEditpass with the correct component name.

If you component name for username is uniEdit1 and for pass is uniEdit2

This code will be correct:

procedure TUniLoginFrm.UniLoginFormReady(Sender: TObject);
begin

    // Add Components for encryption in Application Layer
    if UniServerModule.ProtectDataList.IndexOfName(UniEdit1.Name) <= 0 then
    UniServerModule.ProtectDataList.Add(UniEdit1.Name + '=' + UniEdit1.JSName)
    // add JSName of Element for UserName
    else
    UniServerModule.ProtectDataList.Values[UniEdit1.Name] := UniEdit1.JSName;

    if UniServerModule.ProtectDataList.IndexOfName(UniEdit2.Name) <= 0 then
    UniServerModule.ProtectDataList.Add(UniEdit2.Name + '=' + UniEdit2.JSName)
    // add JSName of Element for UserPass
    else
    UniServerModule.ProtectDataList.Values[UniEdit2.Name] := UniEdit2.JSName;
end;

image.thumb.png.6c5b01c156ba2bd6f414bd997dfc368e.png

image.thumb.png.d350770676e37cb7cbf4b31098bcf273.png

image.png

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...