Logo di Cron Background Job Security

Cron Background Job Security

Organizzazione
wpultimatesecurity
cron-background-job-security

Usa questa skill quando pianifichi eventi cron di WordPress con wp_schedule_event / wp_schedule_single_event o scrivi la callback eseguita da un hook cron. Considera che le callback cron vengono eseguite senza un utente connesso, verifica nuovamente le autorizzazioni in base al contesto memorizzato anziché usare current_user_can, non inserire segreti negli URL cron e convalida tutti i dati memorizzati usati dal processo. Previene l'esecuzione di azioni privilegiate non autenticate tramite cron.

Add to TypingMind

Panoramica

Pubblicato dawpultimatesecurity
RepositoryWordPress-Security-Skills
Nome della skillcron-background-job-security
Stelle
54
Fork
3
File inclusi
2
LicenzaMIT
Link
  • Istruzioni in Markdown

    Un file SKILL.md che il modello carica quando serve, consumando token solo quando una richiesta è effettivamente pertinente.

  • Funziona con qualsiasi LLM

    Le skill IA sono in semplice Markdown, non in codice specifico di un fornitore, quindi funzionano con GPT, Claude, Gemini, Grok o un modello locale.

  • File inclusi: 2

    Script, template e riferimenti che il modello può leggere mentre lavora. I file sono di sola lettura e non vengono mai eseguiti.

  • Open source

    Pubblicata da wpultimatesecurity su GitHub. Leggi i sorgenti prima di installarla.

Installazione

Installa la skill IA Cron Background Job Security in TypingMind per usarla con qualsiasi LLM, oppure copiala in un altro agente in grado di leggere SKILL.md.

1

Installa in TypingMind

TypingMind installa una skill direttamente dalla sua cartella GitHub: legge SKILL.md, raccoglie i file delle risorse e salva il risultato in locale.

  1. Apri l'app e vai su Plugin → Skill.
  2. Scegli "Installa da GitHub".
  3. Incolla l'URL della cartella della skill riportato qui sotto e conferma.
    https://github.com/wpultimatesecurity/WordPress-Security-Skills/tree/dev/skills/cron-background-job-security
  4. Attiva la skill in ogni chat in cui vuoi averla a disposizione.
Plugin → Skill → Aggiungi skill → Da URL GitHub, poi incolla l'URL della cartella e premi Continua.
2

Installa in un altro agente

Qualsiasi agente che legge il formato Agent Skills può usare questa skill: copia la cartella della skill nella directory delle skill di quell'agente.

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
Dopo la copia, riavvia Claude Code per caricare la nuova skill.

Usala in TypingMind

Attiva Cron Background Job Security in qualsiasi chat di TypingMind e al resto pensa il modello. Il nome e la descrizione della skill sono nel prompt di sistema e, non appena arriva una richiesta pertinente, il modello carica da solo le istruzioni complete: non devi mai richiamarla manualmente e non consuma token finché non viene effettivamente usata.

Il modello carica automaticamente Cron Background Job Security non appena riceve una richiesta pertinente.

Funziona con qualsiasi modello IA

Le skill IA sono semplici istruzioni in Markdown, non codice specifico di un fornitore, quindi Cron Background Job Security non è vincolata al modello per cui è stata scritta. Installala una sola volta in TypingMind e usala con GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama o un modello locale che esegui tu, sempre con le tue chiavi API.

  • Caricata solo quando serve

    Il prompt di sistema contiene solo il nome e la descrizione. Le istruzioni vengono recuperate alla prima richiesta pertinente, quindi una skill inutilizzata non costa nulla.

  • Cambia modello durante la chat

    Poiché la skill è composta da istruzioni e non da codice, continua a funzionare anche se cambi modello: il nuovo modello legge lo stesso file SKILL.md.

Istruzioni della skill

Questo è il contenuto di SKILL.md che il modello carica. Leggilo prima dell'installazione: una skill è un insieme di istruzioni che il tuo modello seguirà.

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

File inclusi

Il modello legge questi file quando servono, mentre la skill è caricata. Sono accessibili in sola lettura e non vengono mai eseguiti.

Domande frequenti

Cosa fa la skill IA Cron Background Job Security?

Usa questa skill quando pianifichi eventi cron di WordPress con wp_schedule_event / wp_schedule_single_event o scrivi la callback eseguita da un hook cron. Considera che le callback cron vengono eseguite senza un utente connesso, verifica nuovamente le autorizzazioni in base al contesto memorizzato anziché usare current_user_can, non inserire segreti negli URL cron e convalida tutti i dati memorizzati usati dal processo. Previene l'esecuzione di azioni privilegiate non autenticate tramite cron.

Perché usare Cron Background Job Security su TypingMind?

Perché la installi una volta e la usi con qualsiasi modello. Cron Background Job Security è scritta in semplice Markdown anziché in codice specifico di un fornitore, quindi la stessa skill funziona con GPT-5, Claude, Gemini, Grok o un modello locale, e puoi cambiare modello durante la chat senza che la skill smetta di funzionare. TypingMind usa le tue chiavi API, quindi paghi direttamente i fornitori anziché un abbonamento per posto utente, e le tue skill e chat restano nel tuo spazio di archiviazione.

Come installo Cron Background Job Security in TypingMind?

Apri Plugin → Skill → Installa da GitHub in TypingMind e incolla https://github.com/wpultimatesecurity/WordPress-Security-Skills/tree/dev/skills/cron-background-job-security. TypingMind legge il file SKILL.md, include i file associati e installa la skill, che puoi abilitare per ogni singola chat.

Quali modelli IA possono usare Cron Background Job Security?

Qualsiasi modello che colleghi a TypingMind. Le skill IA sono semplici istruzioni in Markdown anziché codice specifico di un fornitore, quindi GPT, Claude, Gemini, Grok e i modelli locali possono tutti caricare questa skill quando una richiesta corrisponde al suo scopo.

Quanti modelli IA posso usare con Cron Background Job Security?

Quanti ne vuoi. Se un modello supporta le skill, puoi usarlo con Cron Background Job Security: GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama e molti altri, tutti su TypingMind con le tue chiavi API.

La skill IA Cron Background Job Security è gratuita?

Sì. È pubblicata su GitHub da wpultimatesecurity con licenza MIT. Paghi solo il tuo fornitore IA per i token che usi.

Cosa sono le skill IA?

Una skill IA è un pacchetto di istruzioni riutilizzabili che insegna a un modello IA come svolgere un'attività specifica. Segue il formato aperto Agent Skills: un file SKILL.md con un nome e una descrizione, più eventuali script, template o file di riferimento di cui il modello potrebbe aver bisogno. Il modello legge le istruzioni solo quando la tua richiesta corrisponde alla skill, quindi una skill installata non comporta costi finché non viene usata.

In cosa si differenziano le skill IA dai plugin o dai server MCP?

Un plugin o un server MCP fornisce a un modello nuovi strumenti da richiamare: codice che viene eseguito da qualche parte e restituisce un risultato. Una skill IA, invece, fornisce al modello conoscenze e procedure: come affrontare un'attività, quali passaggi seguire e quali caratteristiche deve avere un buon output. Le skill sono semplici istruzioni in Markdown, quindi non richiedono server, chiavi API né ambienti di esecuzione e funzionano con qualsiasi modello.

Elenco completo

Crea subito il tuo spazio di lavoro AI

Iscriviti alla nostra newsletter per ricevere aggiornamenti sulle nuove funzionalità e sulle prossime iniziative a premi 👇