devflow-toolkit 0.3.27__py3-none-any.whl → 0.4.1__py3-none-any.whl
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.
- devflow/commands/spec.py +10 -0
- devflow/commands/status.py +30 -0
- devflow/core/config.py +21 -9
- devflow/core/discovery.py +132 -1
- devflow/core/security_baseline.py +366 -0
- devflow/core/specification.py +86 -1
- devflow/prompts/__init__.py +103 -15
- devflow/prompts/discovery.md +41 -5
- devflow/prompts/spec.md +6 -0
- {devflow_toolkit-0.3.27.dist-info → devflow_toolkit-0.4.1.dist-info}/METADATA +140 -29
- {devflow_toolkit-0.3.27.dist-info → devflow_toolkit-0.4.1.dist-info}/RECORD +14 -13
- {devflow_toolkit-0.3.27.dist-info → devflow_toolkit-0.4.1.dist-info}/WHEEL +0 -0
- {devflow_toolkit-0.3.27.dist-info → devflow_toolkit-0.4.1.dist-info}/entry_points.txt +0 -0
- {devflow_toolkit-0.3.27.dist-info → devflow_toolkit-0.4.1.dist-info}/licenses/LICENSE +0 -0
devflow/commands/spec.py
CHANGED
|
@@ -191,6 +191,16 @@ def _create_specification(
|
|
|
191
191
|
detector = ProjectDetector()
|
|
192
192
|
root = detector.find_root(path)
|
|
193
193
|
config = ConfigManager(root).load()
|
|
194
|
+
if config.discovery.uses_legacy_defaults:
|
|
195
|
+
_print_warnings(
|
|
196
|
+
[
|
|
197
|
+
"Discovery uses the old limits (follow_up 3, maximum 12, "
|
|
198
|
+
"max_rounds 3), which can stop Discovery before every security "
|
|
199
|
+
"control is covered. Set discovery.question_budget.follow_up: 6, "
|
|
200
|
+
"maximum: 20 and discovery.interaction.max_rounds: 5 in "
|
|
201
|
+
".devflow/config.yaml."
|
|
202
|
+
]
|
|
203
|
+
)
|
|
194
204
|
|
|
195
205
|
if resume is not None:
|
|
196
206
|
_ensure_continuable(config, resume)
|
devflow/commands/status.py
CHANGED
|
@@ -20,6 +20,10 @@ from devflow.core.discovery import (
|
|
|
20
20
|
DiscoveryManager,
|
|
21
21
|
)
|
|
22
22
|
from devflow.core.project import ProjectDetector
|
|
23
|
+
from devflow.core.security_baseline import (
|
|
24
|
+
applicable_areas,
|
|
25
|
+
uncovered_controls,
|
|
26
|
+
)
|
|
23
27
|
from devflow.core.state import (
|
|
24
28
|
ChangeLocation,
|
|
25
29
|
ChangeStatus,
|
|
@@ -29,6 +33,7 @@ from devflow.core.state import (
|
|
|
29
33
|
WorkflowStatus,
|
|
30
34
|
artifact_blockers,
|
|
31
35
|
)
|
|
36
|
+
from devflow.prompts import coverage_texts, security_texts
|
|
32
37
|
|
|
33
38
|
console = Console()
|
|
34
39
|
error_console = Console(stderr=True)
|
|
@@ -245,6 +250,31 @@ def _print_discovery(
|
|
|
245
250
|
soft_wrap=True,
|
|
246
251
|
)
|
|
247
252
|
|
|
253
|
+
areas = applicable_areas(security_texts("", discovery))
|
|
254
|
+
if areas:
|
|
255
|
+
console.print(
|
|
256
|
+
" security baseline: "
|
|
257
|
+
+ ", ".join(area.label for area in areas),
|
|
258
|
+
soft_wrap=True,
|
|
259
|
+
)
|
|
260
|
+
missing = uncovered_controls(areas, coverage_texts(discovery))
|
|
261
|
+
if missing:
|
|
262
|
+
console.print(
|
|
263
|
+
" [yellow]level-1 controls not cited by any decision: "
|
|
264
|
+
+ ", ".join(control.asvs_id for control in missing)
|
|
265
|
+
+ "[/yellow]",
|
|
266
|
+
soft_wrap=True,
|
|
267
|
+
)
|
|
268
|
+
for risk in discovery.accepted_risks:
|
|
269
|
+
state = (
|
|
270
|
+
f"accepted by {risk.accepted_by}"
|
|
271
|
+
if risk.is_accepted
|
|
272
|
+
else "pending acceptance"
|
|
273
|
+
)
|
|
274
|
+
console.print(
|
|
275
|
+
f" {risk.id} [security risk] {state}: {risk.risk}",
|
|
276
|
+
soft_wrap=True,
|
|
277
|
+
)
|
|
248
278
|
for note in discovery.notes:
|
|
249
279
|
console.print(f" [yellow]corrected: {note}[/yellow]", soft_wrap=True)
|
|
250
280
|
|
devflow/core/config.py
CHANGED
|
@@ -24,6 +24,9 @@ DEFAULT_PLANS_PATH = Path(".devflow") / "plans"
|
|
|
24
24
|
DEFAULT_TEMPLATES_PATH = Path(".devflow") / "templates"
|
|
25
25
|
DEFAULT_DOCUMENTATION_LANGUAGE = "en"
|
|
26
26
|
MAX_DISCOVERY_BUDGET = 100
|
|
27
|
+
# follow_up, maximum and max_rounds written by `devflow init` before
|
|
28
|
+
# 0.4.1. They were too small once Discovery covered security levels.
|
|
29
|
+
LEGACY_DISCOVERY_LIMITS = (3, 12, 3)
|
|
27
30
|
|
|
28
31
|
_LANGUAGE_ALIASES = {
|
|
29
32
|
"aleman": "de",
|
|
@@ -214,10 +217,19 @@ class DiscoverySettings:
|
|
|
214
217
|
"""Deterministic limits for the Discovery decision loop."""
|
|
215
218
|
|
|
216
219
|
question_budget_initial: int = 6
|
|
217
|
-
question_budget_follow_up: int =
|
|
218
|
-
question_budget_maximum: int =
|
|
219
|
-
max_rounds: int =
|
|
220
|
+
question_budget_follow_up: int = 6
|
|
221
|
+
question_budget_maximum: int = 20
|
|
222
|
+
max_rounds: int = 5
|
|
220
223
|
batch_size: int = 6
|
|
224
|
+
|
|
225
|
+
@property
|
|
226
|
+
def uses_legacy_defaults(self) -> bool:
|
|
227
|
+
"""Return whether the limits are the pre-0.4.1 defaults."""
|
|
228
|
+
return (
|
|
229
|
+
self.question_budget_follow_up,
|
|
230
|
+
self.question_budget_maximum,
|
|
231
|
+
self.max_rounds,
|
|
232
|
+
) == LEGACY_DISCOVERY_LIMITS
|
|
221
233
|
assumptions_enabled: bool = True
|
|
222
234
|
require_explicit_acceptance: bool = True
|
|
223
235
|
|
|
@@ -490,12 +502,12 @@ class ConfigManager:
|
|
|
490
502
|
"discovery": {
|
|
491
503
|
"question_budget": {
|
|
492
504
|
"initial": 6,
|
|
493
|
-
"follow_up":
|
|
494
|
-
"maximum":
|
|
505
|
+
"follow_up": 6,
|
|
506
|
+
"maximum": 20,
|
|
495
507
|
},
|
|
496
508
|
"interaction": {
|
|
497
509
|
"batch_size": 6,
|
|
498
|
-
"max_rounds":
|
|
510
|
+
"max_rounds": 5,
|
|
499
511
|
},
|
|
500
512
|
"assumptions": {
|
|
501
513
|
"enabled": True,
|
|
@@ -782,13 +794,13 @@ class ConfigManager:
|
|
|
782
794
|
maximum=100,
|
|
783
795
|
)
|
|
784
796
|
follow_up = self._bounded_integer(
|
|
785
|
-
budget.get("follow_up",
|
|
797
|
+
budget.get("follow_up", 6),
|
|
786
798
|
"discovery.question_budget.follow_up",
|
|
787
799
|
minimum=0,
|
|
788
800
|
maximum=100,
|
|
789
801
|
)
|
|
790
802
|
maximum = self._bounded_integer(
|
|
791
|
-
budget.get("maximum",
|
|
803
|
+
budget.get("maximum", 20),
|
|
792
804
|
"discovery.question_budget.maximum",
|
|
793
805
|
minimum=0,
|
|
794
806
|
maximum=MAX_DISCOVERY_BUDGET,
|
|
@@ -810,7 +822,7 @@ class ConfigManager:
|
|
|
810
822
|
question_budget_follow_up=follow_up,
|
|
811
823
|
question_budget_maximum=maximum,
|
|
812
824
|
max_rounds=self._bounded_integer(
|
|
813
|
-
interaction.get("max_rounds",
|
|
825
|
+
interaction.get("max_rounds", 5),
|
|
814
826
|
"discovery.interaction.max_rounds",
|
|
815
827
|
minimum=1,
|
|
816
828
|
maximum=20,
|
devflow/core/discovery.py
CHANGED
|
@@ -157,6 +157,7 @@ ASSUMPTION_SOURCES = ("agent_default", "human", "existing_convention")
|
|
|
157
157
|
_QUESTION_ID = re.compile(r"^Q\d{1,3}$")
|
|
158
158
|
_RECOMMENDED = re.compile(r"recom+end", re.IGNORECASE)
|
|
159
159
|
_ASSUMPTION_ID = re.compile(r"^A\d{1,3}$")
|
|
160
|
+
_RISK_ID = re.compile(r"^R\d{1,3}$")
|
|
160
161
|
|
|
161
162
|
_STOPWORDS = {
|
|
162
163
|
"a",
|
|
@@ -714,6 +715,41 @@ class DiscoveryAssumption:
|
|
|
714
715
|
}
|
|
715
716
|
|
|
716
717
|
|
|
718
|
+
@dataclass(frozen=True)
|
|
719
|
+
class AcceptedRisk:
|
|
720
|
+
"""A security control the user explicitly decided not to apply now."""
|
|
721
|
+
|
|
722
|
+
id: str
|
|
723
|
+
risk: str
|
|
724
|
+
reason: str
|
|
725
|
+
control: str | None = None
|
|
726
|
+
status: str = ASSUMPTION_PENDING
|
|
727
|
+
accepted_by: str | None = None
|
|
728
|
+
accepted_at: str | None = None
|
|
729
|
+
review_by: str | None = None
|
|
730
|
+
|
|
731
|
+
@property
|
|
732
|
+
def is_accepted(self) -> bool:
|
|
733
|
+
return self.status == ASSUMPTION_ACCEPTED
|
|
734
|
+
|
|
735
|
+
def to_dict(self) -> dict[str, Any]:
|
|
736
|
+
data: dict[str, Any] = {"id": self.id}
|
|
737
|
+
if self.control:
|
|
738
|
+
data["control"] = self.control
|
|
739
|
+
data.update(
|
|
740
|
+
{
|
|
741
|
+
"risk": self.risk,
|
|
742
|
+
"reason": self.reason,
|
|
743
|
+
"status": self.status,
|
|
744
|
+
"accepted_by": self.accepted_by,
|
|
745
|
+
"accepted_at": self.accepted_at,
|
|
746
|
+
}
|
|
747
|
+
)
|
|
748
|
+
if self.review_by:
|
|
749
|
+
data["review_by"] = self.review_by
|
|
750
|
+
return data
|
|
751
|
+
|
|
752
|
+
|
|
717
753
|
@dataclass(frozen=True)
|
|
718
754
|
class DiscoveryDocument:
|
|
719
755
|
"""Persistent discovery record for one change."""
|
|
@@ -729,6 +765,7 @@ class DiscoveryDocument:
|
|
|
729
765
|
questions: tuple[DiscoveryQuestion, ...] = ()
|
|
730
766
|
assumptions: tuple[DiscoveryAssumption, ...] = ()
|
|
731
767
|
deferred: tuple[DeferredItem, ...] = ()
|
|
768
|
+
accepted_risks: tuple[AcceptedRisk, ...] = ()
|
|
732
769
|
# Minor problems DevFlow corrected while reading the record. They are
|
|
733
770
|
# reported to the user and never written back by themselves.
|
|
734
771
|
notes: tuple[str, ...] = ()
|
|
@@ -800,9 +837,20 @@ class DiscoveryDocument:
|
|
|
800
837
|
if not assumption.is_accepted
|
|
801
838
|
)
|
|
802
839
|
|
|
840
|
+
@property
|
|
841
|
+
def pending_risks(self) -> tuple[AcceptedRisk, ...]:
|
|
842
|
+
"""Return risks that still need explicit acceptance by a person."""
|
|
843
|
+
return tuple(
|
|
844
|
+
risk for risk in self.accepted_risks if not risk.is_accepted
|
|
845
|
+
)
|
|
846
|
+
|
|
803
847
|
@property
|
|
804
848
|
def derived_status(self) -> str:
|
|
805
|
-
if
|
|
849
|
+
if (
|
|
850
|
+
self.pending_questions
|
|
851
|
+
or self.pending_assumptions
|
|
852
|
+
or self.pending_risks
|
|
853
|
+
):
|
|
806
854
|
return DISCOVERY_AWAITING
|
|
807
855
|
if self.status == DISCOVERY_PENDING:
|
|
808
856
|
return DISCOVERY_PENDING
|
|
@@ -834,6 +882,11 @@ class DiscoveryDocument:
|
|
|
834
882
|
f"{assumption.id}: proposed assumption requires acceptance: "
|
|
835
883
|
f"{assumption.value}"
|
|
836
884
|
)
|
|
885
|
+
for risk in self.pending_risks:
|
|
886
|
+
messages.append(
|
|
887
|
+
f"{risk.id}: security risk requires explicit acceptance: "
|
|
888
|
+
f"{risk.risk}"
|
|
889
|
+
)
|
|
837
890
|
if not messages and self.status == DISCOVERY_PENDING:
|
|
838
891
|
messages.append("Discovery has not been completed.")
|
|
839
892
|
return tuple(messages)
|
|
@@ -898,6 +951,15 @@ class DiscoveryDocument:
|
|
|
898
951
|
if self.deferred
|
|
899
952
|
else {}
|
|
900
953
|
),
|
|
954
|
+
**(
|
|
955
|
+
{
|
|
956
|
+
"accepted_risks": [
|
|
957
|
+
risk.to_dict() for risk in self.accepted_risks
|
|
958
|
+
]
|
|
959
|
+
}
|
|
960
|
+
if self.accepted_risks
|
|
961
|
+
else {}
|
|
962
|
+
),
|
|
901
963
|
}
|
|
902
964
|
|
|
903
965
|
|
|
@@ -1279,6 +1341,17 @@ class DiscoveryManager:
|
|
|
1279
1341
|
self._deferred(item, index, question_ids)
|
|
1280
1342
|
for index, item in enumerate(deferred_data, start=1)
|
|
1281
1343
|
)
|
|
1344
|
+
risks_data = _list(mapping.get("accepted_risks"), "accepted_risks")
|
|
1345
|
+
if len(risks_data) > MAX_ASSUMPTIONS:
|
|
1346
|
+
msg = f"At most {MAX_ASSUMPTIONS} accepted risks are allowed."
|
|
1347
|
+
raise DiscoveryError(msg)
|
|
1348
|
+
accepted_risks = tuple(
|
|
1349
|
+
self._risk(item, index, notes=notes, default_time=updated_at)
|
|
1350
|
+
for index, item in enumerate(risks_data, start=1)
|
|
1351
|
+
)
|
|
1352
|
+
if len({risk.id for risk in accepted_risks}) != len(accepted_risks):
|
|
1353
|
+
msg = "Accepted risk ids must be unique."
|
|
1354
|
+
raise DiscoveryError(msg)
|
|
1282
1355
|
|
|
1283
1356
|
document = DiscoveryDocument(
|
|
1284
1357
|
version=version,
|
|
@@ -1292,6 +1365,7 @@ class DiscoveryManager:
|
|
|
1292
1365
|
questions=questions,
|
|
1293
1366
|
assumptions=assumptions,
|
|
1294
1367
|
deferred=deferred,
|
|
1368
|
+
accepted_risks=accepted_risks,
|
|
1295
1369
|
notes=tuple(notes),
|
|
1296
1370
|
)
|
|
1297
1371
|
return document
|
|
@@ -1498,6 +1572,63 @@ class DiscoveryManager:
|
|
|
1498
1572
|
next_level=next_level,
|
|
1499
1573
|
)
|
|
1500
1574
|
|
|
1575
|
+
def _risk(
|
|
1576
|
+
self,
|
|
1577
|
+
data: object,
|
|
1578
|
+
index: int,
|
|
1579
|
+
*,
|
|
1580
|
+
notes: list[str],
|
|
1581
|
+
default_time: str,
|
|
1582
|
+
) -> AcceptedRisk:
|
|
1583
|
+
mapping = _mapping(data, f"accepted_risks[{index}]")
|
|
1584
|
+
identifier = _text(mapping.get("id"), "accepted risk id")
|
|
1585
|
+
if not _RISK_ID.fullmatch(identifier):
|
|
1586
|
+
msg = f"Invalid accepted risk id: {identifier!r}"
|
|
1587
|
+
raise DiscoveryError(msg)
|
|
1588
|
+
status = _text(mapping.get("status"), f"{identifier}.status")
|
|
1589
|
+
if status not in ASSUMPTION_STATUSES:
|
|
1590
|
+
notes.append(
|
|
1591
|
+
f"{identifier}: unknown status {status!r} read as "
|
|
1592
|
+
f"{ASSUMPTION_PENDING!r}."
|
|
1593
|
+
)
|
|
1594
|
+
status = ASSUMPTION_PENDING
|
|
1595
|
+
accepted_by = _optional_text(
|
|
1596
|
+
mapping.get("accepted_by"),
|
|
1597
|
+
f"{identifier}.accepted_by",
|
|
1598
|
+
)
|
|
1599
|
+
accepted_at = _optional_text(
|
|
1600
|
+
mapping.get("accepted_at"),
|
|
1601
|
+
f"{identifier}.accepted_at",
|
|
1602
|
+
)
|
|
1603
|
+
if status == ASSUMPTION_ACCEPTED:
|
|
1604
|
+
if not accepted_by:
|
|
1605
|
+
accepted_by = "user"
|
|
1606
|
+
notes.append(f"{identifier}: missing accepted_by read as user.")
|
|
1607
|
+
if not accepted_at:
|
|
1608
|
+
accepted_at = default_time
|
|
1609
|
+
notes.append(
|
|
1610
|
+
f"{identifier}: missing accepted_at read as {default_time}."
|
|
1611
|
+
)
|
|
1612
|
+
else:
|
|
1613
|
+
accepted_by = None
|
|
1614
|
+
accepted_at = None
|
|
1615
|
+
return AcceptedRisk(
|
|
1616
|
+
id=identifier,
|
|
1617
|
+
control=_optional_text(
|
|
1618
|
+
mapping.get("control"),
|
|
1619
|
+
f"{identifier}.control",
|
|
1620
|
+
),
|
|
1621
|
+
risk=_limited_text(mapping.get("risk"), f"{identifier}.risk"),
|
|
1622
|
+
reason=_limited_text(mapping.get("reason"), f"{identifier}.reason"),
|
|
1623
|
+
status=status,
|
|
1624
|
+
accepted_by=accepted_by,
|
|
1625
|
+
accepted_at=accepted_at,
|
|
1626
|
+
review_by=_optional_text(
|
|
1627
|
+
mapping.get("review_by"),
|
|
1628
|
+
f"{identifier}.review_by",
|
|
1629
|
+
),
|
|
1630
|
+
)
|
|
1631
|
+
|
|
1501
1632
|
def _deferred(
|
|
1502
1633
|
self,
|
|
1503
1634
|
data: object,
|
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
"""Security baseline derived from OWASP ASVS 5.0.
|
|
2
|
+
|
|
3
|
+
DevFlow detects which security areas a change touches and gives
|
|
4
|
+
Discovery the level-1 controls to ask or inform, and the level-2
|
|
5
|
+
controls to offer as the next level. Detection is deterministic and
|
|
6
|
+
spends no tokens. Requirement identifiers follow ASVS 5.0; the control
|
|
7
|
+
texts are short summaries, not the normative wording.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import re
|
|
13
|
+
import unicodedata
|
|
14
|
+
from collections.abc import Iterable
|
|
15
|
+
from dataclasses import dataclass
|
|
16
|
+
|
|
17
|
+
ASVS_VERSION = "5.0"
|
|
18
|
+
ASVS_URL = (
|
|
19
|
+
"https://owasp.org/www-project-application-security-verification-standard/"
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@dataclass(frozen=True)
|
|
24
|
+
class Control:
|
|
25
|
+
"""One ASVS requirement summarized for Discovery."""
|
|
26
|
+
|
|
27
|
+
asvs_id: str
|
|
28
|
+
summary: str
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@dataclass(frozen=True)
|
|
32
|
+
class SecurityArea:
|
|
33
|
+
"""An ASVS chapter that a change can touch."""
|
|
34
|
+
|
|
35
|
+
key: str
|
|
36
|
+
chapter: str
|
|
37
|
+
signals: tuple[str, ...]
|
|
38
|
+
level1: tuple[Control, ...]
|
|
39
|
+
level2: tuple[Control, ...]
|
|
40
|
+
|
|
41
|
+
@property
|
|
42
|
+
def label(self) -> str:
|
|
43
|
+
return f"ASVS {ASVS_VERSION} {self.chapter}"
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
_AUTH_SIGNALS = (
|
|
47
|
+
"login",
|
|
48
|
+
"logout",
|
|
49
|
+
"log in",
|
|
50
|
+
"sign in",
|
|
51
|
+
"sign up",
|
|
52
|
+
"signup",
|
|
53
|
+
"register",
|
|
54
|
+
"registr",
|
|
55
|
+
"password",
|
|
56
|
+
"contrasena",
|
|
57
|
+
"clave",
|
|
58
|
+
"autentic",
|
|
59
|
+
"authent",
|
|
60
|
+
"iniciar sesion",
|
|
61
|
+
"cerrar sesion",
|
|
62
|
+
"inicio de sesion",
|
|
63
|
+
"crear cuenta",
|
|
64
|
+
"create account",
|
|
65
|
+
"user account",
|
|
66
|
+
"cuenta de usuario",
|
|
67
|
+
"credencial",
|
|
68
|
+
"credential",
|
|
69
|
+
"oauth",
|
|
70
|
+
"jwt",
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
AREAS: tuple[SecurityArea, ...] = (
|
|
74
|
+
SecurityArea(
|
|
75
|
+
key="authentication",
|
|
76
|
+
chapter="V6 Authentication",
|
|
77
|
+
signals=_AUTH_SIGNALS,
|
|
78
|
+
level1=(
|
|
79
|
+
Control("6.2.1", "Passwords of at least 8 characters (15 recommended)."),
|
|
80
|
+
Control("6.2.4", "Reject common passwords at registration and change."),
|
|
81
|
+
Control("6.2.3", "Password change asks for the current password."),
|
|
82
|
+
Control("6.3.1", "Defend against brute force and credential stuffing."),
|
|
83
|
+
Control("6.4.2", "No password hints or secret questions."),
|
|
84
|
+
),
|
|
85
|
+
level2=(
|
|
86
|
+
Control("6.2.12", "Reject passwords found in known breaches."),
|
|
87
|
+
Control("6.3.3", "Multi-factor authentication."),
|
|
88
|
+
Control("6.4.3", "Secure reset of a forgotten password."),
|
|
89
|
+
),
|
|
90
|
+
),
|
|
91
|
+
SecurityArea(
|
|
92
|
+
key="session",
|
|
93
|
+
chapter="V7 Session Management",
|
|
94
|
+
signals=(*_AUTH_SIGNALS, "session", "sesion", "cookie", "token"),
|
|
95
|
+
level1=(
|
|
96
|
+
Control("7.2.4", "Issue a new session token at login."),
|
|
97
|
+
Control("7.4.1", "Logout or expiry makes the session unusable."),
|
|
98
|
+
Control("7.4.2", "End all sessions when an account is disabled."),
|
|
99
|
+
),
|
|
100
|
+
level2=(
|
|
101
|
+
Control("7.3.1", "Inactivity timeout."),
|
|
102
|
+
Control("7.3.2", "Absolute maximum session lifetime."),
|
|
103
|
+
Control("7.4.3", "End other sessions after a password change."),
|
|
104
|
+
),
|
|
105
|
+
),
|
|
106
|
+
SecurityArea(
|
|
107
|
+
key="authorization",
|
|
108
|
+
chapter="V8 Authorization",
|
|
109
|
+
signals=(
|
|
110
|
+
"permiso",
|
|
111
|
+
"permission",
|
|
112
|
+
"rol",
|
|
113
|
+
"roles",
|
|
114
|
+
"role",
|
|
115
|
+
"admin",
|
|
116
|
+
"acceso",
|
|
117
|
+
"access",
|
|
118
|
+
"propietario",
|
|
119
|
+
"owner",
|
|
120
|
+
"privad",
|
|
121
|
+
"private",
|
|
122
|
+
"restring",
|
|
123
|
+
"restrict",
|
|
124
|
+
"proteg",
|
|
125
|
+
"protect",
|
|
126
|
+
),
|
|
127
|
+
level1=(
|
|
128
|
+
Control("8.2.1", "Each function is limited to users allowed to use it."),
|
|
129
|
+
Control("8.2.2", "Each record is limited to users allowed to see it."),
|
|
130
|
+
Control("8.3.1", "Authorization is enforced on the server."),
|
|
131
|
+
),
|
|
132
|
+
level2=(
|
|
133
|
+
Control("8.2.3", "Field-level access rules."),
|
|
134
|
+
),
|
|
135
|
+
),
|
|
136
|
+
SecurityArea(
|
|
137
|
+
key="input",
|
|
138
|
+
chapter="V2 Validation and V1 Encoding",
|
|
139
|
+
signals=(
|
|
140
|
+
"formulario",
|
|
141
|
+
"form",
|
|
142
|
+
"input",
|
|
143
|
+
"campo",
|
|
144
|
+
"field",
|
|
145
|
+
"crear",
|
|
146
|
+
"create",
|
|
147
|
+
"editar",
|
|
148
|
+
"edit",
|
|
149
|
+
"actualizar",
|
|
150
|
+
"update",
|
|
151
|
+
"buscar",
|
|
152
|
+
"search",
|
|
153
|
+
"busqueda",
|
|
154
|
+
"filtr",
|
|
155
|
+
"filter",
|
|
156
|
+
"comentario",
|
|
157
|
+
"comment",
|
|
158
|
+
"contacto",
|
|
159
|
+
"contact",
|
|
160
|
+
),
|
|
161
|
+
level1=(
|
|
162
|
+
Control("2.2.1", "Validate input against the expected values."),
|
|
163
|
+
Control("2.2.2", "Validate on the server, not only in the browser."),
|
|
164
|
+
Control("1.2.4", "Parameterized queries or the ORM, no raw SQL."),
|
|
165
|
+
Control("1.2.1", "Encode output for its context (prevents XSS)."),
|
|
166
|
+
),
|
|
167
|
+
level2=(
|
|
168
|
+
Control("2.4.1", "Anti-automation: limit excessive requests."),
|
|
169
|
+
Control("2.3.3", "Transactions: an operation completes or rolls back."),
|
|
170
|
+
),
|
|
171
|
+
),
|
|
172
|
+
SecurityArea(
|
|
173
|
+
key="web",
|
|
174
|
+
chapter="V3 Web Frontend Security",
|
|
175
|
+
signals=(
|
|
176
|
+
"html",
|
|
177
|
+
"pagina",
|
|
178
|
+
"page",
|
|
179
|
+
"plantilla",
|
|
180
|
+
"template",
|
|
181
|
+
"vista",
|
|
182
|
+
"view",
|
|
183
|
+
"frontend",
|
|
184
|
+
"navegador",
|
|
185
|
+
"browser",
|
|
186
|
+
"cookie",
|
|
187
|
+
),
|
|
188
|
+
level1=(
|
|
189
|
+
Control("3.5.3", "Sensitive actions use POST, never GET."),
|
|
190
|
+
Control("3.3.1", "Cookies are marked Secure."),
|
|
191
|
+
Control("3.4.1", "HSTS header on every response."),
|
|
192
|
+
),
|
|
193
|
+
level2=(
|
|
194
|
+
Control("3.3.4", "Session cookies are HttpOnly."),
|
|
195
|
+
Control("3.4.3", "Content-Security-Policy header."),
|
|
196
|
+
),
|
|
197
|
+
),
|
|
198
|
+
SecurityArea(
|
|
199
|
+
key="files",
|
|
200
|
+
chapter="V5 File Handling",
|
|
201
|
+
signals=(
|
|
202
|
+
"archivo",
|
|
203
|
+
"file",
|
|
204
|
+
"upload",
|
|
205
|
+
"subir",
|
|
206
|
+
"imagen",
|
|
207
|
+
"image",
|
|
208
|
+
"adjunt",
|
|
209
|
+
"attachment",
|
|
210
|
+
"pdf",
|
|
211
|
+
"csv",
|
|
212
|
+
),
|
|
213
|
+
level1=(
|
|
214
|
+
Control("5.2.1", "Limit the size of accepted files."),
|
|
215
|
+
Control("5.2.2", "Check the extension and type of each file."),
|
|
216
|
+
Control("5.3.1", "Uploaded files are never executed by the server."),
|
|
217
|
+
Control("5.3.2", "Never build paths from user-supplied file names."),
|
|
218
|
+
),
|
|
219
|
+
level2=(
|
|
220
|
+
Control("5.4.3", "Scan uploaded files with an antivirus."),
|
|
221
|
+
),
|
|
222
|
+
),
|
|
223
|
+
SecurityArea(
|
|
224
|
+
key="api",
|
|
225
|
+
chapter="V4 API and Web Service",
|
|
226
|
+
signals=(
|
|
227
|
+
"api",
|
|
228
|
+
"endpoint",
|
|
229
|
+
"rest",
|
|
230
|
+
"json",
|
|
231
|
+
"graphql",
|
|
232
|
+
"webhook",
|
|
233
|
+
),
|
|
234
|
+
level1=(
|
|
235
|
+
Control("4.1.1", "Every response declares the right Content-Type."),
|
|
236
|
+
Control("8.3.1", "API authorization is enforced on the server."),
|
|
237
|
+
),
|
|
238
|
+
level2=(
|
|
239
|
+
Control("2.4.1", "Rate limiting on the API."),
|
|
240
|
+
Control("4.1.2", "Only user-facing endpoints redirect HTTP to HTTPS."),
|
|
241
|
+
),
|
|
242
|
+
),
|
|
243
|
+
SecurityArea(
|
|
244
|
+
key="data",
|
|
245
|
+
chapter="V14 Data Protection",
|
|
246
|
+
signals=(
|
|
247
|
+
"datos personales",
|
|
248
|
+
"personal data",
|
|
249
|
+
"correo",
|
|
250
|
+
"email",
|
|
251
|
+
"telefono",
|
|
252
|
+
"phone",
|
|
253
|
+
"direccion",
|
|
254
|
+
"address",
|
|
255
|
+
"pago",
|
|
256
|
+
"payment",
|
|
257
|
+
"tarjeta",
|
|
258
|
+
"card",
|
|
259
|
+
"datos de salud",
|
|
260
|
+
"health data",
|
|
261
|
+
"sensibl",
|
|
262
|
+
"sensitive",
|
|
263
|
+
"cedula",
|
|
264
|
+
"identidad",
|
|
265
|
+
),
|
|
266
|
+
level1=(
|
|
267
|
+
Control("14.2.1", "Sensitive data never travels in URLs."),
|
|
268
|
+
Control("14.3.1", "Clear signed-in data from the browser on logout."),
|
|
269
|
+
),
|
|
270
|
+
level2=(
|
|
271
|
+
Control("14.1.1", "Identify and classify sensitive data."),
|
|
272
|
+
Control("14.3.2", "Cache-Control: no-store for sensitive responses."),
|
|
273
|
+
),
|
|
274
|
+
),
|
|
275
|
+
SecurityArea(
|
|
276
|
+
key="configuration",
|
|
277
|
+
chapter="V13 Configuration",
|
|
278
|
+
signals=(
|
|
279
|
+
"deploy",
|
|
280
|
+
"despliegue",
|
|
281
|
+
"desplegar",
|
|
282
|
+
"produccion",
|
|
283
|
+
"production",
|
|
284
|
+
"docker",
|
|
285
|
+
),
|
|
286
|
+
level1=(
|
|
287
|
+
Control("13.4.1", "Source control metadata (.git) is never served."),
|
|
288
|
+
),
|
|
289
|
+
level2=(
|
|
290
|
+
Control("13.4.2", "Debug mode is disabled in production."),
|
|
291
|
+
Control("13.3.1", "Secrets live in a secrets manager, not in code."),
|
|
292
|
+
),
|
|
293
|
+
),
|
|
294
|
+
)
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
def _normalize(value: str) -> str:
|
|
298
|
+
decomposed = unicodedata.normalize("NFKD", value)
|
|
299
|
+
plain = "".join(c for c in decomposed if not unicodedata.combining(c))
|
|
300
|
+
return " ".join(plain.lower().split())
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
def applicable_areas(texts: Iterable[str]) -> tuple[SecurityArea, ...]:
|
|
304
|
+
"""Return the areas whose signals appear in the given texts."""
|
|
305
|
+
text = _normalize(" ".join(value for value in texts if value))
|
|
306
|
+
if not text:
|
|
307
|
+
return ()
|
|
308
|
+
return tuple(
|
|
309
|
+
area
|
|
310
|
+
for area in AREAS
|
|
311
|
+
if any(_matches(signal, text) for signal in area.signals)
|
|
312
|
+
)
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
def _matches(signal: str, text: str) -> bool:
|
|
316
|
+
# Short signals must be whole words ("api", "rest", "form"); longer
|
|
317
|
+
# ones also match as a prefix ("autentic" matches "autenticacion").
|
|
318
|
+
suffix = r"\b" if len(signal) <= 4 else ""
|
|
319
|
+
return re.search(rf"\b{re.escape(signal)}{suffix}", text) is not None
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
def baseline_lines(areas: Iterable[SecurityArea]) -> list[str]:
|
|
323
|
+
"""Render the baseline compactly for the Decision Context."""
|
|
324
|
+
lines: list[str] = []
|
|
325
|
+
for area in areas:
|
|
326
|
+
level1 = "; ".join(
|
|
327
|
+
f"{control.asvs_id} {control.summary.rstrip('.')}"
|
|
328
|
+
for control in area.level1
|
|
329
|
+
)
|
|
330
|
+
level2 = "; ".join(
|
|
331
|
+
f"{control.asvs_id} {control.summary.rstrip('.')}"
|
|
332
|
+
for control in area.level2
|
|
333
|
+
)
|
|
334
|
+
lines.append(f"- {area.label}")
|
|
335
|
+
lines.append(f" - Level 1 (ask or inform): {level1}")
|
|
336
|
+
if level2:
|
|
337
|
+
lines.append(f" - Level 2 (offer as next level): {level2}")
|
|
338
|
+
return lines
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
def checklist_lines(areas: Iterable[SecurityArea]) -> list[str]:
|
|
342
|
+
"""Render the level-1 controls as a review checklist for spec.md."""
|
|
343
|
+
lines: list[str] = []
|
|
344
|
+
for area in areas:
|
|
345
|
+
for control in area.level1:
|
|
346
|
+
lines.append(f"- {area.label} {control.asvs_id}: {control.summary}")
|
|
347
|
+
return lines
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
def uncovered_controls(
|
|
351
|
+
areas: Iterable[SecurityArea],
|
|
352
|
+
cited: Iterable[str],
|
|
353
|
+
) -> tuple[Control, ...]:
|
|
354
|
+
"""Return level-1 controls whose ASVS id no decision cites yet."""
|
|
355
|
+
text = " ".join(value for value in cited if value)
|
|
356
|
+
missing: list[Control] = []
|
|
357
|
+
seen: set[str] = set()
|
|
358
|
+
for area in areas:
|
|
359
|
+
for control in area.level1:
|
|
360
|
+
if control.asvs_id in seen:
|
|
361
|
+
continue
|
|
362
|
+
seen.add(control.asvs_id)
|
|
363
|
+
pattern = rf"(?<![\d.]){re.escape(control.asvs_id)}(?!\d)"
|
|
364
|
+
if re.search(pattern, text) is None:
|
|
365
|
+
missing.append(control)
|
|
366
|
+
return tuple(missing)
|