We’re using an Apache RewriteMap and other rewrite rule directives.
Our issue is that some cookies are incorrect and mixed up between sessions. We think we may have a mutex issue where Apache calls the script multiple times concurrently.
We’re using Apache 2.4.x and it should set a lock to call the script one at a time if certain conditions are set.
How could we figure out for sure if the script gets called only one at a time (the mutex lock works) or if Apache calls it multiple times in parallel.
We’re also see this error in the logs:
[Thu May 09 06:40:01.891518 2024] [rewrite:error] [pid 3732926] [client x.x.x.x:0] AH10410: Rewritten query string contains control characters or spaces
Not sure if that could cause these rewrite issues or it’s independent.
Our rewrite rules are as follows (and yes, they’re long):
##### Session management URL handling
## **** SEE SLM-DISPATCHER-SCRIPTS.README in scripts/dispatcher-scripts ****
###################
Define DTD_DEFAULT_WITH_REFERER 'O99999'
Define DTD_COOKIE_NAME 'slm_dtd_cell'
Define QUERYSTRING_COOKIE_NAME 'slm_qstring'
Define COOKIE_DOMAIN '.salliemae.com'
# SPLIT variable value MUST match value in python script
Define SPLIT 'AsplitA'
###################
### Include supporting python script file for querystring management for the slm_qstring cookie
###################
RewriteMap qstring_rewriter prg:/etc/slm/scripts/slm-sessionmanagement-script.py
###################
### Map http referrer
###################
RewriteCond %{REQUEST_URI} (\/|\.html)$ [NC]
RewriteCond %{HTTP_REFERER} ^.*\.aol.*$ [NC]
RewriteRule ^(.*)$ - [E=referer:A]
RewriteCond %{REQUEST_URI} (\/|\.html)$ [NC]
RewriteCond %{HTTP_REFERER} ^.*ask\..*$ [NC]
RewriteRule ^(.*)$ - [E=referer:K]
RewriteCond %{REQUEST_URI} (\/|\.html)$ [NC]
RewriteCond %{HTTP_REFERER} ^.*google\..*$ [NC]
RewriteRule ^(.*)$ - [E=referer:G]
RewriteCond %{REQUEST_URI} (\/|\.html)$ [NC]
RewriteCond %{HTTP_REFERER} ^.*bing\..*$ [NC]
RewriteRule ^(.*)$ - [E=referer:B]
RewriteCond %{REQUEST_URI} (\/|\.html)$ [NC]
RewriteCond %{HTTP_REFERER} ^.*msn\..*$ [NC]
RewriteRule ^(.*)$ - [E=referer:M]
RewriteCond %{REQUEST_URI} (\/|\.html)$ [NC]
RewriteCond %{HTTP_REFERER} ^.*yahoo\..*$ [NC]
RewriteRule ^(.*)$ - [E=referer:Y]
###################
### Map user agent, only if referrer mapped successfully
###################
RewriteCond %{REQUEST_URI} (\/|\.html)$ [NC]
RewriteCond %{ENV:referer} !^$
RewriteCond %{HTTP_USER_AGENT} ^.*chrome.*$ [NC]
RewriteRule ^(.*)$ - [E=useragent:CHRME]
RewriteCond %{REQUEST_URI} (\/|\.html)$ [NC]
RewriteCond %{ENV:referer} !^$
RewriteCond %{HTTP_USER_AGENT} ^.*firefox.*$ [NC]
RewriteRule ^(.*)$ - [E=useragent:FRFOX]
RewriteCond %{REQUEST_URI} (\/|\.html)$ [NC]
RewriteCond %{ENV:referer} !^$
RewriteCond %{HTTP_USER_AGENT} ^.*opr.*$ [NC]
RewriteRule ^(.*)$ - [E=useragent:OPERA]
RewriteCond %{REQUEST_URI} (\/|\.html)$ [NC]
RewriteCond %{ENV:referer} !^$
RewriteCond %{HTTP_USER_AGENT} !^.*chrome.*$ [NC] #handle Chrome's addition of Safari into its user agent string
RewriteCond %{HTTP_USER_AGENT} !^.*edg.*$ [NC] #handle Edge's addition of Safari into its user agent string
RewriteCond %{HTTP_USER_AGENT} ^.*safari.*$ [NC]
RewriteRule ^(.*)$ - [E=useragent:SFARI]
RewriteCond %{REQUEST_URI} (\/|\.html)$ [NC]
RewriteCond %{ENV:referer} !^$
RewriteCond %{HTTP_USER_AGENT} ^.*MSIE.*$ [NC]
RewriteRule ^(.*)$ - [E=useragent:EXPLR]
RewriteCond %{REQUEST_URI} (\/|\.html)$ [NC]
RewriteCond %{ENV:referer} !^$
RewriteCond %{HTTP_USER_AGENT} ^.*edg.*$ [NC]
RewriteRule ^(.*)$ - [E=useragent:EXPLR]
RewriteCond %{REQUEST_URI} (\/|\.html)$ [NC]
RewriteCond %{ENV:referer} !^$
RewriteCond %{HTTP_USER_AGENT} ^.*wow64.*$ [NC]
RewriteRule ^(.*)$ - [E=useragent:EXPLR]
###################
### Construct dtd_cell code and create/update in cookie
###################
#use any provided dtd_cell from querystring to create/update the dtd_cell cookie
RewriteCond %{REQUEST_URI} (\/|\.html)$ [NC]
RewriteCond %{QUERY_STRING} (^|&)dtd_cell=([^&]+)&?(.*)$ [NC]
RewriteRule ^(.*)$ - [CO=${DTD_COOKIE_NAME}:%2:${COOKIE_DOMAIN}:0:/:secure]
#add to slm_qstring cookie if dtd in querystring and slm_query cookie doesn't exist
RewriteCond %{REQUEST_URI} (\/|\.html)$ [NC]
RewriteCond %{HTTP_COOKIE} !${QUERYSTRING_COOKIE_NAME}=
RewriteCond %{QUERY_STRING} (^|&)dtd_cell=([^&]+)&?(.*)$ [NC]
RewriteRule ^(.*)$ - [CO=${QUERYSTRING_COOKIE_NAME}:${qstring_rewriter:%{QUERY_STRING}${SPLIT}%1}:${COOKIE_DOMAIN}:0:/:secure]
#construct when dtd_cell not in querystring and referer and agent match exists and no dtd cookie exists
RewriteCond %{REQUEST_URI} (\/|\.html)$ [NC]
RewriteCond %{ENV:referer} !^$
RewriteCond %{ENV:useragent} !^$
RewriteCond %{QUERY_STRING} !(^|&)dtd_cell= [NC]
RewriteRule ^(.*)$ - [CO=${DTD_COOKIE_NAME}:%{ENV:referer}${DTD_DEFAULT_WITH_REFERER}%{ENV:useragent}:${COOKIE_DOMAIN}:0:/:secure]
#1 of 2: construct when not in querystring and referer exists and slm_qstring cookie does not exist IF THERE IS NO QUERYSTRING
RewriteCond %{REQUEST_URI} (\/|\.html)$ [NC]
RewriteCond %{ENV:referer} !^$
RewriteCond %{ENV:useragent} !^$
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{HTTP_COOKIE} !${QUERYSTRING_COOKIE_NAME}=
RewriteRule ^(.*)$ - [CO=${QUERYSTRING_COOKIE_NAME}:dtd_cell=%{ENV:referer}${DTD_DEFAULT_WITH_REFERER}%{ENV:useragent}:${COOKIE_DOMAIN}:0:/:secure]
#2 of 2: construct when not in querystring and referer exists and slm_qstring cookie does not exist IF THERE IS A QUERYSTRING
RewriteCond %{REQUEST_URI} (\/|\.html)$ [NC]
RewriteCond %{ENV:referer} !^$
RewriteCond %{ENV:useragent} !^$
RewriteCond %{QUERY_STRING} !^$
RewriteCond %{QUERY_STRING} !(^|&)dtd_cell= [NC]
RewriteCond %{HTTP_COOKIE} !${QUERYSTRING_COOKIE_NAME}=
RewriteRule ^(.*)$ - [CO=${QUERYSTRING_COOKIE_NAME}:dtd_cell=%{ENV:referer}${DTD_DEFAULT_WITH_REFERER}%{ENV:useragent}&%{QUERY_STRING}:${COOKIE_DOMAIN}:0:/:secure]
#construct when not in querystring and referer exists and slm_qstring cookie exists
RewriteCond %{REQUEST_URI} (\/|\.html)$ [NC]
RewriteCond %{ENV:referer} !^$
RewriteCond %{ENV:useragent} !^$
RewriteCond %{QUERY_STRING} !(^|&)dtd_cell= [NC]
RewriteCond %{HTTP_COOKIE} ${QUERYSTRING_COOKIE_NAME}=(.*?(;|$))
RewriteRule ^(.*)$ - [CO=${QUERYSTRING_COOKIE_NAME}:${qstring_rewriter:dtd_cell=%{ENV:referer}${DTD_DEFAULT_WITH_REFERER}%{ENV:useragent}&%{QUERY_STRING}${SPLIT}%1}:${COOKIE_DOMAIN}:0:/:secure]
###################
### Place querystring params in a cookie
###################
# new slm_qstring cookie when we have a qs, but no slm_qstring cookie exists
RewriteCond %{REQUEST_URI} (\/|\.html)$ [NC]
#commenting null referer check per SLMCOM-788946
#RewriteCond %{ENV:referer} ^$
RewriteCond %{QUERY_STRING} !^$
RewriteCond %{HTTP_COOKIE} !${QUERYSTRING_COOKIE_NAME}=
RewriteRule ^(.*)$ - [CO=${QUERYSTRING_COOKIE_NAME}:${qstring_rewriter:%{QUERY_STRING}${SPLIT}%1}:${COOKIE_DOMAIN}:0:/:secure]
###################
### iterate slm_qstring cookie via python
###################
# update slm_qstring cookie when we have a qs, and a slm_qstring cookie exists
RewriteCond %{REQUEST_URI} (\/|\.html)$ [NC]
RewriteCond %{QUERY_STRING} !^$
RewriteCond %{HTTP_COOKIE} ${QUERYSTRING_COOKIE_NAME}=(.*?(;|$))
RewriteRule ^(.*) - [CO=${QUERYSTRING_COOKIE_NAME}:${qstring_rewriter:%{QUERY_STRING}${SPLIT}%1}:${COOKIE_DOMAIN}:0:/:secure]
Views
Replies
Total Likes
Hi,
Can you replicate this locally and then remove the directive you think is causing the conflict to confirm that it is the source of the issue?
Hope this helps.
@ramu_chinthala Did you find the suggestion helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.
Views
Replies
Total Likes
Views
Likes
Replies