2

I inherited an application that has a custom variable in the CGI Scope:

CGI.HTTP_variablename

How are custom variables added to the CGI Scope in ColdFusion (in this case, version 2018).

This variable is internal to the organization and is used with CFLDAP for user verification, so it cannot be done a different way.

I also do not have access to the web server or the ColdFusion administrator to just check how it was done. All I have access to is the source code, and there is nothing in the source code that helps to answer this question.

The site itself is hosted in IIS, but the ColdFusion Administrator is running on TomCat.

Thank you.

  • 1
    It probably can be done a different way. The server scope comes to mind, as does the application scope. – Dan Bracuk Dec 22 '21 at 17:27
  • What is the variable, are you sure its custom? – haxtbh Dec 22 '21 at 17:28
  • Does this answer your question? [Create CGI Custom Server variable in Coldfusion 2018](https://stackoverflow.com/questions/69033375/create-cgi-custom-server-variable-in-coldfusion-2018) – James Moberg Dec 22 '21 at 17:53
  • James - No, doesn't answer. haxtbh - Yes, I'm sure it's custom, since it includes the company name in the actual variable name. Dan - Already state it can't be done a different way. – RickInWestPalmBeach Dec 22 '21 at 20:14

2 Answers2

5

That's not a "custom variable" per se. What you're seeing is a behavior of the CGI scope that allows you to access any HTTP request headers via the convention of

cgi.http_<name of header>

This means, for instance, you can access the host or user agent as either

getHTTPRequestData().headers.host
getHTTPRequestData().headers['user-agent']

or

cgi.http_host
cgi['http_user-agent']

Likewise, any custom HTTP headers sent from the client can be accessed in the same manners.

getHTTPRequestData().headers.myCustomHeader
cgi.http_myCustomHeader
Brad Wood
  • 3,863
  • 16
  • 23
  • Would this header be found in code? Or could it be set in the ColdFusion Administrator ? – RickInWestPalmBeach Dec 23 '21 at 14:56
  • You can add with code: https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-tags/tags-g-h/cfheader.html or add via the webserver: https://learn.microsoft.com/en-us/troubleshoot/iis/add-http-response-header-web-site – Adrian J. Moreno Dec 23 '21 at 15:05
  • The HTTP header would be set by whatever client sent the HTTP request. This could be a browser, another app server, an Ajax call, Postman, or some CFML code. I really don't know enough about your setup to answer this for you. But the main point is, the server RECEIVING the HTTP request has no control over creating the header. It's the client SENDING the HTTP request that adds the header. – Brad Wood Dec 23 '21 at 18:50
0

The CGI scope is a read-only struct that cannot be modified in your CFML code. See: https://helpx.adobe.com/coldfusion/cfml-reference/reserved-words-and-variables/cgi-environment-cgi-scope-variables.html

If you need to set a custom CGI variable, you will need to set it from the web server, which will depend on the web server you are using. They are typically called Environment Variables on the web server.

Redtopia
  • 4,947
  • 7
  • 45
  • 68
  • I already know all about the CGI Scope. I assume it must be done from the web server. Can you be more specific? My original question refers to web servers being used. – RickInWestPalmBeach Dec 22 '21 at 20:15
  • I have no idea what you already know, and I want to make sure the answer is clear that you cannot directly modify the CGI scope, which is specified in the doc I linked to. As far as adding an environment variable in IIS, you need to add them to the `system.webServer/httpPlatform/environmentVariables` property. There are lots of articles that discuss this, but they depend on how IIS is currently configured. Check out this thread: https://stackoverflow.com/questions/55641276/configuring-python-for-iis, which is not exactly specific to your question, but might help. – Redtopia Dec 22 '21 at 21:32
  • Lucee Server allows the CGI scope to be written to, but it really doesn't make any sense to do so outside of mocking variables for testing, etc. Also, writing values to the CGI scope which come from the web server or servlet context does not actually change the source value. It only changes a copy in memory. – Brad Wood Dec 23 '21 at 20:48