Skip to content

Commit b784c3d

Browse files
author
Codex
committed
fix: security, config, and validation blockers for runtime release
- Bootstrap multibase without sending the API key across redirects. - Cross-origin redirect validation and database selector detection. - Odoo session cookie domain/path/secure check before using it. - .env parsed with interpolate=false to keep ${...} literal. - Transient bootstrap failures are retried (do not mark permanent failure). - 16 unit tests for database bootstrap, session cookie, and dotenv safety. - CI workflow compiles, runs unit tests, smoke checks, and validates installer URLs. - Full LGPL-3.0-or-later license text. - Public installer URLs corrected from nicolasramos-es to nicolasramos. - Release checklist with mandatory E2E evidence per platform and integration. - Compatibility and configuration docs updated with support status.
1 parent 3286f69 commit b784c3d

8 files changed

Lines changed: 650 additions & 30 deletions

File tree

.github/workflows/quality.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,18 @@ jobs:
1313
with:
1414
python-version: '3.11'
1515
- name: Install dependencies
16-
run: python3 -m pip install -r requirements.txt
16+
run: |
17+
python3 -m pip install --upgrade pip
18+
python3 -m pip install -r requirements.txt
1719
- name: Compile runtime
1820
run: python3 -m py_compile daemon.py scripts/smoke.py
21+
- name: Run runtime unit tests
22+
run: python3 -m unittest tests.test_daemon
1923
- name: Run smoke checks
2024
run: python3 scripts/smoke.py
2125
- name: Check shell installer syntax
2226
run: bash -n install.sh
27+
- name: Check repository text and release URLs
28+
run: |
29+
! grep -RIn --exclude-dir=.git 'raw\.githubusercontent\.com/nicolasramos[-]es/odoo-agent-runtime' README.md docs install.sh install.ps1 .github LICENSE
30+
test -s LICENSE

LICENSE

Lines changed: 163 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,165 @@
1-
GNU LESSER GENERAL PUBLIC LICENSE
2-
Version 3, 29 June 2007
1+
GNU LESSER GENERAL PUBLIC LICENSE
2+
Version 3, 29 June 2007
33

4-
This project is licensed under the GNU Lesser General Public License version 3.
4+
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
5+
Everyone is permitted to copy and distribute verbatim copies
6+
of this license document, but changing it is not allowed.
57

6-
See https://www.gnu.org/licenses/lgpl-3.0.en.html for the full license text.
8+
9+
This version of the GNU Lesser General Public License incorporates
10+
the terms and conditions of version 3 of the GNU General Public
11+
License, supplemented by the additional permissions listed below.
12+
13+
0. Additional Definitions.
14+
15+
As used herein, "this License" refers to version 3 of the GNU Lesser
16+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
17+
General Public License.
18+
19+
"The Library" refers to a covered work governed by this License,
20+
other than an Application or a Combined Work as defined below.
21+
22+
An "Application" is any work that makes use of an interface provided
23+
by the Library, but which is not otherwise based on the Library.
24+
Defining a subclass of a class defined by the Library is deemed a mode
25+
of using an interface provided by the Library.
26+
27+
A "Combined Work" is a work produced by combining or linking an
28+
Application with the Library. The particular version of the Library
29+
with which the Combined Work was made is also called the "Linked
30+
Version".
31+
32+
The "Minimal Corresponding Source" for a Combined Work means the
33+
Corresponding Source for the Combined Work, excluding any source code
34+
for portions of the Combined Work that, considered in isolation, are
35+
based on the Application, and not on the Linked Version.
36+
37+
The "Corresponding Application Code" for a Combined Work means the
38+
object code and/or source code for the Application, including any data
39+
and utility programs needed for reproducing the Combined Work from the
40+
Application, but excluding the System Libraries of the Combined Work.
41+
42+
1. Exception to Section 3 of the GNU GPL.
43+
44+
You may convey a covered work under sections 3 and 4 of this License
45+
without being bound by section 3 of the GNU GPL.
46+
47+
2. Conveying Modified Versions.
48+
49+
If you modify a copy of the Library, and, in your modifications, a
50+
facility refers to a function or data to be supplied by an Application
51+
that uses the facility (other than as an argument passed when the
52+
facility is invoked), then you may convey a copy of the modified
53+
version:
54+
55+
a) under this License, provided that you make a good faith effort to
56+
ensure that, in the event an Application does not supply the
57+
function or data, the facility still operates, and performs
58+
whatever part of its purpose remains meaningful, or
59+
60+
b) under the GNU GPL, with none of the additional permissions of
61+
this License applicable to that copy.
62+
63+
3. Object Code Incorporating Material from Library Header Files.
64+
65+
The object code form of an Application may incorporate material from
66+
a header file that is part of the Library. You may convey such object
67+
code under terms of your choice, provided that, if the incorporated
68+
material is not limited to numerical parameters, data structure
69+
layouts and accessors, or small macros, inline functions and templates
70+
(ten or fewer lines in length), you do both of the following:
71+
72+
a) Give prominent notice with each copy of the object code that the
73+
Library is used in it and that the Library and its use are
74+
covered by this License.
75+
76+
b) Accompany the object code with a copy of the GNU GPL and this license
77+
document.
78+
79+
4. Combined Works.
80+
81+
You may convey a Combined Work under terms of your choice that,
82+
taken together, effectively do not restrict modification of the
83+
portions of the Library contained in the Combined Work and reverse
84+
engineering for debugging such modifications, if you also do each of
85+
the following:
86+
87+
a) Give prominent notice with each copy of the Combined Work that
88+
the Library is used in it and that the Library and its use are
89+
covered by this License.
90+
91+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
92+
document.
93+
94+
c) For a Combined Work that displays copyright notices during
95+
execution, include the copyright notice for the Library among
96+
these notices, as well as a reference directing the user to the
97+
copies of the GNU GPL and this license document.
98+
99+
d) Do one of the following:
100+
101+
0) Convey the Minimal Corresponding Source under the terms of this
102+
License, and the Corresponding Application Code in a form
103+
suitable for, and under terms that permit, the user to
104+
recombine or relink the Application with a modified version of
105+
the Linked Version to produce a modified Combined Work, in the
106+
manner specified by section 6 of the GNU GPL for conveying
107+
Corresponding Source.
108+
109+
1) Use a suitable shared library mechanism for linking with the
110+
Library. A suitable mechanism is one that (a) uses at run time
111+
a copy of the Library already present on the user's computer
112+
system, and (b) will operate properly with a modified version
113+
of the Library that is interface-compatible with the Linked
114+
Version.
115+
116+
e) Provide Installation Information, but only if you would otherwise
117+
be required to provide such information under section 6 of the
118+
GNU GPL, and only to the extent that such information is
119+
necessary to install and execute a modified version of the
120+
Combined Work produced by recombining or relinking the
121+
Application with a modified version of the Linked Version. (If
122+
you use option 4d0, the Installation Information must accompany
123+
the Minimal Corresponding Source and Corresponding Application
124+
Code. If you use option 4d1, you must provide the Installation
125+
Information in the manner specified by section 6 of the GNU GPL
126+
for conveying Corresponding Source.)
127+
128+
5. Combined Libraries.
129+
130+
You may place library facilities that are a work based on the
131+
Library side by side in a single library together with other library
132+
facilities that are not Applications and are not covered by this
133+
License, and convey such a combined library under terms of your
134+
choice, if you do both of the following:
135+
136+
a) Accompany the combined library with a copy of the same work based
137+
on the Library, uncombined with any other library facilities,
138+
conveyed under the terms of this License.
139+
140+
b) Give prominent notice with the combined library that part of it
141+
is a work based on the Library, and explaining where to find the
142+
accompanying uncombined form of the same work.
143+
144+
6. Revised Versions of the GNU Lesser General Public License.
145+
146+
The Free Software Foundation may publish revised and/or new versions
147+
of the GNU Lesser General Public License from time to time. Such new
148+
versions will be similar in spirit to the present version, but may
149+
differ in detail to address new problems or concerns.
150+
151+
Each version is given a distinguishing version number. If the
152+
Library as you received it specifies that a certain numbered version
153+
of the GNU Lesser General Public License "or any later version"
154+
applies to it, you have the option of following the terms and
155+
conditions either of that published version or of any later version
156+
published by the Free Software Foundation. If the Library as you
157+
received it does not specify a version number of the GNU Lesser
158+
General Public License, you may choose any version of the GNU Lesser
159+
General Public License ever published by the Free Software Foundation.
160+
161+
If the Library as you received it specifies that a proxy can decide
162+
whether future versions of the GNU Lesser General Public License shall
163+
apply, that proxy's public statement of acceptance of any version is
164+
permanent authorization for you to choose that version for the
165+
Library.

daemon.py

Lines changed: 112 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030

3131
DEFAULT_TIMEOUT_SECONDS = 600
32+
ODOO_SESSION_COOKIE = 'session_id'
3233

3334

3435
def get_hostname():
@@ -67,10 +68,74 @@ def __init__(self, odoo_url, api_key, name, poll_interval=10, max_concurrent=3,
6768
'X-API-Key': api_key,
6869
'Content-Type': 'application/json',
6970
})
71+
# Bootstrap is deliberately isolated from API authentication. It may
72+
# follow redirects, so it must never share API headers with API calls.
73+
self.bootstrap_session = requests.Session()
74+
self.bootstrap_session.headers.clear()
7075

7176
def _api_url(self, path):
7277
return f'{self.odoo_url}{path}'
7378

79+
def _has_odoo_origin(self, url):
80+
"""Return whether *url* has the configured Odoo origin."""
81+
if not isinstance(url, str):
82+
return False
83+
try:
84+
configured = urlparse(self.odoo_url)
85+
candidate = urlparse(url)
86+
configured_port = configured.port or (443 if configured.scheme == 'https' else 80)
87+
candidate_port = candidate.port or (443 if candidate.scheme == 'https' else 80)
88+
except ValueError:
89+
return False
90+
return (
91+
bool(configured.scheme and configured.hostname and candidate.scheme and candidate.hostname)
92+
and candidate.scheme.lower() == configured.scheme.lower()
93+
and candidate.hostname.lower() == configured.hostname.lower()
94+
and candidate_port == configured_port
95+
)
96+
97+
def _bootstrap_validation_failed(self, message, *args):
98+
"""Record a non-retryable database bootstrap validation failure."""
99+
self._database_bootstrap_failed = True
100+
logger.error(message, *args)
101+
return False
102+
103+
def _bootstrap_session_cookies(self, response):
104+
"""Yield Odoo session cookies collected during database bootstrap."""
105+
for cookies in (self.bootstrap_session.cookies, getattr(response, 'cookies', None)):
106+
if cookies is None:
107+
continue
108+
try:
109+
for cookie in cookies:
110+
if cookie.name == ODOO_SESSION_COOKIE and cookie.value:
111+
yield cookie
112+
except TypeError:
113+
continue
114+
115+
def _session_cookie_applies_to_api_url(self, cookie):
116+
"""Return whether a session cookie will be sent to the runtime API URL."""
117+
api_url = urlparse(self._api_url('/api/agent/runtime/heartbeat'))
118+
host = api_url.hostname
119+
if not host:
120+
return False
121+
122+
cookie_domain = (getattr(cookie, 'domain', '') or '').lstrip('.').lower()
123+
cookie_path = getattr(cookie, 'path', '/') or '/'
124+
if not cookie_domain:
125+
return False
126+
if getattr(cookie, 'domain_specified', False):
127+
matches_host = host.lower() == cookie_domain or host.lower().endswith(f'.{cookie_domain}')
128+
else:
129+
matches_host = host.lower() == cookie_domain
130+
if not matches_host:
131+
return False
132+
if not api_url.path.startswith(cookie_path):
133+
return False
134+
if not cookie_path.endswith('/') and len(api_url.path) > len(cookie_path):
135+
if api_url.path[len(cookie_path)] != '/':
136+
return False
137+
return not getattr(cookie, 'secure', False) or api_url.scheme.lower() == 'https'
138+
74139
def _bootstrap_database_session(self):
75140
"""Select the configured Odoo database and retain its session cookie."""
76141
if self._database_bootstrapped:
@@ -79,31 +144,61 @@ def _bootstrap_database_session(self):
79144
return False
80145

81146
login_url = f'{self.odoo_url}/web/login?{urlencode({"db": self.database})}'
147+
# Defensive even if this object is reused unexpectedly: bootstrap must
148+
# never carry an API key across its redirect chain.
149+
for header in list(self.bootstrap_session.headers):
150+
if header.lower() == 'x-api-key':
151+
del self.bootstrap_session.headers[header]
82152
try:
83-
response = self.session.get(login_url, allow_redirects=True, timeout=30)
153+
response = self.bootstrap_session.get(login_url, allow_redirects=True, timeout=30)
84154
response.raise_for_status()
85155
except requests.exceptions.RequestException as exc:
86-
self._database_bootstrap_failed = True
87156
logger.error(
88157
'Database bootstrap failed for ODOO_DATABASE=%r: %s. '
89-
'Runtime API calls were not attempted.',
158+
'Runtime API calls were not attempted; the runtime can retry.',
90159
self.database,
91160
exc,
92161
)
93162
return False
94163

95164
final_url = getattr(response, 'url', '')
96-
if (
97-
isinstance(final_url, str)
98-
and urlparse(final_url).path.rstrip('/') == '/web/database/selector'
99-
):
100-
self._database_bootstrap_failed = True
101-
logger.error(
165+
redirect_urls = [
166+
getattr(redirect, 'url', None)
167+
for redirect in (getattr(response, 'history', ()) or ())
168+
]
169+
if any(not self._has_odoo_origin(url) for url in [*redirect_urls, final_url]):
170+
return self._bootstrap_validation_failed(
171+
'Database bootstrap failed for ODOO_DATABASE=%r: cross-origin redirect chain or final URL. '
172+
'Runtime API calls were not attempted.',
173+
self.database,
174+
)
175+
176+
if any(urlparse(url).path.rstrip('/') == '/web/database/selector' for url in [*redirect_urls, final_url]):
177+
return self._bootstrap_validation_failed(
102178
'Database bootstrap failed for ODOO_DATABASE=%r: redirected to '
103179
'/web/database/selector. Runtime API calls were not attempted.',
104180
self.database,
105181
)
106-
return False
182+
183+
session_cookies = list(self._bootstrap_session_cookies(response))
184+
if not session_cookies:
185+
return self._bootstrap_validation_failed(
186+
'Database bootstrap failed for ODOO_DATABASE=%r: no Odoo session cookie was set. '
187+
'Runtime API calls were not attempted.',
188+
self.database,
189+
)
190+
191+
if not any(self._session_cookie_applies_to_api_url(cookie) for cookie in session_cookies):
192+
return self._bootstrap_validation_failed(
193+
'Database bootstrap failed for ODOO_DATABASE=%r: Odoo session cookie does not apply to the runtime API URL. '
194+
'Runtime API calls were not attempted.',
195+
self.database,
196+
)
197+
198+
self.session.cookies.update(self.bootstrap_session.cookies)
199+
response_cookies = getattr(response, 'cookies', None)
200+
if response_cookies is not None:
201+
self.session.cookies.update(response_cookies)
107202

108203
self._database_bootstrapped = True
109204
logger.info('Selected Odoo database %r for this runtime session.', self.database)
@@ -140,7 +235,7 @@ def _is_ok(self, result):
140235
def send_heartbeat(self):
141236
"""Send heartbeat to Odoo."""
142237
data = {
143-
'version': '0.3.0',
238+
'version': '0.2.1',
144239
'runtime_name': self.name,
145240
'device_info': get_device_info(),
146241
}
@@ -488,8 +583,13 @@ def setup_logging(verbose=False):
488583
)
489584

490585

586+
def load_runtime_dotenv(dotenv_path=None):
587+
"""Load runtime configuration without expanding dollar expressions."""
588+
return load_dotenv(dotenv_path=dotenv_path, interpolate=False)
589+
590+
491591
def main():
492-
load_dotenv()
592+
load_runtime_dotenv()
493593

494594
parser = argparse.ArgumentParser(description='Odoo Agent Runtime Daemon')
495595
parser.add_argument('--odoo-url', default=os.getenv('ODOO_URL', 'http://localhost:8069'),

0 commit comments

Comments
 (0)