Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

security-rule-development

БесплатноБез исполняемых скриптовНе проверен

Adding or changing rules for b2c security scan (the SDK security module). Use when adding a new security rule, tuning a rule's false positives or negatives…

SalesforceCommerceCloudот SalesforceCommerceCloud★ 58 звёзд на GitHub

Об этом скилле

Security Rule Development

Security rules live in packages/b2c-tooling-sdk/src/security/. Each rule is an ESLint v9 rule, so the same object runs in three places: the SDK runner (used by b2c security scan, MCP, and the VS Code extension), ESLint, and oxlint's JS plugins. Tests run every rule under all three.

Add a rule

  1. Create src/security/rules/<rule-id>.ts with defineScriptRule:

    import {defineScriptRule} from '../rule.js';
    import {isRequestDerived, propertyName} from '../script/helpers.js';
    
    export default defineScriptRule({
      id: 'my-rule', // kebab-case, no slashes; a public contract once released
      severity: 'medium', // critical | high | medium | low | info
      confidence: 'medium', // how sure a finding is real; low = needs human or agent judgment
      category: 'injection', // see SecurityCategory in types.ts
      cwe: ['CWE-79'],
      description: 'One sentence: what the rule finds.',
      remediation: 'How to fix a finding.',
      create(context) {
        return {
          CallExpression(node) {
            if (propertyName(node.callee) === 'writeRaw' && isRequestDerived(node.arguments[0], context.sourceCode)) {
              context.report({node, message: 'Specific, actionable message.'});
            }
          },
        };
      },
    });
    
  2. Register it in src/security/rules/index.ts (SCRIPT_RULES).

  3. Add fixtures in test/security/fixtures/<rule-id>/. Every .js file under the directory is a fixture:

    • End every line that should produce a finding with // expect. The finding's start line must be the marked line.
    • Files without markers must produce no findings. Include the safe versions and near-misses the rule must not flag.
    • Single-file rules use bad.js and good.js. Cross-file rules add a project/ tree with cartridges (folders with a .project file) and a project/project.json of {"cartridgePath": [...]}; the harness builds the project index from the rule's directory and passes it to every runner.
    • Base fixtures on real storefront code where possible (SFRA, SiteGenesis, Storefront Next cartridges). The reference storefronts are not assumed to be clean: judge findings there on their merits.
  4. Document it with a ## <rule-id> section in docs/guide/security-rules.md (severity, confidence, CWE, what it finds, a finding/fix example) and a row in the table at the top. Regenerate the tooling index (pnpm --filter @salesforce/b2c-tooling-sdk run generate:tooling-index).

  5. Update the user skill fix table in skills/b2c-cli/skills/b2c-security/SKILL.md.

  6. Run pnpm --filter @salesforce/b2c-tooling-sdk exec mocha "test/security/**/*.test.ts". The harness checks the ID format, fixtures, docs section, and that the SDK runner, ESLint, and oxlint all report exactly the marked lines.

  7. Add a changeset (@salesforce/b2c-tooling-sdk and @salesforce/b2c-cli, minor for a new rule).

Metadata rules

Rules over site import/export data live in src/security/metadata/rules/ and are registered in METADATA_RULES. They don't run in ESLint or oxlint, but share findings, suppressions, baselines, and SARIF with script rules.

import {defineMetadataRule} from '../types.js';
import {childNamed, descendantsNamed} from '../xml.js';

export const myRule = defineMetadataRule({
  id: 'service-something',
  severity: 'medium',
  confidence: 'high',
  category: 'config',
  cwe: ['CWE-16'],
  description: 'What it finds.',
  remediation: 'How to fix it.',
  kinds: ['services'], // services | preferences | metadata | csrf-allowlist | ocapi-settings
  check(document, report) {
    if (document.format !== 'xml') return;
    for (const service of descendantsNamed(document.root, 'service')) {
      const flag = childNamed(service, 'some-flag');
      if (flag?.text === 'true') report({line: flag.line, column: flag.column, message: '...'});
    }
  },
});
  • XML elements have local name, attributes, trimmed text, line, column, and children. JSON documents (OCAPI settings) have data and text; locate lines with jsonKeyLines(text, key, value).
  • To read a new file kind, add its XML root element (or file name rule) to detectMetadataKind() in src/security/metadata/run.ts.
  • Fixtures go in test/security/fixtures/<rule-id>/bad/ and good/ with real file names (services.xml, wapi_shop_config.json). Mark XML lines with <!-- expect --> at the end of the line; for JSON, list expected line numbers in a sidecar <file>.expect.

Rule API: what you may use

Rules must run identically in all three runners, so stick to this subset:

  • Visitors keyed by ESTree node type, plus '<Type>:exit'. No selector syntax (CallExpression > Identifier).
  • node.parent (set on every node).
  • context.report({node, message}). No messageId, data, fix, or suggest.
  • context.sourceCode.getText(node), .getScope(node), .getAncestors(node), .ast, .text.
  • `context.
Полный SKILL.md на GitHub

Установить security-rule-development в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл security-rule-development?

Adding or changing rules for b2c security scan (the SDK security module). Use when adding a new security rule, tuning a rule's false positives or negatives from a real-world case, writing rule fixtures, or changing the rule runner, suppressions, baselines, or SARIF output.

Как установить скилл security-rule-development?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл security-rule-development запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить security-rule-development с