feat(learning-harness): absence rows travel with their registration

Eight of the ten vendored access-control rows had no named handler at all,
so every one of them would have scored `missing_context` forever rather
than as a detector miss. After the re-harvest nine are named and the tenth
states its reason.

The handler-context mode now carries the class its framework registers,
multi-line decorators, and commented-out guards -- `#@token_required`
above a ThreatByte handler is the entire bug. Where the registration lives
in another document (connexion's `operationId`, an express router), a
recipe names `context = [...]`, the harvester writes that stanza per side,
and the pair materializes both files at their repository-relative paths so
the entry-point mapper sees the layout the project has. `harvest_recipe`
fetches every blob before the first write and the driver takes `--report`,
so a failed fetch leaves a reviewed excerpt exactly as it was.

Two defects the re-harvest exposed: `.mjs` was not a known suffix, so the
one pair vendored as an ES module had no file target at all; and
`_python_route_access` matched auth words inside decorator prose, reading
`@ns.doc(description='... without proper authorization checks')` as a
guard. Recorded in the hygiene artifact: nine of the ten duplicate groups
sit on both sides of the split, which the repository-level split cannot
see.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01T7XD7x5KonMdmGRkp63EQG
This commit is contained in:
Marius Ciepluch
2026-09-06 12:39:55 +02:00
co-authored by Claude Opus 5
parent 7a33756a7e
commit c2d9c4ad01
48 changed files with 1613 additions and 11776 deletions
+14
View File
@@ -3272,6 +3272,7 @@ class = "broken_access_control"
path = "server/api/v1/api_v1.py"
function = "delete"
mechanism = "missing_auth_guard"
family = "access_control"
evidence = "BFLA (Broken Function Level Authorization) on the delete-user API endpoint. The @token_required decorator is commented out (lines 221-222), so DELETE /api/v1/delete-user/<user_id> can be called by anyone without authentication to delete any"
[[pair]]
@@ -3301,6 +3302,7 @@ class = "broken_access_control"
path = "server/api/v1/api_v1.py"
function = "get"
mechanism = "missing_auth_guard"
family = "access_control"
evidence = "BOLA (Broken Object Level Authorization) on the API profile endpoint. The @token_required decorator is commented out (line 152-153), so /api/v1/profile?user_id=X returns any user's profile (username, email, country, role, permissions, team)"
[[pair]]
@@ -3353,12 +3355,18 @@ provenance = "human"
split = "holdout"
review_tier = "seeded"
[[pair.context]]
relpath = "openapi_specs/openapi3.yml"
vuln = "vampi-books-get-by-title/context/vuln/openapi_specs/openapi3.yml"
fixed = "vampi-books-get-by-title/context/fixed/openapi_specs/openapi3.yml"
[[pair.expected]]
cwe = "CWE-639"
class = "broken_access_control"
path = "api_views/books.py"
function = "get_by_title"
mechanism = "missing_auth_guard"
family = "access_control"
evidence = "Broken Object Level Authorization (BOLA). When vuln=1, get_by_title queries the book by title only (Book.query.filter_by(book_title=str(book_title)).first()) without verifying the authenticated user is the owner. Any authenticated user can "
[[pair]]
@@ -3411,12 +3419,18 @@ provenance = "human"
split = "holdout"
review_tier = "seeded"
[[pair.context]]
relpath = "openapi_specs/openapi3.yml"
vuln = "vampi-users-update-password/context/vuln/openapi_specs/openapi3.yml"
fixed = "vampi-users-update-password/context/fixed/openapi_specs/openapi3.yml"
[[pair.expected]]
cwe = "CWE-639"
class = "broken_access_control"
path = "api_views/users.py"
function = "update_password"
mechanism = "missing_auth_guard"
family = "access_control"
evidence = "Unauthorized password change (IDOR). When vuln=1, the update_password function uses the username from the URL path parameter to look up the user whose password to change, instead of using the authenticated user from the JWT token (resp['sub"
[[pair]]
+13 -4
View File
@@ -3208,7 +3208,7 @@ parent = "c4db46f72586c4ecb65859051ea037018dbf0e5e"
commit = "c4db46f72586c4ecb65859051ea037018dbf0e5e"
path = "server/api/v1/api_v1.py"
fix_path = "server/api/v1/api_v1.py"
mode = "enclosing"
mode = "handler_context"
line = 223
fix_line = 123
function = "delete"
@@ -3229,6 +3229,8 @@ trap_id = "threatbyte-fp-004"
acceptable_cwes = ["CWE-862", "CWE-306", "CWE-284", "CWE-287"]
evidence = "BFLA (Broken Function Level Authorization) on the delete-user API endpoint. The @token_required decorator is commented out (lines 221-222), so DELETE /api/v1/delete-user/<user_id> can be called by anyone without authentication to delete any"
commit_url = "https://github.com/anotherik/ThreatByte/blob/c4db46f72586c4ecb65859051ea037018dbf0e5e/server/api/v1/api_v1.py#L223"
family = "access_control"
fix_function = "post"
split = "train"
[[recipe]]
@@ -3239,7 +3241,7 @@ parent = "c4db46f72586c4ecb65859051ea037018dbf0e5e"
commit = "c4db46f72586c4ecb65859051ea037018dbf0e5e"
path = "server/api/v1/api_v1.py"
fix_path = "server/api/v1/api_v1.py"
mode = "enclosing"
mode = "handler_context"
line = 154
fix_line = 123
function = "get"
@@ -3260,6 +3262,8 @@ trap_id = "threatbyte-fp-004"
acceptable_cwes = ["CWE-639", "CWE-284", "CWE-862", "CWE-863"]
evidence = "BOLA (Broken Object Level Authorization) on the API profile endpoint. The @token_required decorator is commented out (line 152-153), so /api/v1/profile?user_id=X returns any user's profile (username, email, country, role, permissions, team)"
commit_url = "https://github.com/anotherik/ThreatByte/blob/c4db46f72586c4ecb65859051ea037018dbf0e5e/server/api/v1/api_v1.py#L154"
family = "access_control"
fix_function = "post"
split = "holdout"
[[recipe]]
@@ -3301,7 +3305,7 @@ parent = "1713b54b601ad29582581eeda4b31fceb1319874"
commit = "1713b54b601ad29582581eeda4b31fceb1319874"
path = "api_views/books.py"
fix_path = "api_views/books.py"
mode = "enclosing"
mode = "handler_context"
line = 51
fix_line = 62
function = "get_by_title"
@@ -3322,6 +3326,8 @@ trap_id = "vampi-fp-003"
acceptable_cwes = ["CWE-639", "CWE-284", "CWE-285", "CWE-862"]
evidence = "Broken Object Level Authorization (BOLA). When vuln=1, get_by_title queries the book by title only (Book.query.filter_by(book_title=str(book_title)).first()) without verifying the authenticated user is the owner. Any authenticated user can "
commit_url = "https://github.com/erev0s/VAmPI/blob/1713b54b601ad29582581eeda4b31fceb1319874/api_views/books.py#L51"
family = "access_control"
context = ["openapi_specs/openapi3.yml"]
split = "holdout"
[[recipe]]
@@ -3363,7 +3369,7 @@ parent = "1713b54b601ad29582581eeda4b31fceb1319874"
commit = "1713b54b601ad29582581eeda4b31fceb1319874"
path = "api_views/users.py"
fix_path = "api_views/users.py"
mode = "enclosing"
mode = "handler_context"
line = 187
fix_line = 55
function = "update_password"
@@ -3384,6 +3390,9 @@ trap_id = "vampi-fp-001"
acceptable_cwes = ["CWE-639", "CWE-284", "CWE-285", "CWE-862"]
evidence = "Unauthorized password change (IDOR). When vuln=1, the update_password function uses the username from the URL path parameter to look up the user whose password to change, instead of using the authenticated user from the JWT token (resp['sub"
commit_url = "https://github.com/erev0s/VAmPI/blob/1713b54b601ad29582581eeda4b31fceb1319874/api_views/users.py#L187"
family = "access_control"
fix_function = "register_user"
context = ["openapi_specs/openapi3.yml"]
split = "holdout"
[[recipe]]
@@ -9,39 +9,47 @@
# relpath: server/api/v1/api_v1.py
# provenance: human
# mechanism: missing_auth_guard
# upstream_start: 103
def post(self):
"""
Handles user login.
"""
data = request.get_json() # Get data from request body
username = data.get('username')
password = data.get('password')
if not username or not password:
return {'error': 'Please provide username and password'}, 400
with get_db_connection() as conn:
cursor = conn.cursor()
query = "SELECT * FROM users WHERE username = ? OR email = ?"
cursor.execute(query, (username, username))
user = cursor.fetchone()
if user and user['password'] == custom_hash(password):
# Generate JWT
token = jwt.encode({
'username': username,
'exp': datetime.datetime.utcnow() + datetime.timedelta(hours=24) # Token expires in 24 hours
}, Config.SECRET_KEY, algorithm='HS256')
# Update last_login timestamp
with get_db_connection() as conn:
cursor = conn.cursor()
cursor.execute("UPDATE users SET last_login = ? WHERE username = ?", (datetime.datetime.now(), username))
conn.commit()
return {'message': 'Login successful', 'token': token}, 200
else:
return {'error': 'Invalid username or password'}, 401
@ns.route('/login')
class UserLogin(Resource):
@ns.expect(login_model)
@ns.response(200, 'Login successful', login_response_model)
@ns.response(400, 'Please provide username and password')
@ns.response(401, 'Invalid username or password')
@ns.response(405, 'Method not allowed')
def post(self):
"""
Handles user login.
"""
data = request.get_json() # Get data from request body
username = data.get('username')
password = data.get('password')
if not username or not password:
return {'error': 'Please provide username and password'}, 400
with get_db_connection() as conn:
cursor = conn.cursor()
query = "SELECT * FROM users WHERE username = ? OR email = ?"
cursor.execute(query, (username, username))
user = cursor.fetchone()
if user and user['password'] == custom_hash(password):
# Generate JWT
token = jwt.encode({
'username': username,
'exp': datetime.datetime.utcnow() + datetime.timedelta(hours=24) # Token expires in 24 hours
}, Config.SECRET_KEY, algorithm='HS256')
# Update last_login timestamp
with get_db_connection() as conn:
cursor = conn.cursor()
cursor.execute("UPDATE users SET last_login = ? WHERE username = ?", (datetime.datetime.now(), username))
conn.commit()
return {'message': 'Login successful', 'token': token}, 200
else:
return {'error': 'Invalid username or password'}, 401
@@ -9,20 +9,29 @@
# relpath: server/api/v1/api_v1.py
# provenance: human
# mechanism: missing_auth_guard
# upstream_start: 215
def delete(self, user_id):
"""
Delete a user from the application.
"""
with get_db_connection() as conn:
cursor = conn.cursor()
cursor.execute("SELECT * FROM users WHERE id = ?", (user_id,))
user = cursor.fetchone()
if user:
cursor.execute("DELETE FROM users WHERE id = ?", (user_id,))
conn.commit()
response = make_response(jsonify({'message': 'User deleted successfully'}), 200)
return response
else:
response = make_response(jsonify({'error': 'User not found'}), 404)
return response
@ns.route('/delete-user/<int:user_id>')
@ns.doc(description='Delete a user from the database without proper authorization checks. '
'This endpoint represents a Broken Function Level Authorization vulnerability.',
responses={200: ('User successfully deleted', delete_model),
404: ('User not found', error_model)})
class UserDelete(Resource):
#@token_required
#def delete(self, current_user, user_id):
def delete(self, user_id):
"""
Delete a user from the application.
"""
with get_db_connection() as conn:
cursor = conn.cursor()
cursor.execute("SELECT * FROM users WHERE id = ?", (user_id,))
user = cursor.fetchone()
if user:
cursor.execute("DELETE FROM users WHERE id = ?", (user_id,))
conn.commit()
response = make_response(jsonify({'message': 'User deleted successfully'}), 200)
return response
else:
response = make_response(jsonify({'error': 'User not found'}), 404)
return response
@@ -9,39 +9,47 @@
# relpath: server/api/v1/api_v1.py
# provenance: human
# mechanism: missing_auth_guard
# upstream_start: 103
def post(self):
"""
Handles user login.
"""
data = request.get_json() # Get data from request body
username = data.get('username')
password = data.get('password')
if not username or not password:
return {'error': 'Please provide username and password'}, 400
with get_db_connection() as conn:
cursor = conn.cursor()
query = "SELECT * FROM users WHERE username = ? OR email = ?"
cursor.execute(query, (username, username))
user = cursor.fetchone()
if user and user['password'] == custom_hash(password):
# Generate JWT
token = jwt.encode({
'username': username,
'exp': datetime.datetime.utcnow() + datetime.timedelta(hours=24) # Token expires in 24 hours
}, Config.SECRET_KEY, algorithm='HS256')
# Update last_login timestamp
with get_db_connection() as conn:
cursor = conn.cursor()
cursor.execute("UPDATE users SET last_login = ? WHERE username = ?", (datetime.datetime.now(), username))
conn.commit()
return {'message': 'Login successful', 'token': token}, 200
else:
return {'error': 'Invalid username or password'}, 401
@ns.route('/login')
class UserLogin(Resource):
@ns.expect(login_model)
@ns.response(200, 'Login successful', login_response_model)
@ns.response(400, 'Please provide username and password')
@ns.response(401, 'Invalid username or password')
@ns.response(405, 'Method not allowed')
def post(self):
"""
Handles user login.
"""
data = request.get_json() # Get data from request body
username = data.get('username')
password = data.get('password')
if not username or not password:
return {'error': 'Please provide username and password'}, 400
with get_db_connection() as conn:
cursor = conn.cursor()
query = "SELECT * FROM users WHERE username = ? OR email = ?"
cursor.execute(query, (username, username))
user = cursor.fetchone()
if user and user['password'] == custom_hash(password):
# Generate JWT
token = jwt.encode({
'username': username,
'exp': datetime.datetime.utcnow() + datetime.timedelta(hours=24) # Token expires in 24 hours
}, Config.SECRET_KEY, algorithm='HS256')
# Update last_login timestamp
with get_db_connection() as conn:
cursor = conn.cursor()
cursor.execute("UPDATE users SET last_login = ? WHERE username = ?", (datetime.datetime.now(), username))
conn.commit()
return {'message': 'Login successful', 'token': token}, 200
else:
return {'error': 'Invalid username or password'}, 401
@@ -9,21 +9,30 @@
# relpath: server/api/v1/api_v1.py
# provenance: human
# mechanism: missing_auth_guard
# upstream_start: 146
def get(self):
"""
Retrieves the profile information of a user based on the provided user ID.
"""
args = profile_query.parse_args()
user_id = args.get('user_id')
with get_db_connection() as conn:
cursor = conn.cursor()
query = "SELECT username, email, country, role, permissions, team FROM users WHERE id = ?"
cursor.execute(query, (user_id,))
user_profile = cursor.fetchone()
if user_profile:
return dict(user_profile), 200
else:
return {'error': 'User profile not found'}, 404
@ns.route('/profile')
class UserProfile(Resource):
@ns.expect(profile_query)
@ns.response(200, 'Success', user_profile_model)
@ns.response(400, 'User ID is required')
@ns.response(404, 'User profile not found')
#@token_required
#def get(self, current_user):
def get(self):
"""
Retrieves the profile information of a user based on the provided user ID.
"""
args = profile_query.parse_args()
user_id = args.get('user_id')
with get_db_connection() as conn:
cursor = conn.cursor()
query = "SELECT username, email, country, role, permissions, team FROM users WHERE id = ?"
cursor.execute(query, (user_id,))
user_profile = cursor.fetchone()
if user_profile:
return dict(user_profile), 200
else:
return {'error': 'User profile not found'}, 404
@@ -0,0 +1,79 @@
# Provenance: erev0s/VAmPI get_by_title (fixed).
# repo: erev0s/VAmPI
# commit: 1713b54b601ad29582581eeda4b31fceb1319874
# parent: 1713b54b601ad29582581eeda4b31fceb1319874
# commit_url: https://github.com/erev0s/VAmPI/blob/1713b54b601ad29582581eeda4b31fceb1319874/api_views/books.py#L51
# cve:
# license: MIT
# function: get_by_title
# relpath: openapi_specs/openapi3.yml
# provenance: human
# mechanism: missing_auth_guard
paths:
/books/v1/{book_title}:
get:
security:
- bearerAuth: [ ]
tags:
- books
summary: Retrieves book by title along with secret
description: >-
Retrieves book by title along with secret. Only the owner may retrieve
it
operationId: api_views.books.get_by_title
parameters:
- name: book_title
in: path
description: retrieve book data
required: true
schema:
type: string
example: 'bookTitle77'
responses:
'200':
description: Successfully retrieve book info
content:
application/json:
schema:
type: array
items:
type: object
properties:
book_title:
type: string
example: 'bookTitle77'
owner:
type: string
example: 'name1'
secret:
type: string
example: 'secret for bookTitle77'
'401':
description: User not authorized
content:
application/json:
schema:
type: object
properties:
status:
type: string
enum: ['fail']
example: 'fail'
message:
type: string
example: 'Invalid token. Please log in again.'
'404':
description: Book not found
content:
application/json:
schema:
type: object
properties:
status:
type: string
enum: ['fail']
example: 'fail'
message:
type: string
example: 'Book not found!'
@@ -0,0 +1,79 @@
# Provenance: erev0s/VAmPI get_by_title (vuln).
# repo: erev0s/VAmPI
# commit: 1713b54b601ad29582581eeda4b31fceb1319874
# parent: 1713b54b601ad29582581eeda4b31fceb1319874
# commit_url: https://github.com/erev0s/VAmPI/blob/1713b54b601ad29582581eeda4b31fceb1319874/api_views/books.py#L51
# cve:
# license: MIT
# function: get_by_title
# relpath: openapi_specs/openapi3.yml
# provenance: human
# mechanism: missing_auth_guard
paths:
/books/v1/{book_title}:
get:
security:
- bearerAuth: [ ]
tags:
- books
summary: Retrieves book by title along with secret
description: >-
Retrieves book by title along with secret. Only the owner may retrieve
it
operationId: api_views.books.get_by_title
parameters:
- name: book_title
in: path
description: retrieve book data
required: true
schema:
type: string
example: 'bookTitle77'
responses:
'200':
description: Successfully retrieve book info
content:
application/json:
schema:
type: array
items:
type: object
properties:
book_title:
type: string
example: 'bookTitle77'
owner:
type: string
example: 'name1'
secret:
type: string
example: 'secret for bookTitle77'
'401':
description: User not authorized
content:
application/json:
schema:
type: object
properties:
status:
type: string
enum: ['fail']
example: 'fail'
message:
type: string
example: 'Invalid token. Please log in again.'
'404':
description: Book not found
content:
application/json:
schema:
type: object
properties:
status:
type: string
enum: ['fail']
example: 'fail'
message:
type: string
example: 'Book not found!'
@@ -9,6 +9,7 @@
# relpath: api_views/books.py
# provenance: human
# mechanism: missing_auth_guard
# upstream_start: 45
def get_by_title(book_title):
resp = token_validator(request.headers.get('Authorization'))
@@ -9,6 +9,7 @@
# relpath: api_views/books.py
# provenance: human
# mechanism: missing_auth_guard
# upstream_start: 45
def get_by_title(book_title):
resp = token_validator(request.headers.get('Authorization'))
@@ -0,0 +1,55 @@
# Provenance: erev0s/VAmPI update_password (fixed).
# repo: erev0s/VAmPI
# commit: 1713b54b601ad29582581eeda4b31fceb1319874
# parent: 1713b54b601ad29582581eeda4b31fceb1319874
# commit_url: https://github.com/erev0s/VAmPI/blob/1713b54b601ad29582581eeda4b31fceb1319874/api_views/users.py#L187
# cve:
# license: MIT
# function: update_password
# relpath: openapi_specs/openapi3.yml
# provenance: human
# mechanism: missing_auth_guard
paths:
/users/v1/register:
post:
tags:
- users
summary: Register new user
description: Register new user
operationId: api_views.users.register_user
requestBody:
description: Username of the user
content:
application/json:
schema:
type: object
properties:
username:
type: string
example: 'name1'
password:
type: string
example: 'pass1'
email:
type: string
example: '[email protected]'
required: true
responses:
'200':
description: Successfully created user
content:
application/json:
schema:
type: object
properties:
message:
type: string
example: 'Successfully registered. Login to receive an auth token.'
status:
type: string
enum: ['success', 'fail']
example: 'success'
'400':
description: Invalid request
content: {}
@@ -0,0 +1,73 @@
# Provenance: erev0s/VAmPI update_password (vuln).
# repo: erev0s/VAmPI
# commit: 1713b54b601ad29582581eeda4b31fceb1319874
# parent: 1713b54b601ad29582581eeda4b31fceb1319874
# commit_url: https://github.com/erev0s/VAmPI/blob/1713b54b601ad29582581eeda4b31fceb1319874/api_views/users.py#L187
# cve:
# license: MIT
# function: update_password
# relpath: openapi_specs/openapi3.yml
# provenance: human
# mechanism: missing_auth_guard
paths:
/users/v1/{username}/password:
put:
security:
- bearerAuth: [ ]
tags:
- users
summary: Update users password
description: Update users password
operationId: api_views.users.update_password
parameters:
- name: username
in: path
description: username to update password
required: true
schema:
type: string
example: 'name1'
requestBody:
description: field to update
content:
application/json:
schema:
type: object
properties:
password:
type: string
example: 'pass4'
required: true
responses:
'204':
description: Successfully updated users password
content: {}
'400':
description: Invalid request
content:
application/json:
schema:
type: object
properties:
status:
type: string
enum: ['fail']
example: 'fail'
message:
type: string
example: 'Malformed Data'
'401':
description: User not authorized
content:
application/json:
schema:
type: object
properties:
status:
type: string
enum: ['fail']
example: 'fail'
message:
type: string
example: 'Invalid token. Please log in again.'
@@ -9,6 +9,7 @@
# relpath: api_views/users.py
# provenance: human
# mechanism: missing_auth_guard
# upstream_start: 52
def register_user():
request_data = request.get_json()
@@ -9,6 +9,7 @@
# relpath: api_views/users.py
# provenance: human
# mechanism: missing_auth_guard
# upstream_start: 179
def update_password(username):
request_data = request.get_json()