Skip to content

Audit Logs

Track all system activities with comprehensive audit logging.

Overview

Audit logs record all significant actions in your Open Short URL instance, providing a complete history of who did what, when, and from where. Essential for security compliance and troubleshooting.

Accessing Audit Logs

WARNING

Audit logs are only accessible to Admin users.

Query Logs

GET /api/audit-logs?page=1&pageSize=20

Query Parameters:

ParameterDescriptionDefault
pagePage number1
pageSizeItems per page20
actionFilter by action type-
entityTypeFilter by entity type-
userIdFilter by user-
startDateStart date (ISO 8601)-
endDateEnd date (ISO 8601)-
sortBySort fieldcreatedAt
sortOrderSort directiondesc

Example Response

json
{
  "logs": [
    {
      "id": "log_123",
      "userId": "user_456",
      "action": "URL_CREATED",
      "entityType": "url",
      "entityId": "url_789",
      "oldValue": null,
      "newValue": {
        "slug": "my-link",
        "originalUrl": "https://example.com"
      },
      "ipAddress": "192.168.1.1",
      "userAgent": "Mozilla/5.0...",
      "metadata": {
        "requestId": "req_abc123"
      },
      "createdAt": "2025-01-15T10:30:00Z"
    }
  ],
  "total": 150,
  "page": 1,
  "pageSize": 20
}

Tracked Actions

URL Actions

ActionDescription
URL_CREATEDShort URL created
URL_UPDATEDShort URL updated
URL_DELETEDShort URL deleted
URL_BULK_CREATEDMultiple URLs created
URL_BULK_UPDATEDMultiple URLs updated
URL_BULK_DELETEDMultiple URLs deleted

User Actions

ActionDescription
USER_LOGINUser logged in
USER_LOGOUTUser logged out
USER_CREATEDNew user created
USER_UPDATEDUser profile updated
USER_DELETEDUser deleted
PASSWORD_CHANGEDPassword changed
TWO_FACTOR_ENABLED2FA enabled
TWO_FACTOR_DISABLED2FA disabled

API Key Actions

ActionDescription
API_KEY_CREATEDAPI key created
API_KEY_DELETEDAPI key deleted

A/B Testing Actions

ActionDescription
VARIANT_CREATEDA/B test variant created
VARIANT_UPDATEDVariant updated
VARIANT_DELETEDVariant deleted

Bundle Actions

ActionDescription
BUNDLE_CREATEDBundle created
BUNDLE_UPDATEDBundle updated
BUNDLE_DELETEDBundle deleted

Webhook Actions

ActionDescription
WEBHOOK_CREATEDWebhook created
WEBHOOK_UPDATEDWebhook updated
WEBHOOK_DELETEDWebhook deleted

Routing Actions

ActionDescription
ROUTING_RULE_CREATEDRouting rule created
ROUTING_RULE_UPDATEDRouting rule updated
ROUTING_RULE_DELETEDRouting rule deleted

System Actions

ActionDescription
SETTINGS_UPDATEDSystem settings changed

Entity Types

Entity TypeDescription
urlShort URL
userUser account
api_keyAPI key
bundleURL bundle
webhookWebhook configuration
variantA/B test variant
routing_ruleSmart routing rule
settingsSystem settings

Log Entry Fields

Core Fields

FieldDescription
idUnique log entry ID
userIdUser who performed action
actionAction type (see above)
entityTypeType of entity affected
entityIdID of affected entity
createdAtWhen action occurred

Change Tracking

FieldDescription
oldValuePrevious state (JSON)
newValueNew state (JSON)

Example change:

json
{
  "action": "URL_UPDATED",
  "oldValue": {
    "title": "Old Title",
    "status": "ACTIVE"
  },
  "newValue": {
    "title": "New Title",
    "status": "INACTIVE"
  }
}

Request Context

FieldDescription
ipAddressClient IP address
userAgentClient user agent
metadataAdditional context

Metadata example:

json
{
  "requestId": "req_abc123",
  "method": "POST",
  "path": "/api/urls"
}

Filtering Examples

By Action Type

GET /api/audit-logs?action=URL_CREATED

By Entity Type

GET /api/audit-logs?entityType=url

By User

GET /api/audit-logs?userId=user_123

By Date Range

GET /api/audit-logs?startDate=2025-01-01&endDate=2025-01-31

Combined Filters

GET /api/audit-logs?action=URL_CREATED&userId=user_123&startDate=2025-01-01

Use Cases

Security Monitoring

Track suspicious activities:

GET /api/audit-logs?action=USER_LOGIN&sortOrder=desc

Look for:

  • Failed login attempts
  • Logins from unusual locations
  • After-hours activity

Change Audit

Review who modified what:

GET /api/audit-logs?entityType=url&entityId=url_123

See complete history of a specific URL.

Compliance Reporting

Generate reports for compliance:

GET /api/audit-logs?startDate=2025-01-01&endDate=2025-03-31&pageSize=1000

Export all activities for a quarter.

Troubleshooting

Debug issues by tracing actions:

GET /api/audit-logs?entityId=url_123&sortBy=createdAt&sortOrder=asc

See chronological history.

Log Retention

Default Behavior

Audit logs are retained indefinitely by default.

  1. Export regularly - Archive logs for long-term storage
  2. Set retention policy - Define how long to keep logs
  3. Monitor growth - Track database size

Best Practices

1. Regular Review

Check audit logs periodically:

  • Daily for critical systems
  • Weekly for general monitoring
  • After security incidents

2. Set Up Alerts

Integrate with monitoring systems:

  • Use webhooks for real-time alerts
  • Track sensitive actions
  • Monitor for anomalies

3. Export for Compliance

Maintain external backups:

  • Export monthly/quarterly
  • Store in secure location
  • Retain per compliance requirements

4. Limit Access

Restrict audit log access:

  • Admin users only
  • Review who has admin access
  • Log access to audit logs

Security Considerations

What's Logged

Audit logs capture:

  • Who (userId)
  • What (action, entity)
  • When (timestamp)
  • Where (IP, user agent)
  • Changes (old/new values)

What's NOT Logged

For privacy and security:

  • Passwords (never stored)
  • Full API keys (only prefixes)
  • Sensitive request bodies

IP Address Privacy

IP addresses are logged for security:

  • May be considered personal data (GDPR)
  • Implement retention policies as needed
  • Anonymize if required

Integration

Export to SIEM

Send logs to security platforms:

javascript
// Example: Export to Splunk
const logs = await fetchAuditLogs();
await sendToSplunk(logs);

Webhook Integration

Get real-time audit notifications by combining with webhooks (custom implementation required).

Next Steps

Released under the MIT License.