dmarcator 0.4.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3d8d5d903f5d6ec715a2cd5042610d7f28f730981f460baceee5abbc4d6eb916
4
- data.tar.gz: d6ebe47854a74d046cf47b720ce60cc0598c83d5b529ed665951d45012a504fc
3
+ metadata.gz: bf9c3559d1b305ece3b68de7e2e0eb72f1371be508b7499ce34160e543cbd6a1
4
+ data.tar.gz: f082d761778abd9e66e8bed82cee7a3aafc498567814021120a5780dc9c5f5fc
5
5
  SHA512:
6
- metadata.gz: b7ea01f6b847ccbb11bb6e4e1ead4c972a0c12e404631c462a8d4b249ca7622c7345b17bfbfd1651807fdd3ce269fdb6a0774ee9c8cb9e2d85cec6e7e55d871d
7
- data.tar.gz: 702597e80f58d060b1a0c6ef334697fa008ba9e0fad70d1096c6b71933901edf68643aa7234195507a12c2011624d5402cb6bc9fb1c7bbbbcb55e7bc914128a6
6
+ metadata.gz: 85da1dd8330918fb7ae6c167a9c08b23c97589f5fb3d8586c7866e64d19cd9bdf04a39efdfa161be70c01ef276cadc3b907e04b35df3ed10f9c32ffd28eb2be8
7
+ data.tar.gz: 4ed5b91fa75ba6eda666357a1541e27b11d008c5ec952f9573cf3a89243877a9757d09b6ae7d0488bb449b6c6dc798ed594d9ab75de1d911490e86bcda82a041
data/ChangeLog.md CHANGED
@@ -1,3 +1,9 @@
1
+ ### 0.4.2 / 2026-10-28
2
+
3
+ * Do not raise when the loaded `resolv` version is not a valid gem version; an unparseable version is treated as unknown instead of failing at load time.
4
+ * Reject DMARC records larger than 4 KiB (`Parser::MAX_RECORD_BYTES`) before parsing to bound work on hostile input.
5
+ * Raise the documented `InvalidRecord`/`InvalidReport` for non-String input instead of `ArgumentError`, `TypeError`, or a silently empty report.
6
+
1
7
  ### 0.4.1 / 2026-10-28
2
8
 
3
9
  * Accept a case-insensitive `mailto:` scheme in `rua`/`ruf` report URIs.
@@ -14,6 +14,11 @@ module DMARCator
14
14
  #
15
15
  class Parser < Parslet::Parser
16
16
 
17
+ # Maximum accepted DMARC record size in bytes. Real records are far
18
+ # smaller; the cap bounds parsing work on hostile input.
19
+ #
20
+ MAX_RECORD_BYTES = 4096
21
+
17
22
  root :dmarc_record
18
23
 
19
24
  rule(:dmarc_record) do
@@ -194,10 +199,18 @@ module DMARCator
194
199
  # The Hash of tags within the record.
195
200
  #
196
201
  # @raise [InvalidRecord]
197
- # The record is malformed, or (in strict mode) contains an unknown tag
198
- # or invalid tag value.
202
+ # The record is not a String, is malformed, is too large, or (in strict
203
+ # mode) contains an unknown tag or invalid tag value.
199
204
  #
200
205
  def self.parse(record, strict: false)
206
+ unless record.is_a?(String)
207
+ raise InvalidRecord, "DMARC record must be a String, got #{record.class}"
208
+ end
209
+
210
+ if record.bytesize > MAX_RECORD_BYTES
211
+ raise InvalidRecord, "DMARC record exceeds maximum size of #{MAX_RECORD_BYTES} bytes"
212
+ end
213
+
201
214
  tree = new.parse(record)
202
215
 
203
216
  if strict
@@ -40,8 +40,15 @@ module DMARCator
40
40
  version = resolv_version
41
41
  return false unless version
42
42
 
43
+ begin
44
+ parsed = Gem::Version.new(version)
45
+ rescue ArgumentError
46
+ # A non-semver version string means we cannot tell; do not warn.
47
+ return false
48
+ end
49
+
43
50
  VULNERABLE_RESOLV.any? do |requirement|
44
- requirement.satisfied_by?(Gem::Version.new(version))
51
+ requirement.satisfied_by?(parsed)
45
52
  end
46
53
  end
47
54
 
@@ -29,10 +29,18 @@ module DMARCator
29
29
  # @param [String] xml
30
30
  # The raw DMARC XML report.
31
31
  #
32
+ # @raise [InvalidReport]
33
+ # The report is not a String, exceeds {MAX_REPORT_BYTES}, or is not
34
+ # well-formed XML.
35
+ #
32
36
  def initialize(xml)
37
+ unless xml.is_a?(String)
38
+ raise InvalidReport, "DMARC XML report must be a String, got #{xml.class}"
39
+ end
40
+
33
41
  @xml = xml
34
42
 
35
- if xml.is_a?(String) && xml.bytesize > MAX_REPORT_BYTES
43
+ if xml.bytesize > MAX_REPORT_BYTES
36
44
  raise InvalidReport, "DMARC XML report exceeds maximum size of #{MAX_REPORT_BYTES} bytes"
37
45
  end
38
46
 
@@ -2,5 +2,5 @@
2
2
 
3
3
  module DMARCator
4
4
  # dmarcator version
5
- VERSION = '0.4.1'
5
+ VERSION = '0.4.2'
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dmarcator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Noah Berman