Skip to content

Commit 5c27101

Browse files
authored
Merge pull request #203 from javaevolved/brunoborges-securitymanager-explicit-authorization
Add SecurityManager explicit authorization pattern
2 parents 68b5388 + bb513d6 commit 5c27101

23 files changed

Lines changed: 692 additions & 7 deletions

.github/ISSUE_TEMPLATE/new-pattern.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,17 @@ body:
99
value: |
1010
## How to submit a new pattern
1111
12-
Patterns are defined as **JSON files** in category subfolders.
13-
Please provide the information below and we'll create the JSON file,
14-
or submit a PR with the JSON file directly.
12+
Patterns are defined as **YAML files** in category subfolders.
13+
Please provide the information below and we'll create the pattern,
14+
or submit a pull request that completes this checklist:
15+
16+
- Canonical content with valid metadata, tags, related patterns, and reciprocal navigation
17+
- A Java 25 proof for the modern code
18+
- Partial content translations for every locale in `html-generators/locales.properties`
19+
- Successful regeneration of all localized site output
20+
- An appended social queue entry and pre-drafted tweet
21+
22+
Pull requests validate this checklist automatically.
1523
1624
- type: dropdown
1725
id: category

.github/copilot-instructions.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,10 @@ Content files are YAML (preferred) or JSON under `content/{category}/{slug}.yaml
6262
2. Add a non-empty `tags` list. Every tag slug must already exist in `html-generators/tags.properties`; add new `slug=Display Name` entries there in the same change.
6363
3. Update `prev`/`next` in the adjacent patterns to maintain the navigation chain.
6464
4. Create `proof/{category}/{PascalCaseSlug}.java` — JBang script wrapping the modern code.
65-
5. Run `jbang html-generators/generate.java` and verify it completes. The generator rejects missing, malformed, or duplicate UUIDs as well as missing, empty, malformed, and unregistered tags.
66-
6. Translations are optional — the AI translation workflow handles them, or create partial files under `translations/content/{locale}/`.
65+
5. Create a partial translation at `translations/content/{locale}/{category}/{slug}.yaml` for every non-English locale registered in `html-generators/locales.properties`.
66+
6. Run `jbang html-generators/generate.java` and verify all localized output builds. Generated site files are ignored and must not be committed. The generator rejects missing, malformed, or duplicate UUIDs as well as missing, empty, malformed, and unregistered tags.
67+
7. Run `jbang html-generators/generatesocialqueue.java` without `--reshuffle`. Commit the appended `social/queue.txt` entry and `social/tweets.yaml` draft; do not change `social/state.yaml`.
68+
8. Run `jbang html-generators/validatepatternchanges.java --file content/{category}/{slug}.yaml` and the new proof. The validator enforces translations, proof, navigation, related targets, and social artifacts.
6769

6870
### Removing or reordering a pattern
6971

.github/workflows/content-validation.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ on:
55
paths:
66
- '.github/workflows/content-validation.yml'
77
- 'content/**'
8+
- 'proof/**'
9+
- 'social/queue.txt'
10+
- 'social/tweets.yaml'
811
- 'translations/**'
912
- 'templates/**'
1013
- 'html-generators/generate.java'
14+
- 'html-generators/validatepatternchanges.java'
1115
- 'html-generators/tags.properties'
1216
- 'html-generators/categories.properties'
1317
- 'html-generators/locales.properties'
@@ -21,6 +25,8 @@ jobs:
2125
runs-on: ubuntu-latest
2226
steps:
2327
- uses: actions/checkout@v7
28+
with:
29+
fetch-depth: 0
2430

2531
- uses: actions/setup-java@v6
2632
with:
@@ -29,5 +35,12 @@ jobs:
2935

3036
- uses: jbangdev/setup-jbang@main
3137

38+
- name: Validate new pattern checklist
39+
if: github.event_name == 'pull_request'
40+
run: >
41+
jbang html-generators/validatepatternchanges.java
42+
--base "${{ github.event.pull_request.base.sha }}"
43+
--head "${{ github.event.pull_request.head.sha }}"
44+
3245
- name: Validate content and generate site
3346
run: jbang html-generators/generate.java

content/security/random-generator.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ support:
4545
state: "available"
4646
description: "Available since JDK 17 (September 2021, JEP 356)."
4747
prev: "security/tls-default"
48-
next: "tooling/jshell-prototyping"
48+
next: "security/security-manager-migration"
4949
related:
5050
- "security/strong-random"
5151
- "security/key-derivation-functions"
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
id: 9e0d265f-d778-4115-9fc9-b09e37c55e41
3+
slug: "security-manager-migration"
4+
title: "SecurityManager checks to explicit authorization"
5+
category: "security"
6+
difficulty: "advanced"
7+
jdkVersion: "24"
8+
oldLabel: "JDK 23 and earlier"
9+
modernLabel: "JDK 24+"
10+
oldApproach: "SecurityManager checks"
11+
modernApproach: "Explicit authorization"
12+
oldCode: |-
13+
SecurityManager manager = System.getSecurityManager();
14+
if (manager != null) {
15+
manager.checkRead(path.toString());
16+
}
17+
return Files.readString(path);
18+
modernCode: |-
19+
// Untrusted users must not be able to modify this tree
20+
Path root = allowedRoot.toRealPath();
21+
Path resolved = root.resolve(requested)
22+
.normalize()
23+
.toRealPath();
24+
if (!resolved.startsWith(root)) {
25+
throw new SecurityException(
26+
"Path is outside the allowed root");
27+
}
28+
return Files.readString(resolved);
29+
summary: "Replace disabled SecurityManager checks with explicit application authorization\
30+
\ and deployment isolation."
31+
explanation: "JEP 486 permanently disabled the Security Manager in JDK 24, so checks\
32+
\ through System.getSecurityManager() can enforce policy only on JDK 23 and earlier.\
33+
\ Applications must authorize access explicitly in domain logic; resolving real filesystem\
34+
\ paths prevents existing symbolic links from escaping an allowed root when untrusted\
35+
\ users cannot modify that tree concurrently. For attacker-writable trees, use race-resistant,\
36+
\ handle-relative access such as SecureDirectoryStream. Use process, container, or\
37+
\ operating-system boundaries for isolation. JDK 24 retains the deprecated API temporarily,\
38+
\ but it cannot be enabled and is not replaced by another in-process sandbox."
39+
whyModernWins:
40+
- icon: "🔍"
41+
title: "Explicit policy"
42+
desc: "Authorization is visible and testable in application logic."
43+
- icon: "🛡️"
44+
title: "Real isolation"
45+
desc: "Process, container, and operating-system boundaries protect the whole application."
46+
- icon: "🚫"
47+
title: "Required migration"
48+
desc: "Removes checks that can no longer enforce policy on JDK 24 and later."
49+
support:
50+
state: "available"
51+
description: "Required on JDK 24 and later, where JEP 486 permanently disables the\
52+
\ Security Manager."
53+
prev: "security/random-generator"
54+
next: "tooling/jshell-prototyping"
55+
related:
56+
- "io/reading-files"
57+
- "io/deserialization-filters"
58+
- "security/tls-default"
59+
tags:
60+
- security
61+
- migration
62+
docs:
63+
- title: "Permanently Disable the Security Manager (JEP 486)"
64+
href: "https://openjdk.org/jeps/486"
65+
- title: "SecureDirectoryStream"
66+
href: "https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/nio/file/SecureDirectoryStream.html"

content/tooling/jshell-prototyping.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ whyModernWins:
3737
support:
3838
state: "available"
3939
description: "Widely available since JDK 9 (Sept 2017)"
40-
prev: "security/tls-default"
40+
prev: "security/security-manager-migration"
4141
next: "tooling/single-file-execution"
4242
related:
4343
- "tooling/aot-class-preloading"

0 commit comments

Comments
 (0)