-
Notifications
You must be signed in to change notification settings - Fork 26
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
Add Altcha captcha to notifications submissions #661
Open
crutch
wants to merge
6
commits into
master
Choose a base branch
from
feature/643-gdpr-compliant-captcha
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9969722
Add Altcha captcha to notifications submissions
crutch 2ca50b0
Re-render the form on missing captcha
crutch d142a80
Handle newsletter subscriptions on the server side
crutch 752d4af
Make the altcha challenge a lot easier
crutch b3509b8
Fix structure.sql
crutch c104f7e
Fix structure.sql even more :)
crutch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AltchaController < ApplicationController | ||
def new | ||
render json: Altcha::Challenge.create.to_json | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class NewsletterSubscriptionsController < ApplicationController | ||
|
||
def subscribe | ||
email, altcha = subscription_params | ||
if AltchaSolution.verify_and_save(altcha) | ||
SubscribeToNewsletterJob.perform_later(email, 'NewsletterSubscription') | ||
respond_to do |format| | ||
format.js { render :success} | ||
end | ||
else | ||
respond_to do |format| | ||
format.js { render :altcha_failure, status: :unprocessable_entity} | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def subscription_params | ||
params.require([:email, :altcha]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
class AltchaSolution < ApplicationRecord | ||
validates :algorithm, :challenge, :salt, :signature, :number, presence: true | ||
attr_accessor :took | ||
|
||
def self.verify_and_save(base64encoded) | ||
p = JSON.parse(Base64.decode64(base64encoded)) rescue nil | ||
return false if p.nil? | ||
|
||
submission = Altcha::Submission.new(p) | ||
return false unless submission.valid? | ||
|
||
solution = self.new(p) | ||
|
||
begin | ||
return solution.save | ||
rescue ActiveRecord::RecordNotUnique | ||
# Replay attack | ||
return false | ||
end | ||
end | ||
|
||
def self.cleanup | ||
# Replay attacks are protected by the time stamp in the salt of the challenge for | ||
# the duration configured in the timeout. All solutions in the database that older | ||
# can be deleted. | ||
AltchaSolution.where('created_at < ?', Time.now - Altcha.timeout).delete_all | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<%= form_tag newsletter_subscribe_path, method: :post, remote: true, id: "newsletter-form" do |f| %> | ||
<%= email_field_tag :email, '', class: 'govuk-input sdn-footer__newsletter-input', placeholder: "Zadajte emailovú adresu", autocomplete: :email %> | ||
<%= submit_tag 'Prihlásiť', class: 'govuk-button sdn-footer__newsletter-button' %> | ||
<altcha-widget hidelogo hidefooter strings="<%= JSON.dump({ 'label': 'Nie som robot', 'verifying': 'Overujem...', 'verified': 'Overené'}) %>" challengeurl="<%= altcha_url() %>"></altcha-widget> | ||
<div class="newsletter-altcha-error"></div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
$('#newsletter-form').replaceWith('<%=j render partial: 'newsletter_subscriptions/form', object: @group %>'); | ||
$('.newsletter-altcha-error').html('Nie sme si isti, či nie ste robot... zaškrtli ste, že nie ste?'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
$('#newsletter-success').show(); | ||
if ($('#newsletter-warning').is(':visible')) { | ||
$('#newsletter-warning').hide(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
$('#new_subscription_notification_group').replaceWith('<%=j render partial: 'form', object: @group %>'); | ||
$('.altcha-error').html('Nie sme si isti, či nie ste robot... zaškrtli ste, že nie ste?'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
Altcha.setup do |config| | ||
config.algorithm = 'SHA-256' | ||
config.num_range = (50_000..51_000) | ||
config.timeout = 5.minutes | ||
config.hmac_key = 'dfa06d467a84fea13941f1c52c38c6458a67617a' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class CreateAltchaSolutions < ActiveRecord::Migration[6.1] | ||
def change | ||
create_table(:altcha_solutions) do |t| | ||
t.string :algorithm | ||
t.string :challenge | ||
t.string :salt | ||
t.string :signature | ||
t.integer :number | ||
|
||
t.timestamps | ||
end | ||
|
||
add_index :altcha_solutions, [ :algorithm, :challenge, :salt, :signature, :number ], unique: true, name: 'index_altcha_solutions' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you OK with including an externally hosted script here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pls @jsuchal daj tu vedieť. Podľa mňa áno.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ide to do ameriky, cize nie.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To je iba CDN, potom to neposiela veci mimo. Ale teda volajú to self-hosted a GDPR-compliant, čiže asi vieme pridať priamo do projektu, ak nechceme ani CDN https://github.com/altcha-org/altcha
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Vitaj vo svete GDPR. https://www.cookieyes.com/documentation/google-fonts-and-gdpr/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wow, okay