You can only achieve this securely with your operating system's permission system.

For example your CGI script could generate random session IDs and store them in a database or flat file and passes it to your non-CGI script, and your non-CGI script checks that resource (DB/file) if that session ID is present, and deletes it (to ensure it's used only once).

But if you want the scheme to be secure, you have to make sure that no other user on the system can read or write that file/DB - and that's the task of your operating system. For example on unix you'd have to run the apache process that starts the CGI under a special user, and all other users are not allowed to read/write that file/DB.

Thinking a bit more of it, perhaps you can just check the user ID - nobody but root and Apache can run a script under Apache's UID. (If your potential attacker has root access, you're lost anyway).


In reply to Re: avoid by pass of web interface by moritz
in thread avoid by pass of web interface by advait

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.