Logo van Cron Background Job Security

Cron Background Job Security

Organisatie
wpultimatesecurity
cron-background-job-security

Gebruik dit bij het plannen van WordPress-cron-gebeurtenissen met wp_schedule_event / wp_schedule_single_event of bij het schrijven van de callback voor een cron-hook. Ga ervan uit dat cron-callbacks worden uitgevoerd zonder aangemelde gebruiker. Controleer de rechten opnieuw aan de hand van opgeslagen context, niet met current_user_can, houd geheimen uit cron-URL's en valideer alle opgeslagen invoer die de taak gebruikt. Voorkomt niet-geauthenticeerde bevoorrechte acties via cron.

Add to TypingMind

Overzicht

Uitgeverwpultimatesecurity
RepositoryWordPress-Security-Skills
Skillnaamcron-background-job-security
Sterren
54
Forks
3
Meegeleverde bestanden
2
LicentieMIT
Links
  • Instructies in Markdown

    Het model laadt het bestand SKILL.md alleen als dat nodig is. Dat kost dus alleen tokens als een verzoek daadwerkelijk bij de skill past.

  • Werkt met elk LLM

    AI-skills bestaan uit instructies in gewone Markdown, niet uit aanbiederspecifieke code. Daardoor werken ze met GPT, Claude, Gemini, Grok of een lokaal model.

  • Meegeleverde bestanden: 2

    Scripts, sjablonen en referentiemateriaal die het model tijdens het werken kan lezen. De bestanden kunnen alleen worden gelezen en worden nooit uitgevoerd.

  • Open source

    Gepubliceerd door wpultimatesecurity op GitHub. Bekijk de bronbestanden voordat je de skill installeert.

Installatie

Installeer de AI-skill Cron Background Job Security in TypingMind om deze met elk LLM te gebruiken, of voeg de skill toe aan een andere agent die SKILL.md kan lezen.

1

Installeren in TypingMind

TypingMind installeert een skill rechtstreeks vanuit de GitHub-map. De app leest SKILL.md, bundelt de bijbehorende bestanden en slaat het resultaat lokaal op.

  1. Open de app en ga naar Plug-ins → Skills.
  2. Kies "Installeren via GitHub".
  3. Plak de onderstaande URL van de skillmap en bevestig.
    https://github.com/wpultimatesecurity/WordPress-Security-Skills/tree/dev/skills/cron-background-job-security
  4. Schakel de skill in voor elke chat waarin je de skill wilt kunnen gebruiken.
Plug-ins → Skills → Skill toevoegen → Via GitHub-URL. Plak vervolgens de map-URL en druk op Doorgaan.
2

Installeren in een andere agent

Elke agent die het Agent Skills-formaat kan lezen, kan deze skill gebruiken — kopieer de map naar de skillmap van die agent.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/wpultimatesecurity/WordPress-Security-Skills.git /tmp/WordPress-Security-Skills
mkdir -p .claude/skills
cp -r /tmp/WordPress-Security-Skills/skills/cron-background-job-security .claude/skills/cron-background-job-security
Start Claude Code na het kopiëren opnieuw op, zodat de nieuwe skill wordt herkend.

Gebruik deze skill in TypingMind

Schakel Cron Background Job Security in voor een chat naar keuze in TypingMind en het model doet de rest. De naam en beschrijving staan in de systeemprompt. Zodra een verzoek bij de skill past, laadt het model zelf de volledige instructies. Je hoeft de skill nooit handmatig aan te roepen. Pas als het model de skill daadwerkelijk gebruikt, kost dat tokens.

Het model laadt Cron Background Job Security automatisch zodra een verzoek erbij past.

Werkt met elk AI-model

AI-skills zijn gewone Markdown-instructies in plaats van aanbiederspecifieke code. Daardoor is Cron Background Job Security niet gebonden aan het model waarvoor de skill is geschreven. Installeer de skill één keer in TypingMind en gebruik deze met GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama of een lokaal model dat je zelf draait — allemaal met je eigen API-sleutels.

  • Alleen geladen wanneer nodig

    De systeemprompt bevat alleen de naam en beschrijving. De instructies worden bij het eerste bijpassende verzoek opgehaald, dus een ongebruikte skill kost niets.

  • Wissel van model tijdens een chat

    Omdat de skill uit instructies bestaat en niet uit code, blijft deze werken als je van model wisselt — het volgende model leest hetzelfde SKILL.md-bestand.

Skillinstructies

Dit is de inhoud van SKILL.md die het model laadt. Lees deze vóór de installatie — een skill bestaat uit instructies die je model zal volgen.

Cron & background job security

When to use this skill

Use this skill whenever code schedules or runs WordPress cron events:

  • Calling wp_schedule_event() or wp_schedule_single_event().
  • Writing a callback for a cron hook (add_action( 'my_plugin_daily_sync', ... )).
  • Running jobs through wp-cron.php, including externally triggered real cron.
  • Storing context (user ids, arguments) for a job to act on later.

Cron callbacks run with no current user. current_user_can() returns false for everything, and wp-cron.php is publicly reachable. Authorization must be captured at schedule time and re-verified inside the callback against stored context, not the absent current user.

Related: see the secrets-credentials-management skill for keeping keys out of cron URLs and the capability-permission-checks skill for normal request authorization.

Core principles (and why they matter)

  1. No current_user_can() inside cron callbacks. There is no logged-in user during cron execution. Capture the acting user or capability context when scheduling and re-verify it from stored data.
  2. wp-cron.php is public. Anyone can trigger it. The callback itself must enforce authorization, not rely on the trigger being hidden.
  3. Do not put secrets in scheduled URLs or args. Cron arguments are stored in the cron option; treat them as persistent but not secret.
  4. Sanitize and validate stored args. The job reads args that were stored earlier; validate them again before acting.
  5. Use wp_next_scheduled() to prevent duplicates. Without it, reactivations or repeated init hooks can schedule the same event many times.
  6. Clean up on deactivation. Use wp_clear_scheduled_hook() so events don't run for a deactivated plugin.

Step-by-step implementation

  1. Schedule the event with wp_next_scheduled() guard:
    php
    if ( ! wp_next_scheduled( 'my_plugin_daily_sync' ) ) {
        wp_schedule_event( time(), 'daily', 'my_plugin_daily_sync' );
    }
  2. If the job needs per-object authorization, store a user id or capability context alongside the args at schedule time (e.g., the user who queued a one-time export).
  3. In the callback, re-verify the stored context:
    • Look up the user and check user_can( $user_id, $capability ).
    • Validate object ids with get_post() / get_userdata() and check ownership/permission.
  4. Sanitize every stored arg before use.
  5. Avoid passing secrets or raw user input as cron args.
  6. On plugin deactivation, clear the hook.

Supporting references

ReferenceLoad when
Cron & background job security checklistBefore final verification of the cron & background job security controls.
Secure cron jobImplementing a recurring cron job with stored authorization context and deactivation cleanup.

Common AI mistakes / anti-patterns

Mistake 1 — Using current_user_can() inside a cron callback

php
// ❌ Insecure: current_user_can is meaningless during cron; this always fails.
add_action( 'my_plugin_daily_sync', function () {
    if ( ! current_user_can( 'manage_options' ) ) {
        return;
    }
    my_plugin_sync();
} );
php
// ✅ Secure: the scheduled event itself is the authorization boundary; validate data only.
add_action( 'my_plugin_daily_sync', 'my_plugin_run_daily_sync' );
function my_plugin_run_daily_sync() {
    $settings = get_option( 'my_plugin_sync_settings', array() );
    $endpoint = isset( $settings['endpoint'] ) ? esc_url_raw( $settings['endpoint'] ) : '';
    if ( ! $endpoint ) {
        return;
    }
    // No current_user_can needed — the fact the event was scheduled is the policy.
    my_plugin_sync( $endpoint );
}

Mistake 2 — Passing a secret in the cron URL

php
// ❌ Insecure: secret lands in the cron option and may appear in logs.
wp_schedule_single_event( time(), 'my_plugin_fetch', array( 'token' => $api_secret ) );
php
// ✅ Secure: store the secret in a wp-config constant or encrypted option; pass only ids.
wp_schedule_single_event( time(), 'my_plugin_fetch', array( 'feed_id' => $feed_id ) );
// Callback reads the secret from a secure location.

Mistake 3 — Trusting $_GET passed to a cron trigger

php
// ❌ Insecure: wp-cron.php is public and $_GET is attacker-controllable.
add_action( 'my_plugin_run_export', function () {
    $user_id = (int) $_GET['user_id'];
    my_plugin_export_for_user( $user_id );
} );
php
// ✅ Secure: capture and validate context at schedule time, then re-verify inside the job.
function my_plugin_queue_export( $user_id ) {
    if ( ! current_user_can( 'manage_options' ) ) {
        return false;
    }
    $user_id = absint( $user_id );
    wp_schedule_single_event( time(), 'my_plugin_run_export', array( 'user_id' => $user_id ) );
}

add_action( 'my_plugin_run_export', 'my_plugin_run_export_callback' );
function my_plugin_run_export_callback( $args ) {
    $user_id = isset( $args['user_id'] ) ? absint( $args['user_id'] ) : 0;
    if ( $user_id <= 0 || ! user_can( $user_id, 'read' ) ) {
        return;
    }
    my_plugin_export_for_user( $user_id );
}

Mistake 4 — Scheduling duplicate events

php
// ❌ Risky: creates a new event on every init if not guarded.
add_action( 'init', function () {
    wp_schedule_event( time(), 'hourly', 'my_plugin_hourly' );
} );
php
// ✅ Secure: guard with wp_next_scheduled().
add_action( 'init', function () {
    if ( ! wp_next_scheduled( 'my_plugin_hourly' ) ) {
        wp_schedule_event( time(), 'hourly', 'my_plugin_hourly' );
    }
} );

Mistake 5 — Forgetting to unschedule on deactivation

php
// ❌ Risky: scheduled hooks outlive the plugin — nothing clears them.
// (No register_deactivation_hook() anywhere in the plugin.)
register_activation_hook( __FILE__, function () {
    if ( ! wp_next_scheduled( 'my_plugin_hourly' ) ) {
        wp_schedule_event( time(), 'hourly', 'my_plugin_hourly' );
    }
} );
php
// ✅ Secure: clear scheduled hooks on deactivation.
register_deactivation_hook( __FILE__, 'my_plugin_deactivate' );
function my_plugin_deactivate() {
    wp_clear_scheduled_hook( 'my_plugin_hourly' );
    wp_clear_scheduled_hook( 'my_plugin_daily_sync' );
}

Correct code examples

An integration example — schedule, callback with stored-context verification, and deactivation cleanup — is in references/secure-cron-job.php. It calls my_plugin_generate_user_export( $user_id ), a project callback your plugin must provide (the file documents the contract); adapt names and hooks to your plugin.

Checklist

  • Cron callbacks do not rely on current_user_can().
  • Per-object jobs capture the acting user/context at schedule time and re-verify it in the callback.
  • Secrets are not passed as cron arguments or embedded in cron URLs.
  • Stored cron args are sanitized and validated before use.
  • wp_next_scheduled() prevents duplicate scheduled events.
  • Custom recurrence intervals are added via the cron_schedules filter before scheduling.
  • Scheduled hooks are cleared on plugin deactivation.
  • Failures are logged without exposing secrets or internal paths.

Official references

Meegeleverde bestanden

Zolang de skill geladen is, leest het model deze bestanden als dat nodig is. Het model kan ze alleen lezen; ze worden nooit uitgevoerd.

Veelgestelde vragen

Wat doet de AI-skill Cron Background Job Security?

Gebruik dit bij het plannen van WordPress-cron-gebeurtenissen met wp_schedule_event / wp_schedule_single_event of bij het schrijven van de callback voor een cron-hook. Ga ervan uit dat cron-callbacks worden uitgevoerd zonder aangemelde gebruiker. Controleer de rechten opnieuw aan de hand van opgeslagen context, niet met current_user_can, houd geheimen uit cron-URL's en valideer alle opgeslagen invoer die de taak gebruikt. Voorkomt niet-geauthenticeerde bevoorrechte acties via cron.

Waarom Cron Background Job Security gebruiken in TypingMind?

Omdat je deze skill één keer installeert en met elk model kunt gebruiken. Cron Background Job Security bestaat uit gewone Markdown in plaats van aanbiederspecifieke code. Dezelfde skill werkt dus met GPT-5, Claude, Gemini, Grok of een lokaal model. Ook als je midden in een chat van model wisselt, blijft de skill werken. TypingMind werkt met je eigen API-sleutels, dus je betaalt aanbieders rechtstreeks in plaats van een abonnement per gebruikersplek af te sluiten. Je skills en chats blijven in je eigen opslag.

Hoe installeer ik Cron Background Job Security in TypingMind?

Open Plug-ins → Skills → Installeren vanaf GitHub in TypingMind en plak https://github.com/wpultimatesecurity/WordPress-Security-Skills/tree/dev/skills/cron-background-job-security. TypingMind leest het bestand SKILL.md, bundelt de bijbehorende bestanden en installeert het geheel als een skill die je per chat kunt inschakelen.

Welke AI-modellen kunnen Cron Background Job Security gebruiken?

Elk model dat je in TypingMind koppelt. AI-skills bestaan uit gewone Markdown-instructies in plaats van aanbiederspecifieke code. GPT, Claude, Gemini, Grok en lokale modellen kunnen deze skill dus allemaal laden wanneer een verzoek erbij past.

Hoeveel AI-modellen kan ik met Cron Background Job Security gebruiken?

Zoveel als je wilt. Je kunt Cron Background Job Security gebruiken met elk model dat skills ondersteunt, zoals GPT, Claude, Gemini, Grok, DeepSeek, Mistral of Llama. Allemaal in TypingMind met je eigen API-sleutels.

Is de AI-skill Cron Background Job Security gratis?

Ja. Deze skill is door wpultimatesecurity op GitHub gepubliceerd onder de licentie MIT. Je betaalt alleen je eigen AI-aanbieder voor de tokens die je gebruikt.

Wat zijn AI-skills?

Een AI-skill is een herbruikbare bundel instructies die een AI-model leert hoe het één specifieke taak moet uitvoeren. De skill volgt het open Agent Skills-formaat: het bestand SKILL.md bevat de naam en beschrijving van de skill. Daarnaast kan de skill scripts, sjablonen of referentiebestanden bevatten die het model nodig heeft. Het model leest de instructies alleen als je verzoek bij de skill past. Een geïnstalleerde skill kost dus niets zolang deze niet wordt gebruikt.

Waarin verschillen AI-skills van plug-ins of MCP-servers?

Een plug-in of MCP-server geeft een model nieuwe tools om aan te roepen: code die ergens wordt uitgevoerd en een resultaat teruggeeft. Een AI-skill geeft het model juist kennis en een werkwijze: hoe het een taak moet aanpakken, welke stappen het moet volgen en hoe goede uitvoer eruitziet. Skills bestaan uit gewone Markdown en hebben dus geen server, API-sleutel of runtime nodig. Ze werken met elk model.

Bekijk alles

Maak nu je eigen AI-werkruimte

Schrijf je in voor onze nieuwsbrief en blijf op de hoogte van nieuwe functies en toekomstige weggeefacties 👇