مراية لـ
https://github.com/postalserver/postal.git
تم المزامنة 2025-12-01 05:43:04 +00:00
refactor: switch to use SecureRandom for random strings
هذا الالتزام موجود في:
@@ -1,7 +1,5 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "nifty/utils/random_string"
|
|
||||||
|
|
||||||
module SMTPServer
|
module SMTPServer
|
||||||
class Client
|
class Client
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ module HasAuthentication
|
|||||||
end
|
end
|
||||||
|
|
||||||
def begin_password_reset(return_to = nil)
|
def begin_password_reset(return_to = nil)
|
||||||
self.password_reset_token = Nifty::Utils::RandomString.generate(length: 24)
|
self.password_reset_token = SecureRandom.alphanumeric(24)
|
||||||
self.password_reset_token_valid_until = 1.day.from_now
|
self.password_reset_token_valid_until = 1.day.from_now
|
||||||
save!
|
save!
|
||||||
AppMailer.password_reset(self, return_to).deliver
|
AppMailer.password_reset(self, return_to).deliver
|
||||||
|
|||||||
@@ -164,7 +164,7 @@ class Domain < ApplicationRecord
|
|||||||
return unless verification_method_changed?
|
return unless verification_method_changed?
|
||||||
|
|
||||||
if verification_method == "DNS"
|
if verification_method == "DNS"
|
||||||
self.verification_token = Nifty::Utils::RandomString.generate(length: 32)
|
self.verification_token = SecureRandom.alphanumeric(32)
|
||||||
elsif verification_method == "Email"
|
elsif verification_method == "Email"
|
||||||
self.verification_token = rand(999_999).to_s.ljust(6, "0")
|
self.verification_token = rand(999_999).to_s.ljust(6, "0")
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ class HTTPSender < BaseSender
|
|||||||
super()
|
super()
|
||||||
@endpoint = endpoint
|
@endpoint = endpoint
|
||||||
@options = options
|
@options = options
|
||||||
@log_id = Nifty::Utils::RandomString.generate(length: 8).upcase
|
@log_id = SecureRandom.alphanumeric(8).upcase
|
||||||
end
|
end
|
||||||
|
|
||||||
def send_message(message)
|
def send_message(message)
|
||||||
|
|||||||
@@ -327,7 +327,7 @@ module Postal
|
|||||||
time = Time.now.to_f - start_time
|
time = Time.now.to_f - start_time
|
||||||
logger.debug " \e[4;34mMessageDB Query (#{time.round(2)}s) \e[0m \e[33m#{query}\e[0m"
|
logger.debug " \e[4;34mMessageDB Query (#{time.round(2)}s) \e[0m \e[33m#{query}\e[0m"
|
||||||
if time > 0.05 && query =~ /\A(SELECT|UPDATE|DELETE) /
|
if time > 0.05 && query =~ /\A(SELECT|UPDATE|DELETE) /
|
||||||
id = Nifty::Utils::RandomString.generate(length: 6).upcase
|
id = SecureRandom.alphanumeric(8)
|
||||||
explain_result = ResultForExplainPrinter.new(connection.query("EXPLAIN #{query}"))
|
explain_result = ResultForExplainPrinter.new(connection.query("EXPLAIN #{query}"))
|
||||||
logger.info " [#{id}] EXPLAIN #{query}"
|
logger.info " [#{id}] EXPLAIN #{query}"
|
||||||
ActiveRecord::ConnectionAdapters::MySQL::ExplainPrettyPrinter.new.pp(explain_result, time).split("\n").each do |line|
|
ActiveRecord::ConnectionAdapters::MySQL::ExplainPrettyPrinter.new.pp(explain_result, time).split("\n").each do |line|
|
||||||
|
|||||||
@@ -488,7 +488,7 @@ module Postal
|
|||||||
#
|
#
|
||||||
def create_link(url)
|
def create_link(url)
|
||||||
hash = Digest::SHA1.hexdigest(url.to_s)
|
hash = Digest::SHA1.hexdigest(url.to_s)
|
||||||
token = Nifty::Utils::RandomString.generate(length: 8)
|
token = SecureRandom.alphanumeric(16)
|
||||||
database.insert(:links, { message_id: id, hash: hash, url: url, timestamp: Time.now.to_f, token: token })
|
database.insert(:links, { message_id: id, hash: hash, url: url, timestamp: Time.now.to_f, token: token })
|
||||||
token
|
token
|
||||||
end
|
end
|
||||||
@@ -585,7 +585,7 @@ module Postal
|
|||||||
def _create(queue: true)
|
def _create(queue: true)
|
||||||
self.timestamp = Time.now.to_f if timestamp.blank?
|
self.timestamp = Time.now.to_f if timestamp.blank?
|
||||||
self.status = "Pending" if status.blank?
|
self.status = "Pending" if status.blank?
|
||||||
self.token = Nifty::Utils::RandomString.generate(length: 12) if token.blank?
|
self.token = SecureRandom.alphanumeric(16) if token.blank?
|
||||||
last_id = @database.insert("messages", @attributes.except(:id))
|
last_id = @database.insert("messages", @attributes.except(:id))
|
||||||
@attributes["id"] = last_id
|
@attributes["id"] = last_id
|
||||||
@database.statistics.increment_all(timestamp, scope)
|
@database.statistics.increment_all(timestamp, scope)
|
||||||
|
|||||||
المرجع في مشكلة جديدة
حظر مستخدم