Skip to content

Fix ScheduleByWeek without WeeksInterval in CalendarTrigger - #1558

Open
joaocmendonca wants to merge 3 commits into
fox-it:mainfrom
joaocmendonca:fix/tasks-calendar-trigger-schedulebyday
Open

joaocmendonca wants to merge 3 commits into
fox-it:mainfrom
joaocmendonca:fix/tasks-calendar-trigger-schedulebyday

Conversation

@joaocmendonca

Copy link
Copy Markdown

Fix ValueError('Unknown calendar type') when parsing Windows Task XML with ScheduleByWeek triggers that omit the WeeksInterval element. This occurs in real-world exported/UTF-16 task XML files

The fix:

  • Detect ScheduleByWeek directly (not gated on WeeksInterval presence)
  • Default weeks_between_triggers to 1 when WeeksInterval is missing
  • Safely extract DaysOfWeek children (handle missing elements gracefully)

Summary

Fix ValueError when parsing Windows Task XML with ScheduleByWeek but no WeeksInterval.

Issue

Parsing task XML files like windows/system32/tasks/at26 (UTF-16, exported) raised:
ValueError: Unknown calendar type
This occurred in CalendarTrigger with ScheduleByWeek that lacks WeeksInterval element (which is not mandatory as per specs, see https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src/TaskSchd/taskschedulerschema-weeksinterval-weeklyscheduletype-element.md).

Fix

  • Changed condition from elif weeks_between_triggers := ... to elif trigger.find("ScheduleByWeek/") is not None
  • Default weeks_between_triggers to 1 when element is missing
  • Safely extract DaysOfWeek children

Testing

Validated with standalone test that reproduces the exact scenario from the issue.
The full test suite can be run: pytest tests/plugins/os/windows/test_tasks.py -q

HTH, Best, Joao

Resolves ValueError('Unknown calendar type') when parsing Windows Task XML
with ScheduleByWeek triggers that omit the WeeksInterval element.
This occurs in real-world exported/UTF-16 task XML files.

The fix:
- Detect ScheduleByWeek directly (not gated on WeeksInterval presence)
- Default weeks_between_triggers to 1 when WeeksInterval is missing
- Safely extract DaysOfWeek children (handle missing elements gracefully)
@joaocmendonca joaocmendonca changed the title fix: handle ScheduleByWeek without WeeksInterval in CalendarTrigger Fix ScheduleByWeek without WeeksInterval in CalendarTrigger Feb 19, 2026
@joaocmendonca

Copy link
Copy Markdown
Author

I should have added that this is a fix for #1505. Thx.

@Schamper

Copy link
Copy Markdown
Contributor

Do you have a sample task that could be added as a unit test? Or otherwise can craft one?

@DissectBot

Copy link
Copy Markdown

@joaocmendonca thank you for your contribution! As this is your first code contribution, please read the following Contributor License Agreement (CLA). If you agree with the CLA, please reply with the following information:

@DissectBot agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
Contributor License Agreement

Contribution License Agreement

This Contribution License Agreement ("Agreement") governs your Contribution(s) (as defined below) and conveys certain license rights to Fox-IT B.V. ("Fox-IT") for your Contribution(s) to Fox-IT"s open source Dissect project. This Agreement covers any and all Contributions that you ("You" or "Your"), now or in the future, Submit (as defined below) to this project. This Agreement is between Fox-IT B.V. and You and takes effect when you click an “I Accept” button, check box presented with these terms, otherwise accept these terms or, if earlier, when You Submit a Contribution.

  1. Definitions.
    "Contribution" means any original work of authorship, including any modifications or additions to an existing work, that is intentionally submitted by You to Fox-IT for inclusion in, or documentation of, any of the software products owned or managed by, or on behalf of, Fox-IT as part of the Project (the "Work").
    "Project" means any of the projects owned or managed by Fox-IT and offered under a license approved by the Open Source Initiative (www.opensource.org).
    "Submit" means any form of electronic, verbal, or written communication sent to Fox-IT or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, Fox-IT for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by You as "Not a Contribution."

  2. Grant of Copyright License. Subject to the terms and conditions of this Agreement, You hereby grant to Fox-IT and to recipients of software distributed by Fox-IT a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, sublicense, and distribute Your Contributions and such derivative works.

  3. Grant of Patent License. Subject to the terms and conditions of this Agreement, You hereby grant to Fox-IT and to recipients of software distributed by Fox-IT a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, maintain, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by You that are necessarily infringed by Your Contribution(s) alone or by combination of Your Contribution(s) with the Work to which such Contribution(s) was submitted. If any entity institutes patent litigation against You or any other entity (including a cross-claim or counterclaim in a lawsuit) alleging that your Contribution, or the Work to which you have contributed, constitutes direct or contributory patent infringement, then any patent licenses granted to that entity under this Agreement for that Contribution or Work shall terminate as of the date such litigation is filed.

  4. Representations. You represent that:

    • You are legally entitled to grant the above license.
    • each of Your Contributions is Your original creation (see section 8 for submissions on behalf of others).
    • Your Contribution submissions include complete details of any third-party license or other restriction (including, but not limited to, related patents and trademarks) of which you are personally aware and which are associated with any part of Your Contributions.
  5. Employer. If Your Contribution is made in the course of Your work for an employer or Your employer has intellectual property rights in Your Submission by contract or applicable law, You must secure permission from Your employer to make the Contribution before signing this Agreement. In that case, the term "You" in this Agreement will refer to You and the employer collectively. If You change employers in the future and desire to Submit additional Contribution for the new employer, then You agree to sign a new Agreement and secure permission from the new employer before Submitting those Contributions.

  6. Support. You are not expected to provide support for Your Contribution, unless You choose to do so. Any such support provided to the Project is provided free of charge.

  7. Warranty. Unless required by applicable law or agreed to in writing, You provide Your Contributions on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE.

  8. Third party material. Should You wish to submit work that is not Your original creation, You may only submit it to Fox-IT separately from any Contribution, identifying the complete details of its source and of any license or other restriction (including, but not limited to, related patents, trademarks, and license agreements) of which You are personally aware, and conspicuously marking the work as "Submitted on behalf of a third-party: [named here]".

  9. Notify. You agree to notify Fox-IT of any facts or circumstances of which You become aware that would make the above representations inaccurate in any respect.

  10. Governing law / competent court. This Agreement is governed by the laws of the Netherlands. Any disputes that may arise are resolved by arbitration in accordance with the Arbitration Regulations of the Foundation for the Settlement of Automation Disputes (Stichting Geschillenoplossing Automatisering – SGOA – (www.sgoa.eu), this without prejudice to either party"s right to request preliminary relief in preliminary relief proceedings or arbitral preliminary relief proceedings. Arbitration proceedings take place in Amsterdam, or in any other place designated in the Arbitration Regulations. Arbitration shall take place in English.

@joaocmendonca

Copy link
Copy Markdown
Author

Do you have a sample task that could be added as a unit test? Or otherwise can craft one?

Here you are @Schamper!

I am unable to attach this as a file, so you have it as text.
This was extracted and redacted from a Windows 7 Ultimate system.
Note the inconsistent presence of backslashes on the Command field.

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.0" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo />
  <Triggers>
    <CalendarTrigger>
      <StartBoundary>2017-11-11T11:11:00</StartBoundary>
      <ScheduleByWeek>
        <DaysOfWeek>
          <Sunday />
          <Monday />
          <Tuesday />
          <Wednesday />
          <Thursday />
          <Friday />
          <Saturday />
        </DaysOfWeek>
      </ScheduleByWeek>
    </CalendarTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
      <UserId>@AtServiceAccount</UserId>
      <LogonType>InteractiveTokenOrPassword</LogonType>
      <RunLevel>HighestAvailable</RunLevel>
    </Principal>
  </Principals>
  <Actions Context="Author">
    <Exec>
      <Command>C:\AAAAA\\AaAaaAaaa\AaAaaAaaa.exe</Command>
      <Arguments>/m</Arguments>
    </Exec>
  </Actions>
</Task>

@joaocmendonca

Copy link
Copy Markdown
Author

@DissectBot agree

@Schamper Schamper left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add this file as a test file and expand the existing unit tests?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Target-query -f tasks throws "ValueError: Unknown calendar type" when parsing XML Tasks files

3 participants