Skip to content

Add Safe Browser enhancements and quiz security features - #877

Open
SayaliGangurde48 wants to merge 3 commits into
FOSSEE:masterfrom
SayaliGangurde48:safe-browser-feature
Open

Add Safe Browser enhancements and quiz security features#877
SayaliGangurde48 wants to merge 3 commits into
FOSSEE:masterfrom
SayaliGangurde48:safe-browser-feature

Conversation

@SayaliGangurde48

Copy link
Copy Markdown

Summary

This PR adds Safe Browser functionality for Yaksh quizzes to provide a more secure online examination environment.

Changes Made

  • Added Safe Browser mode configuration for quizzes.
  • Added Safe Browser settings form.
  • Added fullscreen enforcement.
  • Added camera and microphone permission support.
  • Added tab switching detection.
  • Added fullscreen exit detection.
  • Added browser shortcut restrictions for exam mode.
  • Updated quiz creation and editing flow.
  • Added required database migrations.

@prathamesh920 prathamesh920 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please resolve the comments.


Also,
A. Keep multiple questions in the quiz and do testing.
And with multiple attempts to students

B. Please check!

  1. Selecting full-screen mode exits automatically whenever the user moves to the next question.
    (So user has to every time click Enter full screen mode)
  2. Check if audio or camera permission is not given by the user,
    then it should not allow student to start the exam!
  3. On some violations it shows Time up and quits the quiz.
  4. Also, after the violations it shows the page quit exam Yes or No.
    If No is clicked then it starts the exam again with a new attempt.
    This should not be allowed from here.

C. Check the flow for Quiz taken by the moderator as a Student or Teacher,
from the moderator's add quiz interface, then safe browser mode is not activated.

D. Camera and audio output is available where?
Means as a teacher how can he/she see?

E. Try to break the system in all the possible way.
JS is acting like a shield here, and the backend django is serving as per the behavior submitted by JS. If user tricks JS, then the backend will not be aware. So, some mechanism,
were there is a dedicated communication between the JS and the backend. And a state should be maintained.
Also, we need to sure if in between the user attempts to violate or stop the camera or audio, it should be tracked.

F. We need to ensure that unit/integration tests are added.

<div class="card-body">

{% if questionpaper.quiz.is_expired %}
<div class="alert alert-error">

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So, these are formatting changes, and no code changes here or addition of code. There are various places this has happened so it makes the PR a bit heavy. I request to remove the formatting changes from this PR, there can be a separate PR for this later.
Wherever i can locate i will comment "formatting changes", can be undone.

<div class="container">
<div class="card">
<div class="card-header">
{{questionpaper.quiz.description}}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

formatting changes


{% if questionpaper.quiz.is_expired %}
<div class="alert alert-error">
This Quiz has expired. You can no longer attempt this Quiz.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

formatting changes
Below as well can be seen, kindly undo.

Comment thread yaksh/templates/yaksh/intro.html Outdated

<strong>
This is your Attempt {{ attempt_num }}
of {{ questionpaper.quiz.attempts_allowed }}.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If infinite attempts allowed then it will display "-1"
In this case it should show "infinite"


</script>

<script>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please make a separate JS file for this and include only when safe exam is selected.

Comment thread yaksh/models.py Outdated
for tc_id in order
]
except TestCaseOrder.DoesNotExist:
testcase_order = TestCaseOrder.objects.get(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why this change? It does the same thing.

Comment thread yaksh/models.py Outdated
for f in files:
zip_file.writestr(
os.path.join("additional_files", os.path.basename(f.file.name)),
os.path.join(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Below "formatting changes"

Comment thread yaksh/views.py Outdated
from stats.models import TrackLesson
from yaksh.forms import (
UserRegisterForm, UserLoginForm, QuizForm, QuestionForm,
UserRegisterForm, UserLoginForm, QuizForm,SafeBrowserForm,QuestionForm,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Put space after comma

Comment thread yaksh/views.py Outdated

return my_render_to_response(request, 'yaksh/course_detail.html', context)

import json

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Already imported in the file on the top.

Comment thread yaksh/views.py Outdated
return my_render_to_response(request, 'yaksh/course_detail.html', context)

import json
from django.views.decorators.http import require_POST

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please put this import at the top along with other django.views.decorators imports

Comment thread yaksh/models.py Outdated
ids = [
int(x)
for x in testcase_order.order.split(",")
if x.strip()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

if tc_id.strip() can be added to the existing code

Comment thread yaksh/static/yaksh/js/safe_browser.js Outdated
"use strict";

var violationCount = 0;
var MAX_VIOLATIONS = 3;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This shouldn't be a constant.

{% endif %}.
</strong>

{% if is_retry %}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is_retry = attempt_number > 1
So the message below will be displayed for normal attempts as well! (one without safe exam mode)

Comment thread yaksh/models.py

ids = [
int(tc_id)
for tc_id in testcase_order.order.split(",")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

testcase_order not defined!
I suggest remove this fix as it is fixed in a different PR with tests

Comment thread yaksh/views.py Outdated
else:
order = module.get_unit_order("quiz", quiz)

added_quiz = form.save(commit=False)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This will try to save invalid form as well!

Comment thread yaksh/views.py Outdated
@require_POST
@login_required
def report_violation(request):
data = json.loads(request.body)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What if no answer paper or missing fields in JSON.
Error handling needed.
Also below, AnswerPaper not found should be caught

Comment thread yaksh/views.py Outdated
paper.status = "completed"
paper.end_time = timezone.now()

print("SAFE BROWSER TERMINATED =", paper.terminated_by_safe_browser)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Remove print()

Comment thread yaksh/views.py Outdated

paper.save()

print(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Remove print()

Comment thread yaksh/views.py


@require_POST
@login_required

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Add @email_verified

Comment thread yaksh/views.py


@require_POST
@login_required

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Add @email_verified

@prathamesh920

Copy link
Copy Markdown
Contributor

Please test Camera permission denied then what happens.

I suggest you add tests for:

  • Creating/editing a quiz with safe-browser mode.
  • Invalid QuizForm and Invalid SafeBrowserForm does not save.
  • report_violation increments count/terminates at max_violations.
  • report_violation rejects non-safe-browser quizzes.
  • Safe-browser terminated attempt does not resume.
  • Normal in-progress attempt still resumes.

Then make the changes to your code.

Then do manual testing as well.

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