Skip to content
This repository was archived by the owner on May 7, 2021. It is now read-only.

Conversation

@ngosset
Copy link
Contributor

@ngosset ngosset commented Mar 13, 2020

We currently have a counter of about 1 hour between requests. Only after the hour has passed do we redirect a person from CAFC.

This is a problem because we reset the counter every time the web application is visited. An Internal mechanism from Azure seems to be "visiting" our site every 5 minutes and resetting the counter. This doesn't show up in our App Service HTTPLogs so it must be an internal mechanism.

Because of this we are effectively not taking any redirects.

This PR adds a check for the referrer to verify the traffic is coming from CAFC before incrementing the counter.

How to test:

To test:

Step 1:

Add a fake DNS entry to your hosts. This makes it so a url points to the web server on YOUR computer.

On Mac OS: edit the file /private/etc/hosts

And add the following entry:

127.0.0.1 centreantifraude.ca

Step 2:

Flush your DNS cache

sudo killall -HUP mDNSResponder 

Step 3: Create a static page with a link to the app:

<html>
<head>
</head>
<body>

<a href='http://localhost:3000'>Click me</a>
</body>
</html>

Step 4:

Start a web server on your local machine that serves the static page

Example:

docker run --name nginx -p 80:80 -v /Users/normangosset/projects/fakesite:/usr/share/nginx/html:ro -d nginx

Step 5:

Make sure you are running server.js locally on port 3000

Navigate to http://localhost:80 and click "click me". You should see the following in the console:

Referrer:http://localhost/
New Request. {"numberOfSubmissions":0,"numberOfRequests":0}

Navigate to http://centreantifraude.ca:80 and click :"click me". You should see the following in console:

Referrer:http://centreantifraude.ca/
New Request. {"numberOfSubmissions":0,"numberOfRequests":1,"lastRequested":"2020-03-13T12:25:16.993Z"}

@sastels sastels temporarily deployed to rac-prototyp-emerg-fix-gw1f3b8 March 13, 2020 11:56 Inactive
@ngosset ngosset changed the base branch from master to release-rcmp-prod March 13, 2020 11:57
@sastels sastels temporarily deployed to rac-prototyp-emerg-fix-gw1f3b8 March 13, 2020 12:28 Inactive
@ngosset ngosset changed the title Emergency Fix - Don't count non-CAFC referrals (WIP) Emergency Fix - Don't count non-CAFC referrals Mar 13, 2020
} else {
availableData.numberOfRequests += 1
availableData.lastRequested = new Date()
var referrer = req.headers.referer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be req.headers.referrer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably, but it works??

https://en.wikipedia.org/wiki/HTTP_referer

"The HTTP referer (a misspelling of referrer[1]) is an optional HTTP header field that identifies the address of the webpage (i.e. the URI or IRI) which is linked to the resource being requested. By checking the referrer, the new webpage can see where the request originated."

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for #@%@#$ sake.

Copy link
Contributor

@sastels sastels left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tested locally as described. 👍

Copy link
Contributor

@davidheerema davidheerema left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reproduced the test environment by building a docker image from this branch, and running it (along with the nginx container for testing). and I received the expected test results:

docker image build -t rac:1.0 .
Maryses-MacBook-Air:f2 david$ docker container run --publish 3000:3000 --env-file ./.env.example --name deef rac:1.0
Availability configured
Self harm word list: agile,lean,mvp,scrum
Warning: CosmosDB not configured. Data will not be saved to CosmosDB database. Please set the environment variables COSMOSDB_NAME and COSMOSDB_KEY
WARNING: File storage not configured
WARNING: Azure content moderator not configured
WARNING: Notify environment variable NOTIFY_API_BASE_URL is missing. Emailing links will probably not work.
WARNING: Notify environment variable NOTIFY_CONFIRMATION_TEMPLATE_ID is missing. Emailing links will probably not work.
Notify client NOT created
Listening at port 3000
Referrer:http://localhost/
New Request. {"numberOfSubmissions":0,"numberOfRequests":0}
Referrer:http://centreantifraude.ca/
New Request. {"numberOfSubmissions":0,"numberOfRequests":1,"lastRequested":"2020-03-13T14:21:18.565Z"}
Referrer:http://centreantifraude.ca/
New Request. {"numberOfSubmissions":0,"numberOfRequests":2,"lastRequested":"2020-03-13T14:21:48.796Z"}
Referrer:http://localhost/
New Request. {"numberOfSubmissions":0,"numberOfRequests":2,"lastRequested":"2020-03-13T14:21:48.796Z"}
Referrer:http://localhost/
New Request. {"numberOfSubmissions":0,"numberOfRequests":2,"lastRequested":"2020-03-13T14:21:48.796Z"}

@ngosset ngosset merged commit 6068b03 into release-rcmp-prod Mar 13, 2020
@ngosset ngosset deleted the emerg-fix-2 branch March 13, 2020 14:32
@khalidelaggan
Copy link
Contributor

Looks great!

davidheerema added a commit that referenced this pull request Mar 27, 2020
* FIX CORS for HTTPS (#1665)

Yesterday CAFC moved to HTTPS, this broke our allowed origins.

* Emergency Fix - Don't count non-CAFC referrals (#1672)

* Only count referrers from CAFC

* Fixed typo

* Referrer urls are less predictable than origin? Just look at the host portion

* temporarily enable request debugging (#1673)

Co-authored-by: ngosset <[email protected]>
Co-authored-by: dhcdn <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants