Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/add initial backend view and url route DO NOT MERGE #3421

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

JamesPRobinson
Copy link
Contributor

Description of change

Rough outline of how we could use the accepted/dimissed cookie. We could call the backend with js* or turn the survey into a django form.

  • e.g.
<link id="accepted" onclick="closeBanner(true)">
<link id="dismissed" onclick="closeBanner(false)">

<script>
const closeBanner = function(hasAccepted) {
const status = "accepted" ? hasAccepted : "dismissed"; 
post("set-notification-cookie", args={status=status, campaign="survey"}) // etc etc
}
</script>

@JamesPRobinson JamesPRobinson changed the title fix/add initial backend view and url route fix/add initial backend view and url route DO NOT MERGE Jan 21, 2025
response = JsonResponse({"message": f"campaign {id_campaign} expired"})
else:
action = request.POST.get("action")
response.set_cookie(f"{id_campaign}_{action}", "true", expires=date_expiry)

Check warning

Code scanning / CodeQL

Failure to use secure cookies Medium

Cookie is added without the Secure and HttpOnly attributes properly set.
response = JsonResponse({"message": f"campaign {id_campaign} expired"})
else:
action = request.POST.get("action")
response.set_cookie(f"{id_campaign}_{action}", "true", expires=date_expiry)

Check warning

Code scanning / CodeQL

Construction of a cookie using user-supplied input Medium

Cookie is constructed from a
user-supplied input
.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would have some checks here to make sure they fall within a range of accepted values

@@ -174,9 +174,31 @@ def _get_tags_as_dict():
return tags_dict


def show_survey_banner(request):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately would need to delete this code after survey expiry is over



class SetNotificationCookie(View):
def post(self, request, *args, **kwargs):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've tried to make this generic but maybe would need to hardcode to survey campaign to avoid the security issues flagged below

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you then set a base class and extend from it? Or perhaps a util function can be used here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants