tina4ruby 3.13.165 → 3.13.166

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: 75d256f5003970e8333c3c9adcb526287d56b82d7e0d795d9c1327ca77df135b
4
- data.tar.gz: ad99e5788d6a47c04f0fa4ab69d314d5df232489aba9c06975d2514085721437
3
+ metadata.gz: d04d22eb673ab5a73c2d8768040ee336d6fa44de17487a562c8cb2505685ad72
4
+ data.tar.gz: 8702a864280bf6a8e695551a5de3b4c3f211991c7a00e584e57bb00ce835fb25
5
5
  SHA512:
6
- metadata.gz: 6453bf9fc5c540f9f6bc49e33b40a4b941fe24d7ddde44cae041391a89eae89831cf129a5efe75ecd2b8fc50464d4df1d17a0220173cada9213b0fd286d69ca1
7
- data.tar.gz: 5e9a0c74f459845b9248551d73658ffd18e5058065ced8c656c1976b913173cdc3d8879cefb5964bdc9c66b13d970b95de8ed7a7b16f7dc97a0159534f047629
6
+ metadata.gz: 2419a7e1eb7f052869ce8e89a6376b43b065abf27c9218c71904df2f8da7283df76978ccf542ef87d310fd8da6998bc3cd97d2e88200b4153a187d2124368bf7
7
+ data.tar.gz: a5e07b3b8eaca98cc838b4ba514b482ea5c4bfea0be2babb9565f004ba8fcbed3e9c0bdc21c13e897b437daf5aba059bbc89d51cbc27d63f06e4467cde11d1e3
data/CHANGELOG.md CHANGED
@@ -6,6 +6,21 @@ number means the same thing everywhere.
6
6
  **The authoritative release notes for every shipped version live in the documentation:**
7
7
  https://tina4.com/ruby/36-releases
8
8
 
9
+ ## 3.13.166 - 2026-11-24
10
+
11
+ ### Security
12
+
13
+ - Database URL redaction never prints the password (GHSA-h2mr-m3v3-cq8c, reported by Michael Smit). A password containing `/ ? # @ %` or a space, a URL with one slash or no colon after the scheme, a URL with no host, or a non-numeric port printed the password, or part of it, in startup logs, connection errors and exception messages, and `URI::InvalidURIError` (which quotes the URL) was kept as the raised error's `cause`. One rule now finds the password (userinfo ends at the last `@`), parsers refuse a malformed URL with a generic message and no cause, drivers are handed the userinfo percent-encoded, and a driver message that quotes part of the URL is scrubbed. Graph, the websocket backplanes, MQTT, AMQP, the Mongo session handler and the dev MCP `env_list` are covered. An unencoded `@` in a query is refused (encode it as `%40`); a value without `scheme://`, or a sqlite URL with a user:password, is refused (#192).
14
+ - A bare `any()` route keeps writes secure by default (ADR-0019). `Router.any` and group `any` registered one ANY route that was public for every method, so anonymous POST, PUT, PATCH and DELETE reached it where `Router.post` on the same path answers 401. Reads stay public; writes need a token unless the route says `.no_auth`. An app that relied on anonymous writes to a bare `any()` route must add `.no_auth` (#191; same in tina4-python#333).
15
+ - sqlite3 2.10.2 (CVE-2026-128084: sqlite3-ruby 2.10.1 and earlier truncated a SQL string or bound value of 4 GiB or more). The lockfile moves to 2.10.2, and `tina4ruby init` writes `gem "sqlite3", ">= 2.10.2"` (#189).
16
+
17
+ ### Fixed
18
+
19
+ - PostgreSQL: a password containing `/`, `@`, `%` or a space can connect. `URI#password=` refused it, so such a password never worked, even percent-encoded in the URL (#192).
20
+ - A failing seed file fails loud (ADR-0108). `seed_dir` logged a failing file, carried on and returned `nil`; it now stops at it and raises `Tina4::SeedError` naming the file, the files that ran before it and the cause, and returns the executed list. `tina4ruby seed` never ran a seed file at all (it died with `NoMethodError`); it now runs through `seed_dir` and exits 1 on a failure. Dev-admin's run-seeds uses the same runner (#186, #188).
21
+ - Windows: `Auth.setup` can write the RSA key pair, the generated development `TINA4_SECRET` reaches `.env.local`, and dev-admin can edit `.env` and show a project file. Ruby on Windows rejects `File::NONBLOCK`, which every one of those opens passed (#190).
22
+ - Windows: `tina4ruby doctor`, `setup` and `deploy` pass their arguments intact to a `tina4.cmd` client (#187).
23
+
9
24
  ## 3.13.165 - 2026-11-22
10
25
 
11
26
  ### Fixed
@@ -0,0 +1,156 @@
1
+ # frozen_string_literal: true
2
+ # Copyright (c) 2026 Code Infinity
3
+ # SPDX-License-Identifier: MPL-2.0
4
+ # This Source Code Form is subject to the terms of the Mozilla Public
5
+ # License, v. 2.0. If a copy of the MPL was not distributed with this
6
+ # file, You can obtain one at https://mozilla.org/MPL/2.0/.
7
+
8
+ module Tina4
9
+ # Run a program that may be a Windows batch file (`.cmd` / `.bat`).
10
+ #
11
+ # A batch file is always run by cmd.exe, which re-parses the command line.
12
+ # Ruby quotes array-form arguments for the C runtime, not for cmd.exe, so an
13
+ # argument holding `%PATH%` is expanded, `^` vanishes, and `x|y` runs `y` as
14
+ # a command (the BatBadBut class). The fix is the one tina4-python
15
+ # (core/batch_spawn.py) and tina4-nodejs (packages/core/src/batchSpawn.ts)
16
+ # use, after cross-spawn and https://qntm.org/cmd: build the cmd.exe line
17
+ # here, each argument quoted, embedded quotes and the backslashes before them
18
+ # escaped, and every cmd.exe metacharacter caret-escaped TWICE, once for the
19
+ # `cmd /c` line and once more because the batch file re-parses the `%*` it
20
+ # forwards.
21
+ #
22
+ # The Ruby-specific part is getting that line to CreateProcess unchanged.
23
+ # Ruby has no verbatim-arguments option: the array form re-quotes every
24
+ # argument, and the single-string form goes through `w32_spawn` in Ruby's
25
+ # win32/win32.c, which asks `has_redirection()` about the string. When that
26
+ # says no, the string reaches CreateProcess exactly as written. When it says
27
+ # yes, Ruby runs `%COMSPEC% /c "<string>"` instead. So we ask the same
28
+ # question first (#redirection? is a port of `has_redirection`) and hand Ruby
29
+ # whichever string comes out as exactly one cmd.exe layer over our line:
30
+ #
31
+ # * `"%COMSPEC%" /d /c <line>` when Ruby will pass it through untouched, or
32
+ # * `<line>` alone when Ruby will wrap it, because its `%COMSPEC% /c "<line>"`
33
+ # is then the one cmd.exe layer (cmd.exe strips the outer quotes, the same
34
+ # as `/s` does, since the line always holds more than two quotes).
35
+ #
36
+ # Anything that is not a batch file, and every non-Windows platform, is
37
+ # spawned exactly as before.
38
+ module BatchSpawn
39
+ # cmd.exe metacharacters, the same set cross-spawn, tina4-python and
40
+ # tina4-nodejs escape.
41
+ CMD_META = /([()\]\[%!^"`<>&|;, *?])/
42
+
43
+ module_function
44
+
45
+ # Native Windows Ruby (mswin / mingw), whose spawn goes through win32.c.
46
+ def windows?
47
+ RUBY_PLATFORM.match?(/mswin|mingw/)
48
+ end
49
+
50
+ # True when +path+ is a batch file that cmd.exe must run (Windows only).
51
+ def batch_file?(path, windows: windows?)
52
+ windows && path.to_s.match?(/\.(cmd|bat)\z/i)
53
+ end
54
+
55
+ # One argument, quoted and escaped for a batch file run by cmd.exe.
56
+ def escape_argument(arg)
57
+ quote_argument(arg.to_s).gsub(CMD_META, '^\1').gsub(CMD_META, '^\1')
58
+ end
59
+
60
+ # C-runtime quoting, in one linear pass (no backtracking regex): backslashes
61
+ # before a quote double and the quote is backslash-escaped; backslashes
62
+ # before the closing quote we add double too; any other backslash is kept.
63
+ def quote_argument(arg)
64
+ quoted = +'"'
65
+ backslashes = 0
66
+ arg.each_char do |char|
67
+ if char == "\\"
68
+ backslashes += 1
69
+ next
70
+ end
71
+ quoted << ("\\" * (char == '"' ? (backslashes * 2) + 1 : backslashes)) << char
72
+ backslashes = 0
73
+ end
74
+ quoted << ("\\" * backslashes * 2) << '"'
75
+ end
76
+
77
+ # The batch file and its escaped arguments, as one cmd.exe command line.
78
+ def command_line(path, args)
79
+ [path.to_s.gsub(CMD_META, '^\1'), *args.map { |arg| escape_argument(arg) }].join(" ")
80
+ end
81
+
82
+ # `Kernel#system(env, program, *args)`, except that a batch file on Windows
83
+ # runs through cmd.exe with every argument escaped. Same return value and
84
+ # `$?` as Kernel#system.
85
+ def system(env, program, *args, **options)
86
+ return Kernel.system(env, program, *args, **options) unless batch_file?(program)
87
+
88
+ comspec = ENV["COMSPEC"] || "cmd.exe"
89
+ # Pin the COMSPEC Ruby wraps with to the one we chose, and keep RUBYSHELL
90
+ # (which Ruby would use instead of cmd.exe) out of this one spawn.
91
+ Kernel.system(env.merge("COMSPEC" => comspec, "RUBYSHELL" => nil),
92
+ shell_string(program, args, comspec), **options)
93
+ end
94
+
95
+ # The single string to give Ruby's spawn so that CreateProcess receives
96
+ # exactly one cmd.exe layer over #command_line (see the module comment).
97
+ def shell_string(program, args, comspec)
98
+ line = command_line(program, args)
99
+ direct = %("#{comspec}" /d /c #{line})
100
+ return direct unless redirection?(direct)
101
+ return line if redirection?(line)
102
+
103
+ # Neither form survives Ruby's spawn intact (only possible with an
104
+ # unusual COMSPEC path). Refuse rather than run a mangled command line.
105
+ raise ArgumentError, "cannot pass these arguments to #{program} through cmd.exe intact"
106
+ end
107
+
108
+ # Port of `has_redirection()` from Ruby's win32/win32.c (the same logic in
109
+ # Ruby 3.1, 3.3 and 3.4; master only adds an end-of-string check that does
110
+ # not change the answer): true when Ruby's single-string spawn will run
111
+ # +cmd+ through `%COMSPEC% /c` rather than pass it to CreateProcess as is.
112
+ # Byte-wise like the C: a multibyte UTF-8 character never contains one of
113
+ # the ASCII bytes it looks for.
114
+ def redirection?(cmd)
115
+ bytes = cmd.b
116
+ quote = nil
117
+ i = 0
118
+ while i < bytes.bytesize
119
+ found, i, quote = redirection_step(bytes, i, quote)
120
+ return true if found
121
+ end
122
+ false
123
+ end
124
+
125
+ # One step of has_redirection() at byte +i+: [redirection found?, next
126
+ # index, quote state].
127
+ def redirection_step(bytes, i, quote)
128
+ char = bytes[i]
129
+ case char
130
+ when "'", '"' then [false, i + 1, toggle_quote(quote, char)]
131
+ when ">", "<", "|", "&", "\n" then [quote.nil?, i + 1, quote]
132
+ when "%" then [*environment_reference(bytes, i), quote]
133
+ when "\\" then [false, i + 2, quote]
134
+ else [false, i + 1, quote]
135
+ end
136
+ end
137
+
138
+ # A quote opens a quoted run, and only the same quote character closes it.
139
+ def toggle_quote(quote, char)
140
+ return char if quote.nil?
141
+
142
+ quote == char ? nil : quote
143
+ end
144
+
145
+ # `%NAME%` counts as redirection, quoted or not. +i+ is at the `%`; returns
146
+ # [found?, where the scan resumes], exactly where the C leaves its pointer.
147
+ def environment_reference(bytes, i)
148
+ j = i + 1
149
+ return [false, j] unless bytes[j]&.match?(/[A-Za-z_]/)
150
+
151
+ j += 1
152
+ j += 1 while bytes[j]&.match?(/\w/)
153
+ [bytes[j] == "%", j + 1]
154
+ end
155
+ end
156
+ end
data/lib/tina4/cli.rb CHANGED
@@ -15,6 +15,7 @@ require "tmpdir" # Dir.mktmpdir — used by the ADR-0063 sandbox edit-hint sc
15
15
  require "stringio" # StringIO — captures generator stdout during the sandbox run
16
16
  require "open3" # Open3.capture2e — captures `ruby -c` output+status for `lint`
17
17
  require_relative "port_takeover"
18
+ require_relative "batch_spawn" # Tina4::BatchSpawn - runs a tina4.cmd client with its arguments intact
18
19
  require_relative "env" # Tina4::Env.is_truthy -- resolve_config runs before lib/tina4 loads
19
20
 
20
21
  module Tina4
@@ -377,10 +378,12 @@ module Tina4
377
378
  return EXIT_CLIENT_UNAVAILABLE
378
379
  end
379
380
 
380
- # Array form => no shell, so no quoting/injection surface. stdio is
381
+ # No shell of our own, so no quoting/injection surface: the array form
382
+ # everywhere, except a tina4.cmd / tina4.bat on Windows, which cmd.exe
383
+ # always runs and BatchSpawn escapes every argument for. stdio is
381
384
  # inherited, so the client's interactive prompts (setup) and colour output
382
385
  # work exactly as if it had been invoked directly.
383
- system({ DELEGATION_GUARD_ENV => command }, client, command, *args)
386
+ BatchSpawn.system({ DELEGATION_GUARD_ENV => command }, client, command, *args)
384
387
  $?&.exitstatus || EXIT_CLIENT_UNAVAILABLE
385
388
  end
386
389
 
@@ -1090,7 +1093,20 @@ module Tina4
1090
1093
  require_relative "../tina4"
1091
1094
  Tina4.initialize!(Dir.pwd)
1092
1095
  load_routes(Dir.pwd)
1093
- Tina4.seed_dir(seed_folder: "seeds", clear: options[:clear])
1096
+ # seeder.rb is autoloaded only through Tina4::FakeData, so Tina4.seed_dir
1097
+ # does not exist until it is loaded: without this line `tina4ruby seed`
1098
+ # died with NoMethodError before running a single seed file.
1099
+ require_relative "seeder"
1100
+ # ADR-0108: the first seed file that raises stops the run and exits 1,
1101
+ # so a failed seeder fails `tina4 seed` (the client propagates the code).
1102
+ begin
1103
+ executed = Tina4.seed_dir(seed_folder: "seeds", clear: options[:clear])
1104
+ rescue Tina4::SeedError => e
1105
+ e.completed.each { |path| puts " Seeded: #{File.basename(path)}" }
1106
+ warn " #{e.message}"
1107
+ exit 1
1108
+ end
1109
+ executed.each { |path| puts " Seeded: #{File.basename(path)}" }
1094
1110
  end
1095
1111
 
1096
1112
  # ── seed:create ───────────────────────────────────────────────────────
@@ -4182,7 +4198,7 @@ module Tina4
4182
4198
 
4183
4199
  # SQLite driver for the default database (TINA4_DATABASE_URL=sqlite:...).
4184
4200
  # tina4ruby loads it lazily; it is an app dependency, like pg or mysql2.
4185
- gem "sqlite3"
4201
+ gem "sqlite3", ">= 2.10.2"
4186
4202
  RUBY
4187
4203
  end
4188
4204
 
@@ -503,7 +503,7 @@ module Tina4
503
503
  @pool = ConnectionPool.new(
504
504
  @pool_size,
505
505
  driver_factory: method(:create_driver),
506
- connection_string: @connection_string,
506
+ connection_string: driver_connection_string,
507
507
  username: @username,
508
508
  password: @password
509
509
  )
@@ -518,7 +518,7 @@ module Tina4
518
518
  end
519
519
 
520
520
  def connect
521
- @driver.connect(@connection_string, username: @username, password: @password)
521
+ @driver.connect(driver_connection_string, username: @username, password: @password)
522
522
  @connected = true
523
523
 
524
524
  # Push the resolved autocommit setting down to the driver when it exposes a
@@ -592,14 +592,40 @@ module Tina4
592
592
  # a scheme-less value whole as the host it could not resolve -
593
593
  # could not translate host name "postgres//u:pass@h/app" to address
594
594
  # - password included.
595
+ #
596
+ # GHSA-h2mr-m3v3-cq8c: a driver can also quote a PART of the value (libpq
597
+ # splits a conninfo on whitespace; the mongo gem quotes "the database name"
598
+ # after a "/"), which a whole-string replace never finds, and it is handed
599
+ # the percent-encoded #driver_connection_string, not the raw value. Both
600
+ # forms, and the password itself, go through the shared primitive.
595
601
  def scrub_connection_string(text)
596
602
  raw = @connection_string.to_s
597
603
  return text.to_s if raw.empty?
598
604
 
599
- text.to_s.gsub(raw) { Tina4::DatabaseUrl.redact(raw) }
605
+ replacement = Tina4::DatabaseUrl.redact(raw)
606
+ out = Tina4::DatabaseUrl.scrub_message(text, raw, replacement)
607
+ driver_url = driver_connection_string
608
+ driver_url == raw ? out : Tina4::DatabaseUrl.scrub_message(out, driver_url, replacement)
600
609
  end
601
610
  private :scrub_connection_string
602
611
 
612
+ # The value a DRIVER is handed: the configured one with its userinfo
613
+ # percent-encoded (GHSA-h2mr-m3v3-cq8c). Drivers re-parse the URL
614
+ # themselves, and libpq, the mongo gem and URI.parse all cut a userinfo at
615
+ # the first "/" or "@" - so `postgres://u:a/b@h/db`, which the framework
616
+ # parses as password "a/b", reached the driver as host "u", port "a" and
617
+ # came back in its error message. Unchanged when nothing needs encoding.
618
+ def driver_connection_string
619
+ Tina4::DatabaseUrl.driver_url(@connection_string)
620
+ end
621
+ private :driver_connection_string
622
+
623
+ # inspect lands in consoles, backtraces and error pages. The default one
624
+ # dumps @connection_string and @password.
625
+ def inspect
626
+ "#<Tina4::Database #{@driver_name} #{safe_connection_target}>"
627
+ end
628
+
603
629
  # The connection string with any password stripped, so a raised error can name
604
630
  # the target without leaking a credential into a log or an HTTP 500 body.
605
631
  #
@@ -1988,6 +2014,8 @@ module Tina4
1988
2014
  drv.respond_to?(name)
1989
2015
  end
1990
2016
 
2017
+ SCHEME_TYPO = %r{\A(?:#{Tina4::DatabaseUrl::ENGINE_ALIASES.keys.map { |k| Regexp.escape(k) }.join("|")})//}i.freeze
2018
+
1991
2019
  def detect_driver(conn)
1992
2020
  # A real URL is decided by its SCHEME, through DatabaseUrl, which resolves
1993
2021
  # aliases once and RAISES on a scheme it does not know.
@@ -1999,8 +2027,13 @@ module Tina4
1999
2027
  # and nobody learns the real database was never reached. It also matched
2000
2028
  # on substrings, so a postgres database named "mysqldata" could be
2001
2029
  # detected as MySQL.
2030
+ #
2031
+ # A known scheme followed by "//" (the ":" lost, `postgres//u:pw@h/db`)
2032
+ # is a URL typo, not a bare path: the parser refuses it, generically.
2033
+ # Before GHSA-h2mr-m3v3-cq8c it fell through to the substring match and
2034
+ # the raw value went to the driver, whose error quoted part of it.
2002
2035
  text = conn.to_s
2003
- if text.match?(/\A[a-zA-Z][a-zA-Z0-9+.-]*:/)
2036
+ if text.match?(/\A[a-zA-Z][a-zA-Z0-9+.-]*:/) || text.match?(SCHEME_TYPO)
2004
2037
  return Tina4::DatabaseUrl.new(text).engine
2005
2038
  end
2006
2039