#1 Re: mORMot 1 » Delphi 10 Seattle-Win64 TestSQL3 error » 2021-03-26 12:45:24

Hi,

I just got the same issue as the OP, and logs show the following:

20210326 12194517 EXCOS EAccessViolation (c0000005) [] at 9ac5e9 
20210326 12194517 EXC   EAccessViolation ("Access violation at address 00000000009AC5E9 in module 'TestSQL3.exe'. Read of address 0000000000000050") [] at 9ac5e9 
20210326 12194517 fail  #25  stack trace API 689f71 6a95e1 b9e02d 6aa55a bcc072 bcc3d4 bcc5da 7ff94a6a7974 7ff94d3ea2d1 
20210326 12194517 fail  SynSelfTests.TTestFileBased(02b4f3d0) File based - TSQLRestClientDB [] stack trace API 689274 6abfcd 6a9601 b9e02d 6aa55a bcc072 bcc3d4 bcc5da 7ff94a6a7974 7ff94d3ea2d1 

Delphi 10.2 Update 3. It happens on Win64 target only. Debugger just throws me to CPU window. Using the latest sources of mORMot.

Edit: I picked an older version mORMot-1.18.4952.zip and the tests passed successfully.

#2 Re: mORMot 1 » Web browser requesting favicon.ico » 2020-11-26 19:11:54

Sorry, it turned out that's not a question related to mORMot. Just in case, favicon can be redirected with:

<link rel="shortcut icon" href="/root/service/favicon.ico">

#3 mORMot 1 » Web browser requesting favicon.ico » 2020-11-26 17:22:28

vlad
Replies: 4

Hello,

I'm running TSQLRestServerDB on TSQLHttpServer. The client is web browser, and it is looking for favicon.ico:

favicon.ico:1 GET http://localhost:1044/favicon.ico 404 (Not Found)

Please let me know how I could return the file to browser.

#4 Re: mORMot 1 » Query Authentication and links to static content » 2020-11-23 21:34:40

Thanks, AB. With my humble knowledge I've implemented JWT as follows:

1) After query authentication succeeds, the web client gets the JWT token containing TAuthSession session ID and stores it as a cookie.
2) Once the method-based service for static content is triggered, I read the JWT from Ctxt.InCookie. Do TJWTHS256.Verify, extract session ID and do TSQLRestServerDB.SessionGetUser. Returning the error if verification fails or user not found.

I'm not sure SessionGetUser is the right way to call it here, though, since it locks the data. Any advice to improve all this is highly appreciated.

#5 Re: mORMot 1 » Query Authentication and links to static content » 2020-11-22 22:57:24

I've implemented a method-based service for static files serving. But it is being called only when authentication flag in TSQLRestServerDB is disabled. Once authentication is switched on, any URL pointing to that method-based service will trigger TSQLRestServerDB.OnAuthenticationFailed, with no chance to do cookie checking in the service itself. On the other hand, I cannot switch off query authentication, it is the main thing in security for my interface-based services. Or may be I didn't understand the hint properly? Kindly advise.

Edit: Sorry, I found the way to disable authentication of method-based service by using ServiceMethodByPassAuthentication.

Is there a commonly used approach to check authentication on such exposed services based on cookies? What would be the more secured workflow in order to prevent user from manipulating cookies from debugger and access the static data?

#6 mORMot 1 » Query Authentication and links to static content » 2020-11-22 20:30:54

vlad
Replies: 4

Hello,

I'm running a TSQLRestServerDB with query authentication enabled. The client side is browser where authentication is processed by a jQuery code. All works fine, session_signature is appened on each ajax request to my interface-based service.

However, the resulting client page may contain paths to some static content (<img>, <a>, <script>, <link> etc) also stored on the server. I found this content can easily be provided to client from TSQLRestServerDB.OnAuthenticationFailed (Ctxt.Returns). I get the Ctxt.URIAfterRoot and parse it accordingly. But this method bypass authentication and is not acceptable.

Could you please advise the best practice to get static content from the server without jeopardizing mORMot security? I was trying to dig into ServiceWorker / Fetch event on browser side in order to intercept URLs to static content and replace with requests to a interface-based service with computed session_signature, could not make it work.

#7 Re: mORMot 1 » Random exceptions in FPC/Lazarus on server closure » 2018-02-16 12:24:58

mpv wrote:

About GZIP - see this topic

Applied it, but compilation ended with SynZipFiles.pas(928,53) Error: Identifier not found "ZLIB_VERSION".

#8 Re: mORMot 1 » Random exceptions in FPC/Lazarus on server closure » 2018-02-16 11:08:42

Sorry for large blocks of code, my fault.

Picked your example, but keep getting random exceptions occasionally. Played also with Sleep() by setting various timings, but the crash happens on aHTTPServer.Free call, so the pause does not have impact as such.

In case it helps, TestSQL3 test went smoothly except this one:

 1.5. Compression:
!  - GZIP format: 1 / 19 FAILED  708.40ms

#9 Re: mORMot 1 » Random exceptions in FPC/Lazarus on server closure » 2018-02-16 08:11:42

Same random exceptions. The code below:

program cbserver;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  {$I SynDprUses.inc}
  Classes, SysUtils,
  SynCommons, SynLog, mORMot, mORMotHttpServer, mORMotSQLite3, SynSQLite3Static, SynDB;

type

  { ICBService }

  ICBService = interface(IInvokable)
    ['{2061324A-51C8-48FC-82CC-D21ECC3D16E1}']
    function Test2: RawUTF8;
  end;

  { TCBService }

  TCBService = class(TInjectableObjectRest, ICBService)
    function Test2: RawUTF8;
  end;

const
  ROOT_NAME = 'root';
  DEFAULT_PORT = '1044';

var
  aServer: TSQLRestServer;
  aHTTPServer: TSQLHttpServer;
  aModel: TSQLModel;

  { TCBService }

function TCBService.Test2: RawUTF8;
begin
  Result := 'sss';
end;

begin
TInterfaceFactory.RegisterInterfaces([TypeInfo(ICBService)]);

with TSQLLog.Family do begin
  Level := LOG_VERBOSE;
  EchoToConsole := LOG_VERBOSE; // log all events to the console
end;
aModel := TSQLModel.Create([], ROOT_NAME);
try
  aServer := TSQLRestServerDB.Create(aModel, 'cbs.db3', false);
  try
    aServer.CreateMissingTables;
    aServer.ServiceDefine(TCBService, [ICBService], sicShared);
    aHTTPServer := TSQLHttpServer.Create(AnsiString(DEFAULT_PORT), [aServer], '+', useHttpApiRegisteringURI);
    try
      writeln(#10'Background server is running.'#10);
      writeln('Press [Enter] to close the server.'#10);
      readln;
    finally
      aHTTPServer.Free;
    end;
  finally
    aServer.Free;
  end;
finally
  aModel.Free;
end;


end.

#10 mORMot 1 » Instantiating a TObject parameter from non-mORMot client » 2018-02-15 23:04:47

vlad
Replies: 1

Hello,

How could I instantiate the aCustomer parameter from a non-Delphi client?

  ICustomerFactory = interface(IInvokable)
    ['{770D009F-15F4-4307-B2AD-BBAE42FE70C0}']
    procedure NewCustomer(out aCustomer: TCustomer);
  end;

Thank you.

#11 mORMot 1 » Random exceptions in FPC/Lazarus on server closure » 2018-02-15 21:51:00

vlad
Replies: 7

Hello,

I just built a small test mORMot server on latest Lazarus, and observed random exceptions on exit. Server source below:

program cbserver;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes, SysUtils, CustApp,
  SynCommons, SynLog, mORMot, mORMotHttpServer, mORMotSQLite3, SynSQLite3Static, SynDB;

type

  { TCBServer }

  TCBServer = class(TCustomApplication)
  protected
    procedure DoRun; override;
  public
    constructor Create(TheOwner: TComponent); override;
    destructor Destroy; override;
  end;

  { ICBService }

  ICBService = interface(IInvokable)
    ['{2061324A-51C8-48FC-82CC-D21ECC3D16E1}']
    function Test2: RawUTF8;
  end;

  { TCBService }

  TCBService = class(TInjectableObjectRest, ICBService)
    function Test2: RawUTF8;
  end;

const
  ROOT_NAME = 'root';
  DEFAULT_PORT = '1044';

var
  aServer: TSQLRestServer;
  aHTTPServer: TSQLHttpServer;
  aModel: TSQLModel;

{ TCBService }

function TCBService.Test2: RawUTF8;
begin
  Result := 'sss';
end;

{ TCBServer }

procedure TCBServer.DoRun;
begin
  TInterfaceFactory.RegisterInterfaces([TypeInfo(ICBService)]);

  with TSQLLog.Family do begin
    Level := LOG_VERBOSE;
    EchoToConsole := LOG_VERBOSE; // log all events to the console
  end;
  aModel := TSQLModel.Create([], ROOT_NAME);
  try
    aServer := TSQLRestServerDB.Create(aModel, 'cbs.db3', false);
    try
      aServer.CreateMissingTables;
      aServer.ServiceDefine(TCBService, [ICBService], sicShared);
      aHTTPServer := TSQLHttpServer.Create(AnsiString(DEFAULT_PORT), [aServer], '+', useHttpApiRegisteringURI);
      try
        writeln(#10'Background server is running.'#10);
        writeln('Press [Enter] to close the server.'#10);
        readln;
      finally
        aHTTPServer.Free;
      end;
    finally
      aServer.Free;
    end;
  finally
    aModel.Free;
  end;


  Terminate;
end;

constructor TCBServer.Create(TheOwner: TComponent);
begin
  inherited Create(TheOwner);
  StopOnException := True;
end;

destructor TCBServer.Destroy;
begin
  inherited Destroy;
end;

var
  Application: TCBServer;
begin
  Application := TCBServer.Create(nil);
  Application.Title := 'Test';
  Application.Run;
  Application.Free;
end.

Sometimes, it exits gracefully:

Heap dump by heaptrc unit of D:\dev\lazarus\projects\CBS\cbserver.exe
2770 memory blocks allocated : 1427827/1436584
2770 memory blocks freed     : 1427827/1436584
0 unfreed memory blocks : 0
True heap size : 720896 (160 used in System startup)
True free heap : 720736

But often, various memory leaks and exceptions are thrown:

488 memory blocks allocated : 545751/546896
480 memory blocks freed     : 544727/545872
8 unfreed memory blocks : 1024
True heap size : 229376 (160 used in System startup)
True free heap : 227552
Should be : 227168
20180215 21353104  +            SynSQLite3.TSQLDatabase(035B6210).Destroy cbs.db3
Call trace for block $00000000095184D0 size 272
  $000000010000E582
  $000000010000AF70
...
20180215 21353104 EXCOS                         EExternalException (C0000005) at 00000001001637A8
20180215 21353104 DB                            SynSQLite3.TSQLDatabase(035B6210) closing "cbs.db3" 0 B
20180215 21353104 EXC                           ESQLite3Exception {"ErrorCode":0,"SQLite3ErrorCode":"secUnknown","Messag
e":"TSQLDatabase.DBClose called with no sqlite3 global"} at 0000000100160F08
20180215 21353104  -                    00.002.401
20180215 21353104  -            00.002.576
20180215 21353104  -    00.003.032
20180215 21353104 EXCOS EExternalException (C0000005) at 000000010000F38C
:
.
20180215 21353104 EXCOS EExternalException (C0000005) at 000000010000F38C
An unhandled exception occurred at $000000010000F38C:
EAccessViolation:
  $000000010000F38C
  $000000010000F489

or this:

20180215 21401560 EXCOS EExternalException (C0000005) at   $000000010003B3D6  VARRECTOTEMPUTF8,  line 20970 of ../../com
ponents/mORMot/SynCommons.pas
An unhandled exception occurred at $000000010003B3D6:
EAccessViolation: Access violation
20180215 21401600  -    00.032.184
20180215 21401600  +    mORMotSQLite3.TSQLRestServerDB(00167630).Destroy root
20180215 21401600  +            mORMotSQLite3.TSQLRestServerDB(00167630).Shutdown() root CurrentRequestCount=0
  $000000010003B3D6  VARRECTOTEMPUTF8,  line 20970 of ../../components/mORMot/SynCommons.pas
  $00000001000405AC  FORMATUTF8,  line 25512 of ../../components/mORMot/SynCommons.pas
  $000000010004032E  FORMATUTF8,  line 25471 of ../../components/mORMot/SynCommons.pas
20180215 21401601  -            00.012.421
20180215 21401601 info          mORMotSQLite3.TSQLRestServerDB(00167630) Destroy root
20180215 21401601  +            SynSQLite3.TSQLDatabase(001392F0).Destroy cbs.db3
20180215 21401601  +
20180215 21401601 DB                            SynSQLite3.TSQLDatabase(001392F0) closing "cbs.db3" 40 KB
20180215 21401601  -                    00.000.478
20180215 21401601  -            00.000.601
20180215 21401601  -    00.014.396
  $0000000100081658  CREATEUTF8,  line 62437 of ../../components/mORMot/SynCommons.pas
Heap dump by heaptrc unit of D:\dev\lazarus\projects\CBS\cbserver.exe
2751 memory blocks allocated : 1405971/1414704
An unhandled exception occurred at $00000001000175FD:
2751 memory blocks freed     : 1405971/1414704
0 unfreed memory blocks : 0
True heap size : 720896 (160 used in System startup)
True free heap : 720736
EInOutError: Invalid file handle
  $00000001000175FD
  $0000000100018BD1
  $0000000100018D57
  $00000001000346C0

My setup: Windows 10 64bit, Lazarus 1.9 from trunk (fpcupdeluxery), latest mORMot. Compiler - same target platform.

Any ideas?

#12 Re: mORMot 1 » Remove "stored AS_UNIQUE" attribute » 2018-02-12 00:46:33

In this particular case DROP INDEX returns "index associated with unique or primary key constraint cannot be dropped".

#13 mORMot 1 » Remove "stored AS_UNIQUE" attribute » 2018-02-11 18:54:09

vlad
Replies: 3

Hello,

One of my TSQLRecord classes had "stored AS_UNIQUE" property attribute. I removed the declaration, but actual index remained in the database. What would be the proper way to remove that index? Tried DROP INDEX from backend but SQLite3 does not allow that.

#15 Re: mORMot 1 » TCollection and Error Code 406 » 2017-08-28 13:24:24

Thanks Arnaud. For now I'll stick to interface-based service in order not to change things much. I replaced TServiceCustomAnswer input parameter with RawByteString:

function Save(const aItem: TSQLImage; const Data: RawByteString; out ID: TID): RawUTF8;

However, I'm still getting 406 exception. This happens only when I add Sprites property to TSQLImage class in example above.

#16 mORMot 1 » TCollection and Error Code 406 » 2017-08-28 12:43:49

vlad
Replies: 4

Hello,

I keep getting error code 406 exception when trying to publish a TInterfacedCollection property to TSQLRecord class that in turn is a parameter to a function of an interface. I also tried TObjectList with TJSONSerializer.RegisterClassForJSON instead of TCollection, but with the same result. In example below if I remove Sprites property from TSQLImage, everything works properly.

Could you please help me understand what I'm doing wrong?

  TSprite = class(TCollectionItem)
  published
    property ImageID: integer read fImageID write fImageID;
    property Name: string read fName write fName;
    property Left: integer read fLeft write fLeft;
    property Top: integer read fTop write fTop;
    property Height: integer read fHeight write fHeight;
    property Width: integer read fWidth write fWidth;
    property FlipHorz: boolean read fFlipHorz write fFlipHorz;
    property FlipVert: boolean read fFlipVert write fFlipVert;
    property Scale: integer read fScale write fScale;
    property Visible: boolean read fVisible write fVisible;
  end;

  TSpriteList = class(TInterfacedCollection)
  private
    function GetCollItem(aIndex: Integer): TSprite;
  protected
    class function GetClass: TCollectionItemClass; override;
  public
    function Add: TSprite;
    property Item[aIndex: Integer]: TSprite read GetCollItem; default;
  end;

  TSQLImage = class(TSQLRecord)
  published
    property Name: string index 30 read fName write fName stored AS_UNIQUE;
    property Image: TSQLRawBlob read fImage write fImage;
    property Sprites: TSpriteList read fSprites;
  end;

  IQBImageService = interface(IInvokable)
    ['{26D32153-FAE3-4CDE-AB32-C5A6A334015B}']
    function Save(const aItem: TSQLImage; const Data: TServiceCustomAnswer; out ID: TID): RawUTF8;
  end;

-------------------------------------
    gs_rec := TSQLImage.Create;
    gs_rec.Name := 'test';
    cu.Header := BINARY_CONTENT_TYPE_HEADER;
    cu.Content := '';

    if aClient.Services.Resolve(IQBImageService, I) = true then
    begin
      st_err := I.Save(gs_rec, cu, ID);
    end;
-------------------------------------

First chance exception at $76D3B802. Exception class EInterfaceFactoryException with message
'TInterfacedObjectFakeClient.FakeCall(IQBImageService.Save) failed: '{
"errorCode":406,
"errorText":"sicShared execution failed (probably due to bad input parameters) for QBImageService.Save"
}''.
Process QB.exe (10816)

Board footer

Powered by FluxBB