mirror of
https://github.com/Dvorinka/Primora.git
synced 2026-10-28 15:51:23 +00:00
Stress-test remediation across MCP, CLI, and backend:
- primora_vault_exec rewritten as an allow-list (was deny-list):
colon-form single-token commands bypassed it, leaking every vault
secret; verbatim env-name injection allowed NODE_OPTIONS=--require
host RCE. Now fixed read-mostly command set, arg/path deny regex,
strict env-name grammar, loader-hook name blocklist. All prior
bypasses verified denied; allowed commands still inject.
- SSRF: webhook/job URL validation now blocks cloud metadata IPs
(169.254.169.254, fd00:ec2::254) inside the link-local allowance
and non-canonical IP encodings (decimal/hex bare hosts) smuggled
as "docker service names".
- Path params encodeURIComponent in all client consumers — encodeURI
left ?#& intact, smuggling query segments through {name} params.
- primora_upload_object strict-validates contentBase64 — Buffer.from
silently dropped invalid chars.
- MCP no-creds startup degrades instead of crashing mid-handshake.
- GET /api/v1/context — API-key self-discovery; fixes the CLI dead
end (login --api-key validates the key + seeds org/project,
use/context/whoami work under key auth).
- CLI: unknown commands / bare group exit 1 with hints; mri numeric
coercion reversed via raw-argv restore (007 stays "007");
login --json; orgs:rm / projects:rm / buckets:rm behind --yes;
fetch-failed errors name the cause.
- Error hygiene: pgx.ErrNoRows -> 404, pgconn codes -> clean
400/409 without SQLSTATE leaks, validator failures formatted,
services.InputError maps input faults to 400 (webhook URL/event
errors were 500s), presign on local driver -> 400.
- Webhook events accept wildcard patterns (*, ns.*, custom.*)
matched via SQL LIKE — client-published events can be webhooked.
Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
82 lines
1.7 KiB
SQL
82 lines
1.7 KiB
SQL
-- name: ListWebhooks :many
|
|
SELECT * FROM core.webhooks
|
|
WHERE project_id = $1
|
|
ORDER BY created_at ASC;
|
|
|
|
-- name: GetWebhookByID :one
|
|
SELECT * FROM core.webhooks
|
|
WHERE id = $1;
|
|
|
|
-- name: ListWebhooksForEvent :many
|
|
SELECT * FROM core.webhooks
|
|
WHERE project_id = $1
|
|
AND enabled
|
|
AND (cardinality(events) = 0 OR EXISTS (
|
|
SELECT 1 FROM unnest(events) AS e
|
|
WHERE e = '*' OR $2::text LIKE REPLACE(e, '*', '%')
|
|
));
|
|
|
|
-- name: CreateWebhook :one
|
|
INSERT INTO core.webhooks (
|
|
project_id,
|
|
url,
|
|
secret,
|
|
events,
|
|
enabled,
|
|
created_by_user_id
|
|
) VALUES ($1, $2, $3, $4, $5, $6)
|
|
RETURNING *;
|
|
|
|
-- name: UpdateWebhook :one
|
|
UPDATE core.webhooks
|
|
SET url = $3,
|
|
events = $4,
|
|
enabled = $5,
|
|
secret = CASE WHEN $6::boolean THEN $7 ELSE secret END,
|
|
updated_at = NOW()
|
|
WHERE id = $1
|
|
AND project_id = $2
|
|
RETURNING *;
|
|
|
|
-- name: DeleteWebhook :one
|
|
DELETE FROM core.webhooks
|
|
WHERE id = $1
|
|
AND project_id = $2
|
|
RETURNING *;
|
|
|
|
-- name: InsertWebhookDelivery :one
|
|
INSERT INTO core.webhook_deliveries (
|
|
webhook_id,
|
|
event_type,
|
|
payload,
|
|
next_retry_at
|
|
) VALUES ($1, $2, $3, NOW())
|
|
RETURNING *;
|
|
|
|
-- name: GetWebhookDeliveryByID :one
|
|
SELECT * FROM core.webhook_deliveries
|
|
WHERE id = $1;
|
|
|
|
-- name: ListWebhookDeliveries :many
|
|
SELECT * FROM core.webhook_deliveries
|
|
WHERE webhook_id = $1
|
|
ORDER BY created_at DESC
|
|
LIMIT $2;
|
|
|
|
-- name: ListPendingWebhookDeliveries :many
|
|
SELECT * FROM core.webhook_deliveries
|
|
WHERE status = 'pending'
|
|
AND (next_retry_at IS NULL OR next_retry_at <= NOW())
|
|
ORDER BY created_at
|
|
LIMIT $1;
|
|
|
|
-- name: MarkWebhookDelivery :exec
|
|
UPDATE core.webhook_deliveries
|
|
SET status = $2,
|
|
attempts = attempts + 1,
|
|
last_status_code = $3,
|
|
last_error = $4,
|
|
delivered_at = $5,
|
|
next_retry_at = $6
|
|
WHERE id = $1;
|