Prevent command line parameters

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

Prevent command line parameters

Postby lkitrossky » Mon Jul 06, 2015 6:24 am

Hi! In our application we are trying to prevent users from command line parameters. In the file command_line_impl.cc we added #if !defined in the following way:
Code: Select all
CefRefPtr<CefCommandLine> CefCommandLine::GetGlobalCommandLine() {
  // Uses a singleton reference object.
  static CefRefPtr<CefCommandLineImpl> commandLinePtr;
#if !defined(NO_CMD_LINE)
  if (!commandLinePtr.get()) {
    base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
    if (command_line)
      commandLinePtr = new CefCommandLineImpl(command_line, false, true);
  }
#error "NO_CMD_LINE not defined"
#endif
  return commandLinePtr.get();
}
and we added NO_CMD_LINE to defines of libcef_static in cef.gyp. Python code treats cef.gyp and ninja builds the project OK, error "NO_CMD_LINE not defined" does not appear. So, we expected that command line parameters are switched of. However command line parameters like --no-sandbox still influence the behavior of the application, we caught it in the renderer process. What we missed? Thanks, Levi
lkitrossky
Mentor
 
Posts: 66
Joined: Tue Mar 24, 2015 7:26 am

Re: Prevent command line parameters

Postby amaitland » Mon Jul 06, 2015 7:55 am

Couldn't you just implement OnBeforeChildProcessLaunch and call Reset on the command line args?

apidocs3/projects/%28default%29/CefBrowserProcessHandler.html#OnBeforeChildProcessLaunch%28CefRefPtr%3CCefCommandLine%3E%29
apidocs3/projects/%28default%29/CefCommandLine.html#Reset%28%29

It was just an idea, I haven't tested it.
Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1291
Joined: Wed Jan 14, 2015 2:35 am

Re: Prevent command line parameters

Postby magreenblatt » Mon Jul 06, 2015 12:14 pm

Set CefSettings.command_line_args_disabled = 1.
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm

Re: Prevent command line parameters

Postby lkitrossky » Tue Jul 07, 2015 5:29 am

Thanks for speedy answers. The results can be interesting for you. I work with our class
Code: Select all
class MyApp : public CefApp,  public CefRenderProcessHandler,  public CefBrowserProcessHandler {...

I implemented as proposed above:
Code: Select all
void MyApp::OnBeforeChildProcessLaunch(CefRefPtr<CefCommandLine> command_line)
void MyApp::OnBeforeCommandLineProcessing( const CefString& process_type, CefRefPtr<CefCommandLine> command_line)

into both I added
Code: Select all
if (NULL != command_line && command_line->HasArguments()) {command_line->Reset();}
and IT DID NOT HELP. Attempts to use CefCommandLine::GetGlobalCommandLine(), CefContext::PopulateRequestContextSettings had not been working as I wrote above.
BUT advice of magreenblatt worked with a minor change:
Code: Select all
settings.command_line_args_disabled = true;  //inside wWinMain in my_win.cc

Thanks, Levi
lkitrossky
Mentor
 
Posts: 66
Joined: Tue Mar 24, 2015 7:26 am


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 50 guests