Long-Horizon Coding Evaluation for LLMs: Security Review Checklist and Practices

    Evaluating LLM coding ability requires more than benchmark scores. This article examines whether models can understand complex system context, carry a change across multiple layers, and bring a task to a runnable and testable state. Based on two contrasting projects from the same engineer, it presents a practical evaluation framework, a permission-isolation case study, and a security review checklist, while noting the limits of a small sample.

    Evaluating LLM coding ability cannot rely on benchmark scores alone. Development teams care about three things: whether a model can understand the context of a complex system, whether it can carry a single change across multiple layers, and whether it can move a task to a runnable and testable state. This article uses two substantially different projects to illustrate how these three concerns appear in practice and provides an evaluation framework and security review checklist that teams can apply directly.

    The sample scope needs to be stated first. Both projects were led by the same engineer, and the sample size is small. The conclusions here are suitable as a reference for team self-testing and should not be generalized directly into industry conclusions.

    1. What Is Long-Horizon Coding, and Why Evaluate It Separately?

    Long-horizon coding here means that a model must complete multiple steps of work continuously within one task. Typical characteristics include: context spanning multiple modules or hundreds of files; tasks that require modifying the database, interfaces, background jobs, and frontend pages at the same time; and processes that last from tens of minutes to several hours, during which the model must find and fix errors on its own.

    Single-file completion evaluation methods can hardly cover such tasks. Completion results can usually be judged correct or incorrect within seconds, while problems in long-horizon tasks often surface later. For example, interface contracts and frontend fields may not match, a migration script may miss a table, or tests may pass locally but fail in the integration environment. Therefore, evaluation should look at the result of the entire chain, not just whether a segment of code is written elegantly.

    Early tools mainly solved function-level or file-level generation problems. Newer models have clearly improved stability on long-horizon tasks, but the improvement varies by task. The most reliable way to judge whether a model is suitable for a certain type of task is to run a small-scale test on your own codebase.

    2. Evaluation Dimensions and Metrics

    It is recommended to record data across the following five dimensions, using the same criteria for every task:

    Dimension Metric Recording method
    Task completion Whether the task reaches a runnable and testable state Binary judgment, with missing steps recorded
    Cross-module capability Number of layers and files involved in one task Count changed files and classify them by data layer, business layer, API layer, and frontend
    Regression stability Pass rate of existing tests Run the full test suite and compare failing cases before and after the change
    Security quality Number of P1 and P2 security defects Combine manual acceptance results with automated scanning results
    Rework cost Manual repair time Total time from model submission to human confirmation that the change can be merged

    The value of these metrics is that they allow comparison across tasks and models. Recording only “done” or “not done” makes it impossible to determine where the model began to fail.

    3. Case One: Cross-Module Modification of a Legacy System

    The first project was a business system with a heavy legacy burden. The task goal was to add two capabilities: allowing users to upload image assets and reference those assets in HTML animation scenarios. The core difficulty was that the model first had to understand the existing table structure, authorization logic, and object storage integration before extending functionality without changing existing behavior.

    The model first parsed the project structure and identified the data model layer, business logic layer, and API layer that needed modification. The core code for the image import flow is shown below. The runtime environment was Java 17 and Spring Boot 3.x, and object storage and message queues used clients encapsulated internally by the team.

    1. public class AssetImportService {
    2. private static final Set<String> ALLOWED_EXTENSIONS = Set.of("png", "jpg", "jpeg", "gif", "webp");
    3. private static final Set<String> ALLOWED_MIME_TYPES = Set.of("image/png", "image/jpeg", "image/gif", "image/webp");
    4. private final ObjectStorageClient storageClient;
    5. private final AssetRepository assetRepository;
    6. private final OutboxRepository outboxRepository;
    7. private final TransactionTemplate transactionTemplate;
    8. private final MimeDetector mimeDetector;
    9. public ImportResult importUserAsset(MultipartFile file, UserContext userCtx) throws IOException {
    10. // 1. Check whether the user has upload permission
    11. if (!userCtx.hasPermission(Permission.UPLOAD_ASSET)) {
    12. throw new UnauthorizedException("Insufficient permissions");
    13. }
    14. // 2. Validate the extension and detect the real MIME type from file content
    15. String extension = getFileExtension(file.getOriginalFilename()).toLowerCase(Locale.ROOT);
    16. byte[] bytes = file.getBytes();
    17. String detectedType = mimeDetector.detect(bytes);
    18. if (!ALLOWED_EXTENSIONS.contains(extension) || !ALLOWED_MIME_TYPES.contains(detectedType)) {
    19. throw new InvalidAssetException("Unsupported file type");
    20. }
    21. // 3. Upload to object storage; the storage path does not contain a user-controlled filename
    22. String objectKey = "assets/" + userCtx.getUserId() + "/" + UUID.randomUUID() + "." + extension;
    23. storageClient.upload(objectKey, new ByteArrayInputStream(bytes), detectedType);
    24. // 4. Write asset metadata and outbox event in the same transaction; delete the uploaded object on failure
    25. try {
    26. Long assetId = transactionTemplate.execute(status -> {
    27. Asset asset = new Asset();
    28. asset.setOwnerId(userCtx.getUserId());
    29. asset.setObjectKey(objectKey);
    30. asset.setStatus(AssetStatus.PROCESSING);
    31. assetRepository.save(asset);
    32. outboxRepository.save(OutboxEvent.of("ASSET_PROCESS", asset.getId()));
    33. return asset.getId();
    34. });
    35. return ImportResult.success(assetId);
    36. } catch (RuntimeException e) {
    37. storageClient.deleteQuietly(objectKey);
    38. throw e;
    39. }
    40. }
    41. }

    Several points in the code require manual review:

    • Comments must match the implementation. The model’s first version had a comment saying “validate file type,” but the code actually validated only permissions. During acceptance, comments and logic should be checked line by line.
    • The Content-Type and filename passed by the client are both untrusted, so type detection must read the file content. The example uses file.getBytes() to read the whole file into memory, and production environments need a file size limit.
    • The task is not sent directly to the queue. It is written to an outbox table and then delivered by a separate process. This avoids the situation where a task exists in the queue but no asset exists in the table even if the database commit fails.
    • If the object storage upload succeeds but the database write fails, the uploaded object must be deleted; otherwise, files with no references are left behind.

    The first version had no transaction boundary or compensation logic. These parts were added during manual acceptance.

    After the functionality worked, the model also needed to complete the “HTML animation scenario reference” module. The security issue in this module is described in Section 5.

    4. Case Two: From Materials to a Playable Prototype

    The input for the second project was learning material for a technical field, including a development guide and principle documentation, plus a product requirements document (PRD). The goal was to implement from scratch a knowledge-learning game that could be completed from start to finish.

    This task tested requirements understanding and architecture design. The model first structured the materials and extracted concepts, dependencies, and exercise types. It then designed the main flow, level data structures, and Agent interaction logic based on the PRD. The data model, game logic, and frontend interface were generated by the model in one pass, after which problems were fixed through manual playtesting and tests.

    In this test, the prototype could be played from beginning to end. However, the questions in some levels deviated from the material content and required manual level-by-level checking against the source material. Therefore, the model is suitable for prototype construction, but content accuracy still requires review by domain experts.

    5. Security Review: How Permission Bypass Occurs

    During manual acceptance of the first project, I found a P1-level permission isolation issue. The image import API already performed permission checks, but in the “HTML animation scenario reference” module, the API queried only by asset ID and did not validate asset ownership. User A could construct a request to reference and view User B’s private images.

    The problematic code looked roughly like this:

    1. // Problem: query by ID only, without ownership validation
    2. Asset asset = assetRepository.findById(assetId)
    3. .orElseThrow(() -> new NotFoundException("Asset not found"));
    4. return AssetView.from(asset);

    The fix is to put the ownership condition into the query itself:

    1. // Fix: query includes the current user; unauthorized requests get the same response as "not found"
    2. Asset asset = assetRepository.findByIdAndOwnerId(assetId, userCtx.getUserId())
    3. .orElseThrow(() -> new NotFoundException("Asset not found"));
    4. return AssetView.from(asset);

    There are two points to note here. First, an unauthorized request returns the same 404 as “not found,” so an attacker cannot use the status code to determine whether an asset exists. Second, ownership validation should be placed in the data access layer rather than relying on every caller to remember to add the check. A model can write permission checks, but it will not necessarily apply them to every resource-read path.

    Security review should be split into three categories, each covering different risks:

    • Static Application Security Testing (SAST): Scan for dangerous patterns such as injection, path concatenation, and deserialization. It can find clearly insecure code but cannot understand business ownership relationships.
    • Dependency scanning: Check whether newly added third-party libraries have known vulnerabilities and confirm that versions are within the team’s allowed range. A model may introduce outdated or unmaintained dependencies, so scanning is required.
    • Permission matrix testing: List expected results by “requester × resource owner × operation” and verify each item with automated tests. Permission bypass issues are mainly found through this type of testing.

    Below is an example permission matrix for the image reference scenario:

    Requester Resource owner Operation Expected result
    User A User A View asset 200, return asset
    User A User B View asset 404
    User A User B Reference asset in a scenario 404, and do not save the reference
    Anonymous user User A View asset 401
    Administrator User B View asset Return according to admin policy and record an audit log

    After each model-generated code change, it is recommended to check the following list:

    1. Does every resource-read endpoint validate ownership, and does the query include the current user?
    2. Does file upload validate both the extension and the file content, and is the storage path free of user input?
    3. Are error responses consistent and free of internal information leakage?
    4. Do the validations described in comments actually exist in the code?
    5. Does cross-tenant data access go through a unified authorization component or gateway?
    6. Do new dependencies pass scanning, and are versions pinned?
    7. Do permission matrix tests cover new endpoints?

    For high-risk operations such as cross-tenant access and file read/write, it is recommended that a unified authorization component or gateway intercept them centrally rather than relying on each business module to implement its own checks. Specific tools can be selected based on the team’s existing infrastructure.

    6. Human-AI Collaboration Delivery Process

    Based on the tests above, teams should organize LLM-assisted development in three steps.

    1. Provide structured context. Before starting a long-horizon task, provide architecture diagrams, database ER diagrams, API lists, and security constraints. The clearer the context, the fewer assumptions the model will make on its own.
    2. Write security requirements into the task description. For example: “For all resource-read endpoints, the query condition must include ownerId.” Such constraints should be written into prompts or project specification files so that every task can read them.
    3. Set up multi-party review. The model produces code as a junior developer, while automated tests, static analysis tools, and senior engineers each take on review roles. Permission bypass, injection, and resource leakage are key areas for manual review.

    Current models can already bring real efficiency gains in long-horizon coding and from-scratch prototype building, and both cases reached a runnable state. However, permission design, data security, and final acceptance still require human control. Whether to use these models in real projects should depend on whether the team has a controlled test environment, automated security gates, and a standardized manual acceptance process.